Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 400
- in vec4 v_position; // view space position
- uniform sampler2D s_normalDepthTex; // Normals and Depth
- uniform mat4 u_worldTrans;
- uniform mat4 u_projTrans;
- uniform mat4 u_viewTrans;
- uniform mat4 u_projViewTrans;
- uniform vec3 u_lightPosition;
- uniform vec3 u_lightDiffuse = vec3(1.0,1.0,0);
- uniform vec3 u_lightSpecular = vec3(1.0,1.0,1.0);
- uniform vec3 u_lightAttenuation = vec3(0.2,0,0.2);
- uniform float u_lightIntensity = 1;
- uniform float u_lightRadius = 50f;
- uniform vec2 u_inverseScreenSize;
- uniform float u_farDistance;
- void main()
- {
- vec2 texCoord = gl_FragCoord.xy * u_inverseScreenSize.xy;
- float linearDepth = texture2D(s_normalDepthTex, texCoord.st).a;
- vec3 lightPos = (u_viewTrans * vec4(u_lightPosition,1)).rgb;
- // vector to far plane
- vec3 viewRay = vec3(v_position.xy * (u_farDistance/v_position.z), u_farDistance);
- // scale viewRay by linear depth to get view space position
- vec3 vertex = viewRay * linearDepth;
- vec3 normal = texture2D(s_normalDepthTex, texCoord.st).xyz;
- vec3 ambient = vec3(0.0, 0.0, 0.0);
- vec3 diffuse = vec3(0.0, 0.0, 0.0);
- vec3 specular = vec3(0.0, 0.0, 0.0);
- vec3 lightDir = lightPos - vertex;
- float distance = length(lightDir);
- float fallof = max(0.0, 1.0 - distance / u_lightRadius);
- gl_FragColor = vec4(fallof,fallof,fallof, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement