Do not render cloudlets on the back half of the cloud at ranges
of > 10km. 50% performance improvements seen under overcast conditions.
This commit is contained in:
parent
024f7494e4
commit
4c4df3401e
4 changed files with 209 additions and 182 deletions
|
@ -5,12 +5,14 @@
|
|||
<texture n ="0">
|
||||
</texture>
|
||||
<range><use>/sim/rendering/clouds3d-vis-range</use></range>
|
||||
<detail><use>/sim/rendering/clouds3d-detail-range</use></detail>
|
||||
<scattering><use>/rendering/scene/scattering</use></scattering>
|
||||
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
|
||||
<altitude><use>/sim/rendering/eye-altitude-m</use></altitude>
|
||||
<cloud_self_shading><use>/environment/cloud-self-shading</use></cloud_self_shading>
|
||||
<moonlight><use>/environment/moonlight</use></moonlight>
|
||||
</parameters>
|
||||
|
||||
<technique n="9">
|
||||
<predicate>
|
||||
<and>
|
||||
|
@ -74,6 +76,11 @@
|
|||
<type>float</type>
|
||||
<value><use>range</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>detail_range</name>
|
||||
<type>float</type>
|
||||
<value><use>detail</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>scattering</name>
|
||||
<type>float</type>
|
||||
|
@ -102,6 +109,7 @@
|
|||
<!--<vertex-program-two-side>true</vertex-program-two-side>-->
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="10">
|
||||
<predicate>
|
||||
<less-equal>
|
||||
|
@ -162,6 +170,11 @@
|
|||
<type>float</type>
|
||||
<value><use>range</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>detail_range</name>
|
||||
<type>float</type>
|
||||
<value><use>detail</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>scattering</name>
|
||||
<type>float</type>
|
||||
|
|
|
@ -5,6 +5,7 @@ varying float fogFactor;
|
|||
varying vec3 hazeColor;
|
||||
|
||||
uniform float range; // From /sim/rendering/clouds3d-vis-range
|
||||
uniform float detail_range; // From /sim/rendering/clouds3d_detail-range
|
||||
uniform float scattering;
|
||||
uniform float terminator;
|
||||
uniform float altitude;
|
||||
|
@ -88,8 +89,15 @@ void main(void)
|
|||
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
|
||||
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
|
||||
float fogCoord = abs(ecPosition.z);
|
||||
float fogCoord = length(vec3(gl_ModelViewMatrix * vec4(gl_Color.x, gl_Color.y, gl_Color.z, 1.0)));
|
||||
float center_dist = length(vec3(gl_ModelViewMatrix * vec4(0.0,0.0,0.0,1.0)));
|
||||
|
||||
if ((fogCoord > detail_range) && (fogCoord > center_dist)) {
|
||||
// More than detail_range away, so discard all sprites on opposite side of
|
||||
// cloud center by shifting them beyond the view fustrum
|
||||
gl_Position = vec4(0.0,0.0,10.0,1.0);
|
||||
gl_FrontColor.a = 0.0;
|
||||
} else {
|
||||
|
||||
// Determine the shading of the vertex. We shade it based on it's position
|
||||
// in the cloud relative to the sun, and it's vertical position in the cloud.
|
||||
|
@ -116,7 +124,6 @@ void main(void)
|
|||
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
|
||||
|
||||
|
||||
|
||||
// Light at the final position
|
||||
|
||||
// first obtain normal to sun position
|
||||
|
@ -167,8 +174,14 @@ if (earthShade < 0.8)
|
|||
//gl_FrontColor.a = 1.0;
|
||||
//light_diffuse+ gl_FrontLightModelProduct.sceneColor;// * shade ;//+ gl_FrontLightModelProduct.sceneColor;
|
||||
|
||||
if ((fogCoord > (0.9 * detail_range)) && (fogCoord > center_dist)) {
|
||||
// cloudlet is almost at the detail range, so fade it out.
|
||||
gl_FrontColor.a = 1.0 - smoothstep(0.9 * detail_range, detail_range, fogCoord);
|
||||
} else {
|
||||
// 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(range*0.9, range, fogCoord));
|
||||
gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(0.9 * range, range, fogCoord));
|
||||
}
|
||||
|
||||
//gl_BackColor = gl_FrontColor;
|
||||
|
||||
// Fog doesn't affect clouds as much as other objects.
|
||||
|
@ -176,7 +189,6 @@ if (earthShade < 0.8)
|
|||
if (fadeScale < 0.05) fadeScale = 0.05;
|
||||
fogFactor = exp( -gl_Fog.density * fogCoord * fadeScale);
|
||||
|
||||
|
||||
// Fog doesn't affect clouds as much as other objects.
|
||||
//fogFactor = exp( -gl_Fog.density * fogCoord * 0.5);
|
||||
//fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
@ -190,12 +202,10 @@ if (earthShade < 0.8)
|
|||
|
||||
// in sunset or sunrise conditions, do extra shading of clouds
|
||||
|
||||
|
||||
// change haze color to blue hue for strong fogging
|
||||
//intensity = length(hazeColor);
|
||||
//hazeColor = intensity * normalize(mix(hazeColor, 2.0* vec3 (0.55, 0.6, 0.8), (1.0 - smoothstep(0.3,0.8,scattering))));
|
||||
|
||||
|
||||
//hazeColor = hazeColor * earthShade;
|
||||
//gl_FrontColor.xyz = gl_FrontColor.xyz * earthShade;
|
||||
|
||||
|
@ -224,8 +234,5 @@ if (earthShade < 0.8)
|
|||
gl_FrontColor.rgb = gl_FrontColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
|
||||
hazeColor.rgb = hazeColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
|
||||
gl_BackColor = gl_FrontColor;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
varying float fogFactor;
|
||||
|
||||
uniform float range; // From /sim/rendering/clouds3d-vis-range
|
||||
uniform float detail_range; // From /sim/rendering/clouds3d_detail-range
|
||||
|
||||
attribute vec3 usrAttr1;
|
||||
attribute vec3 usrAttr2;
|
||||
|
@ -39,15 +40,21 @@ void main(void)
|
|||
// Now shift the sprite to the correct position in the cloud.
|
||||
gl_Position.xyz += gl_Color.xyz;
|
||||
|
||||
// Determine the position - used for fog and shading calculations
|
||||
float fogCoord = length(vec3(gl_ModelViewMatrix * vec4(gl_Color.x, gl_Color.y, gl_Color.z, 1.0)));
|
||||
float center_dist = length(vec3(gl_ModelViewMatrix * vec4(0.0,0.0,0.0,1.0)));
|
||||
|
||||
if ((fogCoord > detail_range) && (fogCoord > center_dist)) {
|
||||
// More than detail_range away, so discard all sprites on opposite side of
|
||||
// cloud center by shifting them beyond the view fustrum
|
||||
gl_Position = vec4(0.0,0.0,10.0,1.0);
|
||||
gl_FrontColor.a = 0.0;
|
||||
} else {
|
||||
// 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(vec3(gl_ModelViewMatrix * vec4(- gl_Position.x, - gl_Position.y, - gl_Position.z, 0.0))));
|
||||
|
||||
// Determine the position - used for fog and shading calculations
|
||||
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
|
||||
float fogCoord = abs(ecPosition.z);
|
||||
|
||||
// Determine the shading of the vertex. We shade it based on it's position
|
||||
// in the cloud relative to the sun, and it's vertical position in the cloud.
|
||||
float shade = mix(shade_factor, top_factor, smoothstep(-0.3, 0.3, n));
|
||||
|
@ -61,23 +68,22 @@ void main(void)
|
|||
shade = min(shade, mix(middle_factor, top_factor, gl_Position.z * 2.0 / cloud_height - 1.0));
|
||||
}
|
||||
|
||||
//float h = gl_Position.z / cloud_height;
|
||||
//if (h < 0.5) {
|
||||
// shade = min(shade, mix(bottom_factor, middle_factor, smoothstep(0.0, 0.5, h)));
|
||||
//} else {
|
||||
// shade = min(shade, mix(middle_factor, top_factor, smoothstep(2.0 * (h - 0.5)));
|
||||
// }
|
||||
|
||||
// Final position of the sprite
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
|
||||
|
||||
gl_FrontColor = gl_LightSource[0].diffuse * shade + gl_FrontLightModelProduct.sceneColor;
|
||||
|
||||
if ((fogCoord > (0.9 * detail_range)) && (fogCoord > center_dist)) {
|
||||
// cloudlet is almost at the detail range, so fade it out.
|
||||
gl_FrontColor.a = 1.0 - smoothstep(0.9 * detail_range, detail_range, fogCoord);
|
||||
} else {
|
||||
// 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(range*0.9, range, fogCoord));
|
||||
gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(0.9 * range, range, fogCoord));
|
||||
}
|
||||
|
||||
gl_BackColor = gl_FrontColor;
|
||||
|
||||
// Fog doesn't affect clouds as much as other objects.
|
||||
fogFactor = exp( -gl_Fog.density * fogCoord * 0.5);
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,6 +217,7 @@ Started September 2000 by David Megginson, david@megginson.com
|
|||
<bump-mapping type="bool" userarchive="y">false</bump-mapping>
|
||||
<clouds3d-enable type="bool" userarchive="y">false</clouds3d-enable>
|
||||
<clouds3d-vis-range type="float" userarchive="y">10000.0</clouds3d-vis-range>
|
||||
<clouds3d-detail-range type="float" userarchive="y">10000.0</clouds3d-detail-range>
|
||||
<clouds3d-density type="float" userarchive="y">0.25</clouds3d-density>
|
||||
<draw-otw type="bool">true</draw-otw>
|
||||
<shadows-ac type="bool" userarchive="y">false</shadows-ac>
|
||||
|
|
Loading…
Add table
Reference in a new issue