1
0
Fork 0

Additions to ALS model shader suggested and partially implemented by Heiko Schulz: alternative reflection coloring model, Fresnel effect and normal map distortion of environment reflections in an efficient approximation

This commit is contained in:
Thorsten Renk 2016-11-17 19:01:46 +02:00
parent f881091bbb
commit 950fc0ab22
2 changed files with 46 additions and 3 deletions

View file

@ -48,6 +48,8 @@ please see Docs/README.model-combined.eff for documentation
<reflection-enabled type="int">0</reflection-enabled> <reflection-enabled type="int">0</reflection-enabled>
<reflection-correction type="float">0.0</reflection-correction> <reflection-correction type="float">0.0</reflection-correction>
<reflect-map-enabled type="int">0</reflect-map-enabled> <reflect-map-enabled type="int">0</reflect-map-enabled>
<reflection-fresnel-factor type="float">0.0</reflection-fresnel-factor>
<reflection-type type="int">1</reflection-type>
<reflection-dynamic type="int">0</reflection-dynamic> <reflection-dynamic type="int">0</reflection-dynamic>
<texture n="4"> <texture n="4">
<image>Aircraft/Generic/Effects/ReflectMaps/reflectmap.png</image> <image>Aircraft/Generic/Effects/ReflectMaps/reflectmap.png</image>
@ -608,7 +610,7 @@ please see Docs/README.model-combined.eff for documentation
</value> </value>
</uniform> </uniform>
<!-- reflection is used --> <!-- reflection is used -->
<uniform> <uniform>
<name>refl_enabled</name> <name>refl_enabled</name>
<type>int</type> <type>int</type>
@ -624,6 +626,15 @@ please see Docs/README.model-combined.eff for documentation
<use>reflection-correction</use> <use>reflection-correction</use>
</value> </value>
</uniform> </uniform>
<!-- Fresnel reflectivity -->
<uniform>
<name>refl_fresnel_factor</name>
<type>float</type>
<value>
<use>reflection-fresnel-factor</use>
</value>
</uniform>
<!-- use a reflection map--> <!-- use a reflection map-->
<uniform> <uniform>
@ -633,6 +644,17 @@ please see Docs/README.model-combined.eff for documentation
<use>reflect-map-enabled</use> <use>reflect-map-enabled</use>
</value> </value>
</uniform> </uniform>
<!-- how are colors merged in a reflection-->
<uniform>
<name>refl_type</name>
<type>int</type>
<value>
<use>reflection-type</use>
</value>
</uniform>
<!-- reflection is dynamic --> <!-- reflection is dynamic -->
<uniform> <uniform>
<name>refl_dynamic</name> <name>refl_dynamic</name>

View file

@ -33,6 +33,7 @@ uniform int lightmap_multi;
uniform int nmap_dds; uniform int nmap_dds;
uniform int nmap_enabled; uniform int nmap_enabled;
uniform int refl_enabled; uniform int refl_enabled;
uniform int refl_type;
uniform int refl_map; uniform int refl_map;
uniform int grain_texture_enabled; uniform int grain_texture_enabled;
uniform int rain_enabled; uniform int rain_enabled;
@ -52,6 +53,7 @@ uniform float lightmap_r_factor;
uniform float nmap_tile; uniform float nmap_tile;
uniform float refl_correction; uniform float refl_correction;
uniform float refl_fresnel; uniform float refl_fresnel;
uniform float refl_fresnel_factor;
uniform float refl_noise; uniform float refl_noise;
uniform float refl_rainbow; uniform float refl_rainbow;
uniform float grain_magnification; uniform float grain_magnification;
@ -233,17 +235,25 @@ void main (void)
/// END grain overlay /// END grain overlay
vec3 reflVecN;
///BEGIN bump ///BEGIN bump
if (nmap_enabled > 0){ if (nmap_enabled > 0){
N = nmap.rgb * 2.0 - 1.0; N = nmap.rgb * 2.0 - 1.0;
// this is exact only for viewing under 90 degrees but much faster than the real solution
reflVecN = normalize (N.x * VTangent + N.y * VBinormal + N.z * reflVec);
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal); N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
if (nmap_dds > 0) if (nmap_dds > 0)
N = -N; N = -N;
} else { } else {
N = normalize(VNormal); N = normalize(VNormal);
reflVecN = reflVec;
} }
///END bump ///END bump
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
vec4 reflection = textureCube(Environment, reflVecN );
vec3 viewVec = normalize(vViewVec); vec3 viewVec = normalize(vViewVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75)); vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
@ -329,6 +339,12 @@ void main (void)
} else { } else {
reflFactor = gl_FrontMaterial.shininess* 0.0078125 + transparency_offset; reflFactor = gl_FrontMaterial.shininess* 0.0078125 + transparency_offset;
} }
// enhance low angle reflection by a fresnel term
float fresnel_enhance = (1.0-smoothstep(0.0,0.4, dot(N,-normalize(vertVec)))) * refl_fresnel_factor;
reflFactor+=fresnel_enhance;
reflFactor = clamp(reflFactor, 0.0, 1.0); reflFactor = clamp(reflFactor, 0.0, 1.0);
// add fringing fresnel and rainbow effects and modulate by reflection // add fringing fresnel and rainbow effects and modulate by reflection
@ -339,7 +355,12 @@ void main (void)
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0); vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
raincolor += Specular; raincolor += Specular;
raincolor *= light_diffuse; raincolor *= light_diffuse;
mixedcolor = mix(texel, raincolor, reflFactor).rgb;
if (refl_type == 1)
{mixedcolor = mix(texel, raincolor, reflFactor).rgb;}
else if (refl_type == 2)
{mixedcolor = ((texel +(reflcolor * reflFactor))-(0.5*reflFactor)).rgb;}
} else { } else {
mixedcolor = texel.rgb; mixedcolor = texel.rgb;
} }