1
0
Fork 0

Add layered clouds

This commit is contained in:
vmmeazza 2010-04-12 19:23:27 +00:00
parent d14a2585c7
commit 1afa90694c
10 changed files with 550 additions and 0 deletions

112
Effects/cloud-models.eff Normal file
View file

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/cloud-models</name>
<parameters>
<texture n ="0">
<type>white</type>
</texture>
</parameters>
<!--
<technique n="10">
<predicate>
<and>
<property>/sim/rendering/shader-effects</property>
<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>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<material>
<active><use>material/active</use></active>
<ambient><use>material/ambient</use></ambient>
<diffuse><use>material/diffuse</use></diffuse>
<specular><use>material/specular</use></specular>
<emissive><use>material/emissive</use></emissive>
<shininess><use>material/shininess</use></shininess>
<color-mode><use>material/color-mode</use></color-mode>
</material>
<blend>
<active><use>blend/active</use></active>
<source><use>blend/source</use></source>
<destination><use>blend/destination</use></destination>
</blend>
<shade-model><use>shade-model</use></shade-model>
<cull-face><use>cull-face</use></cull-face>
<rendering-hint><use>rendering-hint</use></rendering-hint>
<texture-unit> -->
<!-- The texture unit is always active because the shaders expect
that. -->
<!--<unit>0</unit>-->
<!-- If there is a texture, the type in the derived effect
will be "2d". -->
<!--<type><use>texture[0]/type</use></type>
<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>
<program>
<vertex-shader>Shaders/model-cloud.vert</vertex-shader>
<fragment-shader>Shaders/default.frag</fragment-shader>
</program>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value></uniform>
</pass>
</technique>-->
<technique n="11">
<pass>
<lighting>true</lighting>
<material>
<active><use>material/active</use></active>
<ambient><use>material/ambient</use></ambient>
<diffuse><use>material/diffuse</use></diffuse>
<specular><use>material/specular</use></specular>
<emissive><use>material/emissive</use></emissive>
<shininess><use>material/shininess</use></shininess>
<color-mode><use>material/color-mode</use></color-mode>
</material>
<blend>
<active><use>blend/active</use></active>
<source><use>blend/source</use></source>
<destination><use>blend/destination</use></destination>
</blend>
<shade-model><use>shade-model</use></shade-model>
<cull-face><use>cull-face</use></cull-face>
<rendering-hint><use>rendering-hint</use></rendering-hint>
<texture-unit>
<active><use>texture[0]/active</use></active>
<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>
-->
<environment>
<mode>modulate</mode>
</environment>
</texture-unit>
</pass>
</technique>
</PropertyList>

View file

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/clouds-layered</name>
<parameters>
<texture n ="0">
</texture>
</parameters>
<technique n="10">
<predicate>
<and>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">1.0</value>
<shader-language/>
</less-equal>
</and>
</predicate>
<pass n="0">
<!-- This is apparently not used, so maybe we'll blow it way soon. -->
<lighting>true</lighting>
<material>
<ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
<diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
<color-mode>off</color-mode>
</material>
<alpha-test>
<comparison>greater</comparison>
<reference type="float">0.01</reference>
</alpha-test>
<shade-model>smooth</shade-model>
<blend>
<source>src-alpha</source>
<destination>one-minus-src-alpha</destination>
</blend>
<depth>
<write-mask>false</write-mask>
</depth>
<render-bin>
<bin-number>10</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<type><use>texture[0]/type</use></type>
<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>
<!--<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>-->
</texture-unit>
<program>
<vertex-shader>Shaders/clouds-layered.vert</vertex-shader>
<fragment-shader>Shaders/clouds-layered.frag</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<vertex-program-two-side>true</vertex-program-two-side>
</pass>
</technique>
</PropertyList>

64
Effects/clouds-thick.eff Normal file
View file

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/clouds-thick</name>
<parameters>
<texture n ="0">
</texture>
</parameters>
<technique n="10">
<predicate>
<and>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">1.0</value>
<shader-language/>
</less-equal>
</and>
</predicate>
<pass n="0">
<!-- This is apparently not used, so maybe we'll blow it way soon. -->
<lighting>true</lighting>
<material>
<ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
<diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
<color-mode>off</color-mode>
</material>
<alpha-test>
<comparison>greater</comparison>
<reference type="float">0.01</reference>
</alpha-test>
<shade-model>smooth</shade-model>
<blend>
<source>src-alpha</source>
<destination>one-minus-src-alpha</destination>
</blend>
<depth>
<write-mask>false</write-mask>
</depth>
<render-bin>
<bin-number>10</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<type><use>texture[0]/type</use></type>
<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>
<!--<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>-->
</texture-unit>
<program>
<vertex-shader>Shaders/clouds-thick.vert</vertex-shader>
<fragment-shader>Shaders/clouds-thick.frag</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<vertex-program-two-side>true</vertex-program-two-side>
</pass>
</technique>
</PropertyList>

82
Effects/clouds-thin.eff Normal file
View file

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/clouds-thin</name>
<parameters>
<texture n ="0">
</texture>
</parameters>
<technique n="10">
<predicate>
<and>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">1.0</value>
<shader-language/>
</less-equal>
</and>
</predicate>
<pass n="0">
<!-- This is apparently not used, so maybe we'll blow it way soon. -->
<lighting>true</lighting>
<material>
<ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
<diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
<color-mode>off</color-mode>
</material>
<alpha-test>
<comparison>greater</comparison>
<reference type="float">0.01</reference>
</alpha-test>
<shade-model>smooth</shade-model>
<blend>
<source>src-alpha</source>
<destination>one-minus-src-alpha</destination>
</blend>
<depth>
<write-mask>false</write-mask>
</depth>
<render-bin>
<bin-number>10</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<type>
<use>texture[0]/type</use>
</type>
<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>
<!--<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>-->
</texture-unit>
<program>
<vertex-shader>Shaders/clouds-thin.vert</vertex-shader>
<fragment-shader>Shaders/clouds-thin.frag</fragment-shader>
<!--<attribute>
<name>usrAttr3</name>
<index>10</index>
</attribute>
<attribute>
<name>usrAttr4</name>
<index>11</index>
</attribute>-->
</program>
<uniform>
<name>baseTexture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<vertex-program-two-side>true</vertex-program-two-side>
</pass>
</technique>
</PropertyList>

View file

@ -0,0 +1,11 @@
uniform sampler2D baseTexture;
varying float fogFactor;
void main(void)
{
vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
vec4 finalColor = base * gl_Color;
gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor );
gl_FragColor.a = mix(0.0, finalColor.a, fogFactor);
}

View file

@ -0,0 +1,61 @@
// -*-C++-*-
#version 120
varying float fogFactor;
float shade = 0.2;
float cloud_height = 3000.0;
void main(void)
{
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);
vec3 u = normalize(ep.xyz - l.xyz);
// Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
// the columns of that matrix.
vec3 absu = abs(u);
vec3 r = normalize(vec3(-u.y, u.x, 0));
vec3 w = cross(u, r);
// Do the matrix multiplication by [ u r w pos]. Assume no
// scaling in the homogeneous component of pos.
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_Position.xyz = gl_Vertex.x * u;
gl_Position.xyz += gl_Vertex.y * r * 1.0;
gl_Position.xyz += gl_Vertex.z * w * 0.4;
//gl_Position.xyz += gl_Vertex.y * r * wScale;
//gl_Position.xyz += gl_Vertex.z * w * hScale;
gl_Position.xyz += gl_Color.xyz;
// Determine a lighting normal based on the vertex position from the
// center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker.
float n = dot(normalize(-gl_LightSource[0].position.xyz),
normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));;
// Determine the position - used for fog and shading calculations
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
float fogCoord = abs(ecPosition.z);
float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height);
// Final position of the sprite
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
// Determine the shading of the sprite based on its vertical position and position relative to the sun.
n = min(smoothstep(-0.5, 0.0, n), fract);
// Determine the shading based on a mixture from the backlight to the front
vec4 backlight = gl_LightSource[0].diffuse * shade;
gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n);
gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
// As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
gl_FrontColor.a = min(smoothstep(100.0, 300.0, fogCoord), 1 - smoothstep(25000.0, 30000.0, fogCoord));
gl_BackColor = gl_FrontColor;
// Fog doesn't affect clouds as much as other objects.
fogFactor = exp( -gl_Fog.density * fogCoord * 0.2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
}

11
Shaders/clouds-thick.frag Normal file
View file

@ -0,0 +1,11 @@
uniform sampler2D baseTexture;
varying float fogFactor;
void main(void)
{
vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
vec4 finalColor = base * gl_Color;
gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor );
gl_FragColor.a = mix(0.0, finalColor.a, fogFactor);
}

62
Shaders/clouds-thick.vert Normal file
View file

@ -0,0 +1,62 @@
// -*-C++-*-
#version 120
varying float fogFactor;
float shade = 0.5;
float cloud_height = 1000.0;
void main(void)
{
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
//gl_TexCoord[0] = gl_MultiTexCoord0 + vec4(textureIndexX, textureIndexY, 0.0, 0.0);
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);
vec3 u = normalize(ep.xyz - l.xyz);
// Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
// the columns of that matrix.
vec3 absu = abs(u);
vec3 r = normalize(vec3(-u.y, u.x, 0));
vec3 w = cross(u, r);
// Do the matrix multiplication by [ u r w pos]. Assume no
// scaling in the homogeneous component of pos.
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_Position.xyz = gl_Vertex.x * u;
gl_Position.xyz += gl_Vertex.y * r;
gl_Position.xyz += gl_Vertex.z * w;
//gl_Position.xyz += gl_Vertex.y * r * wScale;
//gl_Position.xyz += gl_Vertex.z * w * hScale;
gl_Position.xyz += gl_Color.xyz;
// Determine a lighting normal based on the vertex position from the
// center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker.
float n = dot(normalize(-gl_LightSource[0].position.xyz),
normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));;
// Determine the position - used for fog and shading calculations
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
float fogCoord = abs(ecPosition.z);
float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height);
// Final position of the sprite
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
// Determine the shading of the sprite based on its vertical position and position relative to the sun.
n = min(smoothstep(-0.5, 0.0, n), fract);
// Determine the shading based on a mixture from the backlight to the front
vec4 backlight = gl_LightSource[0].diffuse * shade;
gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n);
gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
// As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(15000.0, 20000.0, fogCoord));
gl_BackColor = gl_FrontColor;
// Fog doesn't affect clouds as much as other objects.
fogFactor = exp( -gl_Fog.density * fogCoord * 0.2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
}

11
Shaders/clouds-thin.frag Normal file
View file

@ -0,0 +1,11 @@
uniform sampler2D baseTexture;
varying float fogFactor;
void main(void)
{
vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
vec4 finalColor = base * gl_Color;
gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor );
gl_FragColor.a = mix(0.0, finalColor.a, fogFactor);
}

72
Shaders/clouds-thin.vert Normal file
View file

@ -0,0 +1,72 @@
// -*-C++-*-
#version 120
varying float fogFactor;
//attribute vec3 usrAttr3;
//attribute vec3 usrAttr4;
//float textureIndexX = usrAttr3.r;
//float textureIndexY = usrAttr3.g;
//float wScale = usrAttr3.b;
//float hScale = usrAttr4.r;
//float shade = usrAttr4.g;
//float cloud_height = usrAttr4.b;
void main(void)
{
float shade = 0.9;
float cloud_height = 1000.0;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
//gl_TexCoord[0] = gl_MultiTexCoord0 + vec4(textureIndexX, textureIndexY, 0.0, 0.0);
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);
vec3 u = normalize(ep.xyz - l.xyz);
// Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
// the columns of that matrix.
vec3 absu = abs(u);
vec3 r = normalize(vec3(-u.y, u.x, 0));
vec3 w = cross(u, r);
// Do the matrix multiplication by [ u r w pos]. Assume no
// scaling in the homogeneous component of pos.
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_Position.xyz = gl_Vertex.x * u;
gl_Position.xyz += gl_Vertex.y * r * 0.25;
gl_Position.xyz += gl_Vertex.z * w * 0.25;
//gl_Position.xyz += gl_Vertex.y * r * wScale;
//gl_Position.xyz += gl_Vertex.z * w * hScale;
gl_Position.xyz += gl_Color.xyz;
// Determine a lighting normal based on the vertex position from the
// center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker.
float n = dot(normalize(-gl_LightSource[0].position.xyz),
normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));;
// Determine the position - used for fog and shading calculations
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
float fogCoord = abs(ecPosition.z);
float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height);
// Final position of the sprite
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
// Determine the shading of the sprite based on its vertical position and position relative to the sun.
n = min(smoothstep(-0.5, 0.0, n), fract);
// Determine the shading based on a mixture from the backlight to the front
vec4 backlight = gl_LightSource[0].diffuse * shade;
gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n);
gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
// As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(15000.0, 20000.0, fogCoord));
gl_BackColor = gl_FrontColor;
// Fog doesn't affect clouds as much as other objects.
fogFactor = exp( -gl_Fog.density * fogCoord * 0.2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
}