Data from vertex to fragment shader

FineCutBodies's icon

Hi guys, I know it's not fully max related question, but is there any way to give any EXACT parameter (not interpolated!) from vertex shader to fragment shader?

what i want to do is to use the vertex color input parameter what i get in the vertex shader (gl_Color.r) and use that in the fragment shader...

I know there are the varying variables for this, but those are interpolating for the fragment shader, and it's really strange, but even if every vertex has the same gl_Color, or i just set the varying parameter exactly to a number at the vertex shader, the parameter arriving to the fragment shader won't be the same!

example (deleted most of the code, just left the related):

Vertex Shader:

varying double corridorType;
void main()
{
//corridorType = gl_Color.r;
corridorType = 1.0;
}

Fragment Shader:

varying double corridorType;
void main(void)
{
if (corridorType = 1.0)
}

Here the If statements will be true and false randomly!

Any ideas would be ppreciated!

diablodale's icon

I few things come to mind for me:

  1. Unless you have done something special in your code, the GLSL version that is being compiled is likely GLSL 1.2 or before. Therefore, there is no double. Double wasn't added until later versions of GLSL. I recommend you try again using float. http://www.opengl.org/wiki/GLSL_Type

  2. Later versions of GLSL, like v1.5, do allow you to control how variables are passed from vertex to fragment. They are called interpolation qualifiers and you can choose smooth, flat, or noperspective. http://www.opengl.org/wiki/Type_Qualifier_(GLSL)#Interpolation_qualifiers

  3. Because they are floating point numbers and the math/theory behind them...sometimes... what you wanted to store as 1.0 was actually stored as 0.9999999999999995 or some other slightly off number. http://confluence.jetbrains.com/display/ReSharper/Compare+of+float+numbers+by+equality+operatorhttp://floating-point-gui.de/errors/comparison/http://stackoverflow.com/questions/17333/most-effective-way-for-float-and-double-comparison

  4. You can define the version of GLSL that you request your video card's compiler/drivers to use. It must be the very first line of your vertex/geo/frag programs as in the below examples. Note...for Max...you *must* enable the compatibility profile. Below I've written that I want GLSL 1.5 compiled with the compatibility profile. Oh, note2...not all graphics cards/drivers support all GLSL versions and compatibility profiles.

        <program name="vp" type="vertex">
        <![CDATA[
        #version 150 compatibility
        varying vec2 texcoord0;
        void main()
FineCutBodies's icon

thanx a lot mate! makes sense... i was thinking also it should be something with floating point... will read those link, as really interesing in the theory behind...