Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to use a shader just for learning purposes. But i have a few questions about it.

I have the following code:

Vertext shader:

const float Eta = 0.66;         // Ratio of indices of refraction 
const float FresnelPower = 5.0; 

const float F  = ((1.0-Eta) * (1.0-Eta)) / ((1.0+Eta) * (1.0+Eta));

varying vec3  Reflect;
varying vec3  Refract;
varying float Ratio;

void main()
{
    vec4 ecPosition  = gl_ModelViewMatrix * gl_Vertex;
    vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

    vec3 i = normalize(ecPosition3);
    vec3 n = normalize(gl_NormalMatrix * gl_Normal);

    Ratio   = F + (1.0 - F) * pow((1.0 - dot(-i, n)), FresnelPower);

    Refract = refract(i, n, Eta);
    Refract = vec3(gl_TextureMatrix[0] * vec4(Refract, 1.0));

    Reflect = reflect(i, n);
    Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

    gl_Position = ftransform();
}

Fragment shader:

varying vec3  Reflect;
varying vec3  Refract;
varying float Ratio;

uniform samplerCube Cubemap;

void main()
{
    vec3 refractColor = vec3(textureCube(Cubemap, Refract));
    vec3 reflectColor = vec3(textureCube(Cubemap, Reflect));

    vec3 color   = mix(refractColor, reflectColor, Ratio);

    gl_FragColor = vec4(color, 1.0);
}

First thing i notice is the "varying" keyword. I couldn't really find out if this is deprecated or not. I'm using opengl 4+. So shouldn't that be changed to 'in' or 'out'?

Other thing is the 'uniform' keyword. That means i have to pass a value from my code to my shader right? In this case i have to pass a cubemap. I guess i can figure out how to create one of those later, that's not important right now. But what i do like to know is how to change the value of the variable. I couldn't really find any info about that...

share|improve this question
    
What language are you using for your code? Also, what have you tried so far? –  Byte56 Jan 25 '12 at 19:07
    
@Byte56 I'm using c++. So far i've been able to compile shaders. I tested it with a simple shader which just colored my model. But i'm just not sure how to work with this shader. How to pass data to it etc. –  w00 Jan 25 '12 at 19:10
    
    
I don't think the question should be tagged as C++. As any OpenGL binding can use GLSL shader code. –  Gustavo Maciel Jan 26 '12 at 5:22
add comment

1 Answer 1

up vote 3 down vote accepted

I'm using opengl 4+.

No you're not. You are using GLSL 1.10. That's what happens when you do not put a #version declaration at the top of your shaders.

If you want to use GLSL version 4.10 or 4.20, you have to ask for it: #version 4.20.

As for varying, yes, that was deprecated in GLSL 1.30 and removed in GLSL 1.40. You should be using in and out.

Other thing is the 'uniform' keyword. That means i have to pass a value from my code to my shader right? In this case i have to pass a cubemap. I guess i can figure out how to create one of those later, that's not important right now. But what i do like to know is how to change the value of the variable. I couldn't really find any info about that...

Did you look? The top two hits on Google for "GLSL uniform" explain how they work. "OpenGL uniform" resolves to similarly useful pages.

However, for the record:

A global variable using the uniform qualifier means that the value of this variable is set from outside of the shader. The value is "uniform" over the execution of a single glDraw call. The API functions that set uniform values for GLSL programs all start with glUniform.

uniform variables of sampler types are special. They represent textures. More details can be found on the wiki.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.