Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- #define COLORED_SHADOWS 1 //0: Stained glass will cast ordinary shadows. 1: Stained glass will cast colored shadows. 2: Stained glass will not cast any shadows. [0 1 2]
- #define SHADOW_BRIGHTNESS 0.75 //Light levels are multiplied by this number when the surface is in shadows [0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00]
- uniform sampler2D lightmap;
- uniform sampler2D texture;
- varying vec2 lmcoord;
- varying vec2 texcoord;
- varying vec4 glcolor;
- varying vec4 shadowPos;
- varying flat int worldTimeVarying;
- uniform int isEyeInWater;
- uniform sampler2D shadowcolor0;
- uniform sampler2D shadowtex0;
- uniform sampler2D shadowtex1;
- uniform vec3 cameraPosition;
- #define Exposure 1.0 // The exposure [0.5 1.0 1.5 2.0 5.0]
- const int shadowMapResolution = 1024; //Resolution of the shadow map. Higher numbers mean more accurate shadows. [128 256 512 1024 2048 4096 8192]
- const bool shadowcolor0Nearest = true;
- const bool shadowtex0Nearest = true;
- const bool shadowtex1Nearest = true;
- void main() {
- vec4 color = texture2D(texture, texcoord) * glcolor * Exposure;
- vec2 lm = lmcoord;
- if (shadowPos.w > 0.0) {
- //surface is facing towards shadowLightPosition
- #if COLORED_SHADOWS == 0
- //for normal shadows, only consider the closest thing to the sun,
- //regardless of whether or not it's opaque.
- if (texture2D(shadowtex0, shadowPos.xy).r < shadowPos.z) {
- #else
- //for invisible and colored shadows, first check the closest OPAQUE thing to the sun.
- if (texture2D(shadowtex1, shadowPos.xy).r < shadowPos.z) {
- #endif
- //surface is in shadows. reduce light level.
- lm.y *= SHADOW_BRIGHTNESS;
- }
- else {
- //surface is in direct sunlight. increase light level.
- lm.y = mix(31.0 / 32.0 * SHADOW_BRIGHTNESS, 31.0 / 32.0, sqrt(shadowPos.w));
- #if COLORED_SHADOWS == 1
- //when colored shadows are enabled and there's nothing OPAQUE between us and the sun,
- //perform a 2nd check to see if there's anything translucent between us and the sun.
- if (texture2D(shadowtex0, shadowPos.xy).r < shadowPos.z) {
- //surface has translucent object between it and the sun. modify its color.
- //if the block light is high, modify the color less.
- vec4 shadowLightColor = texture2D(shadowcolor0, shadowPos.xy);
- //make colors more intense when the shadow light color is more opaque.
- shadowLightColor.rgb = mix(vec3(1.0), shadowLightColor.rgb, shadowLightColor.a);
- //also make colors less intense when the block light level is high.
- shadowLightColor.rgb = mix(shadowLightColor.rgb, vec3(1.0), lm.x);
- //apply the color.
- lightmap.rgb *= shadowLightColor.rgb;
- }
- #endif
- }
- }
- }
- vec4 lmVec4 = texture2D(lightmap, lmcoord);
- // Normalized pixel coordinates (from 0 to 1)
- vec2 uv = lmcoord/vec2(shadowMapResolution);
- // Define the bluring radius/strength (direction independant)
- vec2 radius = vec2(20.0);
- // Calculate the value at the corners so that the matrix can be easily inverted
- float maximum = sqrt(radius.x * radius.x + radius.y * radius.y);
- // Define the variable which will hold the blured values
- vec3 blur = vec3(0.0);
- // Define the variable which will be used to normalize the image
- float sum = 0.0;
- // The kernel is dynamically created based on the bluring radius
- for(float u = -radius.x; u<=radius.x; u++){
- for(float v = -radius.y; v<=radius.y; v++){
- // The pixel weight used by the kernel is defined as: the distance from the kernel origin (0,0)
- // to the current kernel position, subtracted from the maximum possible distance. This leads
- // to a gradient from 0% relative weight on the edges to 100% relative weight at the origin of the kernel
- float weight = maximum - sqrt(u * u + v * v);
- // The weight is then exponentialized which seams to sleightly maintain more of the origianl detail
- //weight = pow(weight, 2.0);
- // The weight is then multiplied by the texture being sampled and added to the overall blurred values
- blur += weight * texture2D(lightmap, uv + (vec2(u, v)/vec2(shadowMapResolution))).xyz;
- // The weight is then added for normalizing purposes
- sum += weight;
- }
- }
- // Finally the blurred image is normalized
- blur /= sum;
- // Output to screen
- lmVec4 = vec4(blur , 1.0);
- if (isEyeInWater == 1) {
- // Water tint
- color *= vec4(0.0, 0.3, 0.7, 1.0) * (((-(worldTimeVarying - 24000)) + 18000) / 18000);
- } else {
- // Normal rendering
- color *= lmVec4;
- }
- /* DRAWBUFFERS:0 */
- gl_FragData[0] = color; //gcolor
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement