1
0
Fork 0

Add the possibility to use shadow mapping on model-interior

This commit is contained in:
Fernando García Liñán 2020-11-17 17:21:01 +01:00
parent d2e5ad9d60
commit 7c16104149
7 changed files with 139 additions and 9 deletions

View file

@ -103,10 +103,12 @@
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/model-interior-ALS-detailed.vert</vertex-shader>
<vertex-shader>Shaders/shadows-include.vert</vertex-shader>
<fragment-shader>Shaders/model-interior-display-ALS.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
<fragment-shader>Shaders/shadows-include.frag</fragment-shader>
</program>
<uniform>
<name>visibility</name>
@ -439,6 +441,34 @@
<type>int</type>
<value><use>grain-texture-enabled</use></value>
</uniform>
<!-- BEGIN shadows include -->
<uniform>
<name>shadow_tex</name>
<type>sampler-2d</type>
<value type="int">10</value>
</uniform>
<uniform>
<name>shadows_enabled</name>
<type>bool</type>
<value>
<use>shadows_enabled</use>
</value>
</uniform>
<uniform>
<name>sun_atlas_size</name>
<type>int</type>
<value>
<use>sun_atlas_size</use>
</value>
</uniform>
<!-- END shadows include -->
<uniform>
<name>shadow_mapping_enabled</name>
<type>bool</type>
<value>
<use>shadow-mapping-enabled</use>
</value>
</uniform>
</pass>
</technique>

View file

@ -64,6 +64,7 @@
<residual-ambience-b type="float">0.0</residual-ambience-b>
<ra-irradiance-map-type type="int">0</ra-irradiance-map-type>
<ra-irradiance-map-strength type="float">0.0</ra-irradiance-map-strength>
<shadow-mapping-enabled type="bool">false</shadow-mapping-enabled>
</parameters>
<technique n="3">
@ -141,10 +142,12 @@
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/model-interior-ALS-detailed.vert</vertex-shader>
<vertex-shader>Shaders/shadows-include.vert</vertex-shader>
<fragment-shader>Shaders/model-interior-ALS-detailed.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
<fragment-shader>Shaders/shadows-include.frag</fragment-shader>
</program>
<uniform>
<name>visibility</name>
@ -467,6 +470,34 @@
<type>int</type>
<value><use>grain-texture-enabled</use></value>
</uniform>
<!-- BEGIN shadows include -->
<uniform>
<name>shadow_tex</name>
<type>sampler-2d</type>
<value type="int">10</value>
</uniform>
<uniform>
<name>shadows_enabled</name>
<type>bool</type>
<value>
<use>shadows_enabled</use>
</value>
</uniform>
<uniform>
<name>sun_atlas_size</name>
<type>int</type>
<value>
<use>sun_atlas_size</use>
</value>
</uniform>
<!-- END shadows include -->
<uniform>
<name>shadow_mapping_enabled</name>
<type>bool</type>
<value>
<use>shadow-mapping-enabled</use>
</value>
</uniform>
</pass>
</technique>
@ -527,11 +558,13 @@
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/model-interior-ALS-base.vert</vertex-shader>
<vertex-shader>Shaders/shadows-include.vert</vertex-shader>
<fragment-shader>Shaders/model-interior-ALS-base.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
<fragment-shader>Shaders/shadows-include.frag</fragment-shader>
</program>
<uniform>
<name>visibility</name>
@ -749,6 +782,34 @@
<type>int</type>
<value><use>use-flashlight</use></value>
</uniform>
<!-- BEGIN shadows include -->
<uniform>
<name>shadow_tex</name>
<type>sampler-2d</type>
<value type="int">10</value>
</uniform>
<uniform>
<name>shadows_enabled</name>
<type>bool</type>
<value>
<use>shadows_enabled</use>
</value>
</uniform>
<uniform>
<name>sun_atlas_size</name>
<type>int</type>
<value>
<use>sun_atlas_size</use>
</value>
</uniform>
<!-- END shadows include -->
<uniform>
<name>shadow_mapping_enabled</name>
<type>bool</type>
<value>
<use>shadow-mapping-enabled</use>
</value>
</uniform>
</pass>
</technique>

View file

@ -43,6 +43,8 @@ uniform int use_searchlight;
uniform int implicit_lightmap_enabled;
uniform int use_flashlight;
uniform bool shadow_mapping_enabled;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
@ -60,6 +62,8 @@ vec3 get_hazeColor(in float light_arg);
vec3 flashlight(in vec3 color, in float radius);
vec3 filter_combined (in vec3 color) ;
float getShadowing();
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
@ -135,14 +139,18 @@ void main()
NdotL = dot(n, lightDir);
//NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz);
if (NdotL > 0.0) {
float shadowmap = 1.0;
if (shadow_mapping_enabled) {
shadowmap = getShadowing();
}
diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a);
color += diffuse * NdotL * opacity;
color += diffuse * NdotL * opacity * shadowmap;
NdotHV = max(dot(n, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
* pow(NdotHV, gl_FrontMaterial.shininess)
* shadowmap);
}
color.a = diffuse.a;
// This shouldn't be necessary, but our lighting becomes very

View file

@ -36,6 +36,10 @@ uniform float overcast;
uniform float ground_scattering;
uniform float moonlight;
uniform bool shadow_mapping_enabled;
void setupShadows(vec4 eyeSpacePos);
// This is the value used in the skydome scattering shader - use the same here for consistency?
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
@ -237,4 +241,8 @@ else // the faster, full-day version without lightfields
// gl_FrontFacing in the fragment shader.
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
if (shadow_mapping_enabled) {
setupShadows(gl_ModelViewMatrix * gl_Vertex);
}
}

View file

@ -59,6 +59,8 @@ uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int grain_texture_enabled;
uniform bool shadow_mapping_enabled;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
@ -76,6 +78,8 @@ vec3 addLights(in vec3 color1, in vec3 color2);
vec3 flashlight(in vec3 color, in float radius);
vec3 filter_combined (in vec3 color) ;
float getShadowing();
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
@ -151,9 +155,12 @@ void main()
NdotL = dot(n, lightDir);
//NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz);
if (NdotL > 0.0) {
float shadowmap = 1.0;
if (shadow_mapping_enabled) {
shadowmap = getShadowing();
}
diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a);
color += diffuse * NdotL * opacity;
color += diffuse * NdotL * opacity * shadowmap;
//NdotHV = max(dot(n, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0) {
@ -162,7 +169,9 @@ void main()
NdotHV = max(0.0, dot(n,HV));
specular = (gl_FrontMaterial.specular.rgb
* (light_specular.rgb+2.0*light_specular.rgb*(1.0-opacity.a))
* pow(NdotHV, gl_FrontMaterial.shininess)*opacity.rgb);
* pow(NdotHV, gl_FrontMaterial.shininess)
* opacity.rgb
* shadowmap);
}
}
color.a = diffuse.a;

View file

@ -46,6 +46,9 @@ uniform float residual_ambience_r;
uniform float residual_ambience_g;
uniform float residual_ambience_b;
uniform bool shadow_mapping_enabled;
void setupShadows(vec4 eyeSpacePos);
// This is the value used in the skydome scattering shader - use the same here for consistency?
const float EarthRadius = 5800000.0;
@ -297,6 +300,9 @@ else // the faster, full-day version without lightfields
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
if (shadow_mapping_enabled) {
setupShadows(gl_ModelViewMatrix * gl_Vertex);
}
}

View file

@ -65,6 +65,8 @@ uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int grain_texture_enabled;
uniform bool shadow_mapping_enabled;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
@ -82,6 +84,8 @@ vec3 addLights(in vec3 color1, in vec3 color2);
vec3 flashlight(in vec3 color, in float radius);
vec3 filter_combined (in vec3 color) ;
float getShadowing();
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
@ -259,14 +263,18 @@ void main()
NdotL = dot(n, lightDir);
//NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz);
if (NdotL > 0.0) {
float shadowmap = 1.0;
if (shadow_mapping_enabled) {
shadowmap = getShadowing();
}
diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a);
color += diffuse * NdotL * opacity;
color += diffuse * NdotL * opacity * shadowmap;
NdotHV = max(dot(n, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
* pow(NdotHV, gl_FrontMaterial.shininess)
* shadowmap);
}
color.a = diffuse.a;
// This shouldn't be necessary, but our lighting becomes very