Created
April 17, 2015 00:33
-
-
Save Razzlegames/a02912734103df22b3e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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