Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uniform sampler2D texture;
- uniform int width;
- uniform sampler2D lightmap;
- uniform vec3 lightColor;
- //final step in the lighting algorithm.
- //generates the final shadow image from the
- //generated occlusion map :-DDDD wow haha
- const float cutoff = 0.1f;
- const float bias = .5f;
- const int intensitylevel = 3;
- vec2 roundP(vec2 poop){
- //pixel to pixel divided by 2
- float p2p = 1.0f / width;
- return poop.xy - mod(poop, vec2(p2p)) + vec2(p2p*0.5f);
- }
- float GetShadowDistanceH(vec2 TexCoord)
- {
- float u = TexCoord.x;
- float v = TexCoord.y;
- u = abs(u-0.5f) * 2.0f;
- v = v * 2.0f - 1.0f;
- float v0 = v/u;
- v0 = (v0 + 1.0f) / 2.0f;
- vec2 newCoords = vec2(TexCoord.x,v0);
- //horizontal info was stored in the Red component
- //gl_FragColor = texture2D(lightmap, newCoords);
- //return newCoords.x < 0.5f ? 0 : 1;
- return texture2D(lightmap, roundP(newCoords)).r; // * 0.70588235; //revert mult done in distancing
- }
- float GetShadowDistanceV(vec2 TexCoord)
- {
- float u = TexCoord.y;
- float v = TexCoord.x;
- u = abs(u-0.5f) * 2.0f;
- v = v * 2.0f - 1.0f;
- float v0 = v/u;
- v0 = (v0 + 1.0f) / 2.0f;
- vec2 newCoords = vec2(TexCoord.y, v0);
- //vertical info was stored in the Green component
- //gl_FragColor = texture2D(lightmap, newCoords);
- //return newCoords.x < 0.5f ? 0 : 1;
- return texture2D(lightmap, roundP(newCoords)).g; // * 0.70588235; //revert mult done in distancing
- }
- void main()
- {
- // distance of this pixel from the center
- float dist = length(gl_TexCoord[0].xy - 0.5f);
- //apply pixel bias
- dist -= 1.0f / width * bias;
- //distance stored in the shadow map
- float shadowMapDistance;
- //coords in [-1,1]
- float nY = 2.0f*( gl_TexCoord[0].y - 0.5f);
- float nX = 2.0f*( gl_TexCoord[0].x - 0.5f);
- //for debug
- float red = 1.0f;
- float green = 1.0f;
- //we use these to determine which quadrant we are in
- if (abs(nY) < abs(nX))
- {
- shadowMapDistance = GetShadowDistanceH(gl_TexCoord[0].xy);
- green = 1.5f; //for debug
- }
- else if (abs(nY) > abs(nX))
- {
- red = 1.5f; //for debug
- shadowMapDistance = GetShadowDistanceV(gl_TexCoord[0].xy);
- }
- else shadowMapDistance = 0.0f;
- //if distance to this pixel is lower than distance from shadowMap,
- //then we are not in shadow
- //float light = dist;
- float light = dist < shadowMapDistance ? 1:0;
- float intensity = 1.0f - dist;
- for(int i = 1; i < intensitylevel; i++){
- intensity = intensity * (1-dist);
- }
- gl_FragColor = vec4(light > 0 ? (lightColor.r * intensity - cutoff) * red : 0.0f,
- light > 0 ? (lightColor.g * intensity - cutoff) * green : 0.0f,
- light > 0 ? lightColor.b * intensity - cutoff : 0.0f,
- 1.0f);
- //gl_FragColor = vec4(light, light, light, 1.0f - (dist / 1.4f));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement