1
0
Fork 0

Extend visibility range of 3d clouds to /sim/rendering/clouds3d-vis-range

This commit is contained in:
Stuart Buchanan 2011-08-21 22:09:04 +01:00
parent b9e80543b1
commit 74a9f8e1a6
2 changed files with 18 additions and 4 deletions

View file

@ -4,6 +4,9 @@
<parameters> <parameters>
<texture n ="0"> <texture n ="0">
</texture> </texture>
<range>
<use>/sim/rendering/clouds3d-vis-range</use>
</range>
</parameters> </parameters>
<technique n="10"> <technique n="10">
<predicate> <predicate>
@ -63,6 +66,11 @@
<type>sampler-2d</type> <type>sampler-2d</type>
<value type="int">0</value> <value type="int">0</value>
</uniform> </uniform>
<uniform>
<name>range</name>
<type>float</type>
<value><use>range</use></value>
</uniform>
<vertex-program-two-side>true</vertex-program-two-side> <vertex-program-two-side>true</vertex-program-two-side>
</pass> </pass>
</technique> </technique>

View file

@ -3,6 +3,8 @@
varying float fogFactor; varying float fogFactor;
uniform float range; // From /sim/rendering/clouds3d-vis-range
attribute vec3 usrAttr1; attribute vec3 usrAttr1;
attribute vec3 usrAttr2; attribute vec3 usrAttr2;
@ -40,11 +42,14 @@ void main(void)
// Determine a lighting normal based on the vertex position from the // 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. // 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), float n = dot(normalize(-gl_LightSource[0].position.xyz),
normalize(vec3(gl_ModelViewMatrix * vec4(- gl_Position.xyz,0.0)))); normalize(vec3(gl_ModelViewMatrix * vec4(- gl_Position.x, - gl_Position.y, - gl_Position.z,0.0))));
// Determine the position - used for fog and shading calculations // Determine the position - used for fog and shading calculations
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position); vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
float fogCoord = abs(ecPosition.z); float fogCoord = abs(ecPosition.z);
// Determine fractional height of vertex from 0 at the bottom, and 1 at mid-height.
// Used to determine shading.
float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height); float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height);
// Final position of the sprite // Final position of the sprite
@ -52,6 +57,7 @@ void main(void)
// Determine the shading of the sprite based on its vertical position and position relative to the sun. // 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); n = min(smoothstep(-0.5, 0.0, n), fract);
// Determine the shading based on a mixture from the backlight to the front // Determine the shading based on a mixture from the backlight to the front
vec4 backlight = gl_LightSource[0].diffuse * shade; vec4 backlight = gl_LightSource[0].diffuse * shade;
@ -59,7 +65,7 @@ void main(void)
gl_FrontColor += gl_FrontLightModelProduct.sceneColor; 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. // 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.0 - smoothstep(15000.0, 20000.0, fogCoord)); gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(range*0.8, range, fogCoord));
gl_BackColor = gl_FrontColor; gl_BackColor = gl_FrontColor;
// Fog doesn't affect clouds as much as other objects. // Fog doesn't affect clouds as much as other objects.