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...