diff options
Diffstat (limited to 'drivers/gles3/shaders/scene.glsl')
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 76 |
1 files changed, 64 insertions, 12 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index fb0f06de01..9bc2bc079d 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -35,7 +35,7 @@ layout(location=3) in vec4 color_attrib; layout(location=4) in vec2 uv_attrib; #endif -#if defined(ENABLE_UV2_INTERP) +#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP) layout(location=5) in vec2 uv2_attrib; #endif @@ -223,7 +223,7 @@ out vec4 color_interp; out vec2 uv_interp; #endif -#if defined(ENABLE_UV2_INTERP) +#if defined(ENABLE_UV2_INTERP) || defined (USE_LIGHTMAP) out vec2 uv2_interp; #endif @@ -234,9 +234,6 @@ out vec3 binormal_interp; #endif - - - #if defined(USE_MATERIAL) layout(std140) uniform UniformData { //ubo:1 @@ -356,7 +353,7 @@ void main() { uv_interp = uv_attrib; #endif -#if defined(ENABLE_UV2_INTERP) +#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP) uv2_interp = uv2_attrib; #endif @@ -549,7 +546,7 @@ in vec4 color_interp; in vec2 uv_interp; #endif -#if defined(ENABLE_UV2_INTERP) +#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP) in vec2 uv2_interp; #endif @@ -1357,7 +1354,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta reflection_accum+=reflection; } - +#ifndef USE_LIGHTMAP if (reflections[idx].ambient.a>0.0) { //compute ambient using skybox @@ -1403,8 +1400,20 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta ambient_accum+=ambient_out; } +#endif } +#ifdef USE_LIGHTMAP +uniform mediump sampler2D lightmap; //texunit:-9 +uniform mediump float lightmap_energy; +#endif + +#ifdef USE_LIGHTMAP_CAPTURE +uniform mediump vec4[12] lightmap_captures; +uniform bool lightmap_capture_sky; + +#endif + #ifdef USE_GI_PROBES uniform mediump sampler3D gi_probe1; //texunit:-9 @@ -1632,7 +1641,7 @@ void main() { vec2 uv = uv_interp; #endif -#if defined(ENABLE_UV2_INTERP) +#if defined(ENABLE_UV2_INTERP) || defined (USE_LIGHTMAP) vec2 uv2 = uv2_interp; #endif @@ -1745,7 +1754,7 @@ FRAGMENT_SHADER_CODE //vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y); } - +#ifndef USE_LIGHTMAP { vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz); @@ -1754,6 +1763,7 @@ FRAGMENT_SHADER_CODE ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution); //ambient_light=vec3(0.0,0.0,0.0); } +#endif } #else @@ -1938,6 +1948,48 @@ FRAGMENT_SHADER_CODE #endif +#ifdef USE_LIGHTMAP + ambient_light = texture(lightmap,uv2).rgb * lightmap_energy; +#endif + +#ifdef USE_LIGHTMAP_CAPTURE + { + vec3 cone_dirs[12] = vec3[] ( + vec3(0, 0, 1), + vec3(0.866025, 0, 0.5), + vec3(0.267617, 0.823639, 0.5), + vec3(-0.700629, 0.509037, 0.5), + vec3(-0.700629, -0.509037, 0.5), + vec3(0.267617, -0.823639, 0.5), + vec3(0, 0, -1), + vec3(0.866025, 0, -0.5), + vec3(0.267617, 0.823639, -0.5), + vec3(-0.700629, 0.509037, -0.5), + vec3(-0.700629, -0.509037, -0.5), + vec3(0.267617, -0.823639, -0.5) + ); + + + vec3 local_normal = normalize(camera_matrix * vec4(normal,0.0)).xyz; + vec4 captured = vec4(0.0); + float sum = 0.0; + for(int i=0;i<12;i++) { + float amount = max(0.0,dot(local_normal,cone_dirs[i])); //not correct, but creates a nice wrap around effect + captured += lightmap_captures[i]*amount; + sum+=amount; + } + + captured/=sum; + + if (lightmap_capture_sky) { + ambient_light = mix( ambient_light, captured.rgb, captured.a); + } else { + ambient_light = captured.rgb; + } + + } +#endif + #ifdef USE_FORWARD_LIGHTING @@ -1952,11 +2004,11 @@ FRAGMENT_SHADER_CODE } else { specular_light+=env_reflection_light; } - +#ifndef USE_LIGHTMAP if (ambient_accum.a>0.0) { ambient_light+=ambient_accum.rgb/ambient_accum.a; } - +#endif #ifdef USE_VERTEX_LIGHTING |