Skip to content

Instantly share code, notes, and snippets.

@Razzlegames
Created April 17, 2015 00:33
Show Gist options
  • Save Razzlegames/a02912734103df22b3e1 to your computer and use it in GitHub Desktop.
Save Razzlegames/a02912734103df22b3e1 to your computer and use it in GitHub Desktop.
#version 110
//----------------------------------------------
// Environment Vertex Shader
//----------------------------------------------
varying vec3 ReflectDir;
varying float LightIntensity;
uniform vec3 LightPos;
// Eye position in world cordinates
uniform vec3 eye_pos;
void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
// Provide model space to world space transform
mat4 model_to_world = gl_TextureMatrixInverse[0] *
gl_ModelViewMatrix;
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
//vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
// Vertex position in world cords
//vec4 pos_w = model_to_world * gl_Vertex;
vec4 pos_w = gl_ModelViewMatrix * gl_Vertex;
// Incident and reflection vectors
//vec3 I = -(pos_w.xyz - eye_pos.xyz);
//vec3 I = -pos_w.xyz;
vec3 I = normalize(-gl_TextureMatrixInverse[0] *
pos_w).xyz;
// * mat3(1.0, 0.0, 0.0,
// 0.0, -1.0, 0.0,
// 0.0, 0.0, 1.0);
ReflectDir = reflect(I, normal);
//ReflectDir = vec3(-ReflectDir.x, ReflectDir.y, ReflectDir.z);
LightIntensity = max(dot(normalize(LightPos -
eye_pos), normal),0.0);
}
//----------------------------------------------
// Environment Fragment Shader
//----------------------------------------------
// Passed in parameters
uniform vec3 BaseColor;
//uniform float MixRatio;
uniform samplerCube EnvMap;
uniform float reflexivity;
varying vec3 ReflectDir;
varying float LightIntensity;
void main()
{
// Look up environment map value in cube map
vec3 envColor = vec3(textureCube(EnvMap, ReflectDir));
// Add lighting to base color and mix
vec3 base = LightIntensity * BaseColor;
base = LightIntensity * gl_Color.rgb;
envColor = mix(envColor, base, (1.0 - reflexivity));
//envColor = mix(envColor, base, 0.5);
//// Use this once reflexivity is being passed in
//envColor = mix(envColor, base, reflexivity);
gl_FragColor = vec4(envColor, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment