1
0
Fork 0

make transition effect Rembrandt compatible.

Note: this is the transition effect used by the materials-dds.xml
Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
Emilian Huminiuc 2012-06-28 23:39:08 +03:00
parent c001b6d679
commit 8fa569e77f
3 changed files with 477 additions and 0 deletions

View file

@ -89,6 +89,306 @@ parameters :
<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
</generate>-->
<technique n="8">
<predicate>
<and>
<property>/sim/rendering/shaders/transition</property>
<property>/sim/rendering/rembrandt/enabled</property>
<less-equal>
<value type="float">4.0</value>
<float-property>/sim/rendering/shaders/water</float-property>
</less-equal>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
<extension-supported>GL_EXT_gpu_shader4</extension-supported>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<!-- Use material values that are either inherited from the
terrain-default effect or supplied by an effect derived
from this one e.g., one created in the materials library. -->
<material>
<ambient>
<use>material/ambient</use>
</ambient>
<diffuse>
<use>material/diffuse</use>
</diffuse>
<specular>
<use>material/specular</use>
</specular>
<color-mode>ambient-and-diffuse</color-mode>
</material>
<blend>
<use>transparent</use>
</blend>
<alpha-test>
<use>transparent</use>
</alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number>
<use>render-bin/bin-number</use>
</bin-number>
<bin-name>
<use>render-bin/bin-name</use>
</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image>
<use>texture[0]/image</use>
</image>
<filter>
<use>texture[0]/filter</use>
</filter>
<wrap-s>
<use>texture[0]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[0]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>1</unit>
<image>
<use>texture[2]/image</use>
</image>
<filter>
<use>texture[2]/filter</use>
</filter>
<wrap-s>
<use>texture[2]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[2]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[2]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<image>
<use>texture[3]/image</use>
</image>
<filter>
<use>texture[3]/filter</use>
</filter>
<wrap-s>
<use>texture[3]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[3]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[3]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>3</unit>
<image>
<use>texture[4]/image</use>
</image>
<filter>
<use>texture[4]/filter</use>
</filter>
<wrap-s>
<use>texture[4]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[4]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[4]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>4</unit>
<type>noise</type>
</texture-unit>
<program>
<!-- <vertex-shader>Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader n="1">Shaders/transition-gbuffer.vert</vertex-shader>
<fragment-shader n="0">Shaders/transition-gbuffer.frag</fragment-shader>
<fragment-shader n="1">Shaders/gbuffer-functions.frag</fragment-shader>
<fragment-shader n="2">Shaders/gbuffer-encode.frag</fragment-shader>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>SecondTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>ThirdTex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>SnowTex</name>
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>RainNorm</name>
<type>float</type>
<value>
<use>rain-norm</use>
</value>
</uniform>
<uniform>
<name>SnowLevel</name>
<type>float</type>
<value>
<use>snow-level</use>
</value>
</uniform>
<uniform>
<name>Transitions</name>
<type>float</type>
<value>
<use>transitions</use>
</value>
</uniform>
<uniform>
<name>InverseSlope</name>
<type>float</type>
<value>
<use>inverse</use>
</value>
</uniform>
<uniform>
<name>CloudCover0</name>
<type>float</type>
<value>
<use>cloud-cover0</use>
</value>
</uniform>
<uniform>
<name>CloudCover1</name>
<type>float</type>
<value>
<use>cloud-cover1</use>
</value>
</uniform>
<uniform>
<name>CloudCover2</name>
<type>float</type>
<value>
<use>cloud-cover2</use>
</value>
</uniform>
<uniform>
<name>CloudCover3</name>
<type>float</type>
<value>
<use>cloud-cover3</use>
</value>
</uniform>
<uniform>
<name>CloudCover4</name>
<type>float</type>
<value>
<use>cloud-cover4</use>
</value>
</uniform>
<!-- BEGIN fog include -->
<uniform>
<name>visibility</name>
<type>float</type>
<value>
<use>visibility</use>
</value>
</uniform>
<uniform>
<name>avisibility</name>
<type>float</type>
<value>
<use>avisibility</use>
</value>
</uniform>
<uniform>
<name>hazeLayerAltitude</name>
<type>float</type>
<value>
<use>lthickness</use>
</value>
</uniform>
<uniform>
<name>scattering</name>
<type>float</type>
<value>
<use>scattering</use>
</value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
<value>
<use>terminator</use>
</value>
</uniform>
<uniform>
<name>fogType</name>
<type>int</type>
<value>
<use>fogtype</use>
</value>
</uniform>
<!-- END fog include -->
</pass>
</technique>
<technique n="9">
<predicate>

View file

@ -0,0 +1,160 @@
// -*-C++-*-
// Texture switching based on face slope and snow level
// based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier.
// <20> Emilian Huminiuc 2011
varying vec4 RawPos;
varying vec3 normal;
varying vec3 Vnormal;
uniform float SnowLevel;
uniform float Transitions;
uniform float InverseSlope;
uniform float RainNorm;
uniform float CloudCover0;
uniform float CloudCover1;
uniform float CloudCover2;
uniform float CloudCover3;
uniform float CloudCover4;
uniform sampler2D BaseTex;
uniform sampler2D SecondTex;
uniform sampler2D ThirdTex;
uniform sampler2D SnowTex;
uniform sampler3D NoiseTex;
// gbuffer function
void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth);
///////////////////
void main()
{
float MixFactor;
float NdotL;
float NdotHV;
float fogFactor;
float cover;
float slope;
float L1;
float L2;
float wetness;
float pf;
vec3 n;
vec3 lightDir;
vec3 halfVector;
vec4 texel;
vec4 fragColor;
vec4 color;
vec4 Noise;
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
Noise = texture3D(NoiseTex, RawPos.xyz*0.0011);
MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
MixFactor *= 300.0;
MixFactor = clamp(MixFactor, 0.0, 1.0);
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
// If gl_Color.a == 0, this is a back-facing polygon and the
// Vnormal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * Vnormal;
n = normalize(n);
color = vec4(1.0);
//Select texture based on slope
slope = normalize(normal).z;
//pull the texture fetch outside flow control to fix aliasing artefacts :(
vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
vec4 thirdTexel = texture2D(ThirdTex, gl_TexCoord[0].st);
vec4 snowTexel = texture2D(SnowTex, gl_TexCoord[0].st);
//Normal transition. For more abrupt faces apply another texture (or 2).
if (InverseSlope == 0.0) {
//Do we do an intermediate transition
if (Transitions >= 1.5) {
if (slope >= L1) {
texel = baseTexel;
}
if (slope >= L2 && slope < L1){
texel = mix(secondTexel, baseTexel, smoothstep(L2, L1 - 0.06 * MixFactor, slope));
}
if (slope < L2){
texel = mix(thirdTexel, secondTexel, smoothstep(L2 - 0.13 * MixFactor, L2, slope));
}
// Just one transition
} else if (Transitions < 1.5) {
if (slope >= L1) {
texel = baseTexel;
}
if (slope < L1) {
texel = mix(thirdTexel, baseTexel, smoothstep(L2 - 0.13 * MixFactor, L1, slope));
}
}
//Invert the transition: keep original texture on abrupt slopes and switch to another on flatter terrain
} else if (InverseSlope > 0.0) {
//Interemdiate transition ?
if (Transitions >= 1.5) {
if (slope >= L1 + 0.1) {
texel = thirdTexel;
}
if (slope >= L2 && slope < L1 + 0.1){
texel = mix(secondTexel, thirdTexel, smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
}
if (slope <= L2){
texel = mix(baseTexel, secondTexel, smoothstep(L2 - 0.06 * MixFactor, L2, slope));
}
//just one
} else if (Transitions < 1.5) {
if (slope > L1 + 0.1) {
texel = thirdTexel;
}
if (slope <= L1 + 0.1){
texel = mix(baseTexel, thirdTexel, smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
}
}
}
//darken textures with wetness
wetness = 1.0 - 0.3 * RainNorm;
texel.rgb = texel.rgb * wetness;
float altitude = RawPos.z;
//Snow texture for areas higher than SnowLevel
if (altitude >= SnowLevel - (1000.0 * slope + 300.0 * MixFactor) && slope > L2 - 0.12) {
texel = mix( texel,
mix( texel, snowTexel, smoothstep(L2 - 0.09 * MixFactor, L2, slope) ),
smoothstep(SnowLevel - (1000.0 * slope + 300.0 * MixFactor),
SnowLevel - (1000.0 * slope - 150.0 * MixFactor),
altitude)
);
}
fragColor = color * texel;
if(cover >= 2.5){
fragColor.rgb = fragColor.rgb * 1.2;
} else {
fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
}
fragColor.rgb *= 1.2 - 0.4 * MixFactor;
float specular = dot( gl_FrontMaterial.specular.rgb, vec3( 0.3, 0.59, 0.11 ) );
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb,
vec3( 0.3, 0.59, 0.11 )
);
encode_gbuffer( n, fragColor.rgb, 1, specular, gl_FrontMaterial.shininess, emission, gl_FragCoord.z );
}

View file

@ -0,0 +1,17 @@
// -*- mode: C; -*-
// Licence: GPL v2
// Authors: Frederic Bouvier, Emilian Huminiuc
//
varying vec4 RawPos;
varying vec3 normal;
varying vec3 Vnormal;
void main() {
RawPos = gl_Vertex;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = normalize(gl_Normal);
Vnormal = gl_NormalMatrix * gl_Normal;
}