1
0
Fork 0

Add fog include and amend parameters iaw new render/shader dialog

Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
Vivian Meazza 2011-11-28 15:02:20 +00:00
parent 04824c4230
commit b8d57b9474
3 changed files with 520 additions and 301 deletions

View file

@ -1,280 +1,492 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/urban</name>
<inherits-from>Effects/terrain-default</inherits-from>
<parameters>
<snow-level><use>/sim/rendering/snow-level-m</use></snow-level>
<depth-factor type="float">0.008</depth-factor>
<night-color type="vec3d">0.75 0.59 0.05</night-color>
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
</parameters>
<generate>
<normal type="int">15</normal>
<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
</generate>
<technique n="8">
<predicate>
<and>
<property>/sim/rendering/urban-shader</property>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">4.0</value>
<float-property>/sim/rendering/quality-level</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>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<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[2]/image</use></image>
<filter>nearest-mipmap-nearest</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>
<mipmap-control>
<function-r>average</function-r>
<function-g>average</function-g>
<function-b>average</function-b>
<function-a>min</function-a>
</mipmap-control>
</texture-unit>
<texture-unit>
<unit>3</unit>
<type>noise</type>
</texture-unit>
<program>
<vertex-shader>Shaders/urban.vert</vertex-shader>
<fragment-shader>Shaders/urban.frag</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
<attribute>
<name>normal</name>
<index>15</index>
</attribute>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>QDMTex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value><use>depth-factor</use></value>
</uniform>
<uniform>
<name>tile_size</name>
<type>float</type>
<value><use>xsize</use></value>
</uniform>
<uniform>
<name>night_color</name>
<type>float-vec3</type>
<value><use>night-color</use></value>
</uniform>
<uniform>
<name>quality_level</name>
<type>float</type>
<value><use>quality-level</use></value>
</uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value><use>snow-level</use></value>
</uniform>
<uniform>
<name>max_lod_level</name>
<type>float</type>
<value><use>max-lod-level</use></value>
</uniform>
</pass>
</technique>
<technique n="9">
<predicate>
<and>
<property>/sim/rendering/urban-shader</property>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">2.0</value>
<float-property>/sim/rendering/quality-level</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>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<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>
<type>noise</type>
</texture-unit>
<program>
<vertex-shader>Shaders/urban.vert</vertex-shader>
<fragment-shader>Shaders/urban.frag</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
<attribute>
<name>normal</name>
<index>15</index>
</attribute>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value><use>depth-factor</use></value>
</uniform>
<uniform>
<name>tile_size</name>
<type>float</type>
<value><use>xsize</use></value>
</uniform>
<uniform>
<name>night_color</name>
<type>float-vec3</type>
<value><use>night-color</use></value>
</uniform>
<uniform>
<name>quality_level</name>
<type>float</type>
<value><use>quality-level</use></value>
</uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value><use>snow-level</use></value>
</uniform>
</pass>
</technique>
<name>Effects/urban</name>
<inherits-from>Effects/terrain-default</inherits-from>
<parameters>
<snow-level>
<use>/sim/rendering/snow-level-m</use>
</snow-level>
<depth-factor type="float">0.008</depth-factor>
<night-color type="vec3d">0.75 0.59 0.05</night-color>
<quality-level>
<use>/sim/rendering/shaders/quality-level</use>
</quality-level>
<!--fog include-->
<visibility>
<use>/environment/ground-visibility-m</use>
</visibility>
<avisibility>
<use>/environment/visibility-m</use>
</avisibility>
<lthickness>
<use>/environment/ground-haze-thickness-m</use>
</lthickness>
<scattering>
<use>/rendering/scene/scattering</use>
</scattering>
<terminator>
<use>/environment/terminator-relative-position-m</use>
</terminator>
<fogtype>
<use>/sim/rendering/scattering-shader</use>
</fogtype>
<!-- END fog include -->
</parameters>
<generate>
<normal type="int">15</normal>
<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
</generate>
<technique n="8">
<predicate>
<and>
<property>/sim/rendering/shaders/urban</property>
<property>/sim/rendering/shaders/quality-level</property>
<less-equal>
<value type="float">4.0</value>
<float-property>/sim/rendering/shaders/quality-level</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>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<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[2]/image</use>
</image>
<filter>nearest-mipmap-nearest</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>
<mipmap-control>
<function-r>average</function-r>
<function-g>average</function-g>
<function-b>average</function-b>
<function-a>min</function-a>
</mipmap-control>
</texture-unit>
<texture-unit>
<unit>3</unit>
<type>noise</type>
</texture-unit>
<program>
<vertex-shader n="0">Shaders/include_fog.vert</vertex-shader>
<vertex-shader n="1">Shaders/urban.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<fragment-shader n="1">Shaders/urban.frag</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
<attribute>
<name>normal</name>
<index>15</index>
</attribute>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>QDMTex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value>
<use>depth-factor</use>
</value>
</uniform>
<uniform>
<name>tile_size</name>
<type>float</type>
<value>
<use>xsize</use>
</value>
</uniform>
<uniform>
<name>night_color</name>
<type>float-vec3</type>
<value>
<use>night-color</use>
</value>
</uniform>
<uniform>
<name>quality_level</name>
<type>float</type>
<value>
<use>quality-level</use>
</value>
</uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value>
<use>snow-level</use>
</value>
</uniform>
<uniform>
<name>max_lod_level</name>
<type>float</type>
<value>
<use>max-lod-level</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>
<and>
<property>/sim/rendering/shaders/urban</property>
<!--<property>/sim/rendering/shader-effects</property>-->
<less-equal>
<value type="float">2.0</value>
<float-property>/sim/rendering/shaders/quality-level</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>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<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>
<type>noise</type>
</texture-unit>
<program>
<vertex-shader n="0">Shaders/include_fog.vert</vertex-shader>
<vertex-shader n="1">Shaders/urban.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<fragment-shader n="1">Shaders/urban.frag</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
<attribute>
<name>normal</name>
<index>15</index>
</attribute>
</program>
<!-- 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 -->
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value>
<use>depth-factor</use>
</value>
</uniform>
<uniform>
<name>tile_size</name>
<type>float</type>
<value>
<use>xsize</use>
</value>
</uniform>
<uniform>
<name>night_color</name>
<type>float-vec3</type>
<value>
<use>night-color</use>
</value>
</uniform>
<uniform>
<name>quality_level</name>
<type>float</type>
<value>
<use>quality-level</use>
</value>
</uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value>
<use>snow-level</use>
</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -33,6 +33,12 @@ int linear_search_steps = 10;
int GlobalIterationCount = 0;
int gIterationCap = 64;
////fog "include" /////
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
//////////////////////
void QDM(inout vec3 p, inout vec3 v)
{
const int MAX_LEVEL = TEXTURE_MIP_LEVELS;
@ -43,9 +49,9 @@ void QDM(inout vec3 p, inout vec3 v)
vec3 p2 = p;
float level = MAX_LEVEL;
vec2 dirSign = (sign(v.xy) + 1.0) * 0.5;
GlobalIterationCount = 0;
float d = 0.0;
vec2 dirSign = (sign(v.xy) + 1.0) * 0.5;
GlobalIterationCount = 0;
float d = 0.0;
while (level >= 0.0 && GlobalIterationCount < gIterationCap)
{
@ -77,8 +83,8 @@ void QDM(inout vec3 p, inout vec3 v)
level++;
//use additional convergence speed-up
#ifdef USE_QDM_ASCEND_INTERVAL
if(frac(level*0.5) > EPSILON)
#ifdef USE_QDM_ASCEND_INTERVAL
if(frac(level*0.5) > EPSILON)
level++;
#elseif USE_QDM_ASCEND_CONST
level++;
@ -113,10 +119,10 @@ void QDM(inout vec3 p, inout vec3 v)
float ray_intersect_QDM(vec2 dp, vec2 ds)
{
vec3 p = vec3( dp, 0.0 );
vec3 v = vec3( ds, 1.0 );
QDM( p, v );
return p.z;
vec3 p = vec3( dp, 0.0 );
vec3 v = vec3( ds, 1.0 );
QDM( p, v );
return p.z;
}
float ray_intersect_relief(vec2 dp, vec2 ds)
@ -154,10 +160,10 @@ float ray_intersect_relief(vec2 dp, vec2 ds)
float ray_intersect(vec2 dp, vec2 ds)
{
if ( quality_level >= 4.0 )
return ray_intersect_QDM( dp, ds );
else
return ray_intersect_relief( dp, ds );
if ( quality_level >= 4.0 )
return ray_intersect_QDM( dp, ds );
else
return ray_intersect_relief( dp, ds );
}
void main (void)
@ -206,12 +212,6 @@ void main (void)
emission_factor *= 0.5*pow(tc.r+0.8*tc.g+0.2*tc.b, 2.0) -0.2;
ambient_light += (emission_factor * vec4(night_color, 0.0));
float fogFactor;
float fogCoord = ecPos3.z / (1.0 + smoothstep(0.3, 0.7, emission_factor));
const float LOG2 = 1.442695;
fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
vec4 noisevec = texture3D(NoiseTex, (rawpos.xyz)*0.01*scale);
vec4 nvL = texture3D(NoiseTex, (rawpos.xyz)*0.00066*scale);
@ -225,19 +225,19 @@ void main (void)
n += noisevec[2]*0.8;
n += noisevec[3]*2.1;
n = mix(0.6, n, fogFactor);
n = mix(0.6, n, length(ecPosition.xyz) );
vec4 finalColor = texture2D(BaseTex, uv);
finalColor = mix(finalColor, clamp(n+nvL[2]*4.1+vec4(0.1, 0.1, nvL[2]*2.2, 1.0), 0.7, 1.0),
step(0.8,Nz)*(1.0-emis)*smoothstep(snowlevel+300.0, snowlevel+360.0, (rawpos.z)+nvL[1]*3000.0));
finalColor *= ambient_light;
if (gl_Fog.density == 1.0)
fogFactor=1.0;
vec4 p = vec4( ecPos3 + tile_size * V * (d-1.0) * depth_factor / s.z, 1.0 );
vec4 iproj = gl_ProjectionMatrix * p;
iproj /= iproj.w;
gl_FragColor = mix(gl_Fog.color ,finalColor, fogFactor);
finalColor.rgb = fog_Func(finalColor.rgb, fogType);
gl_FragColor = finalColor;
gl_FragDepth = (iproj.z+1.0)/2.0;
}

View file

@ -12,6 +12,12 @@ varying vec4 constantColor;
attribute vec3 tangent, binormal;
////fog "include"////////
uniform int fogType;
void fog_func(int type);
/////////////////////////
void main(void)
{
rawpos = gl_Vertex;
@ -25,4 +31,5 @@ void main(void)
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
fog_func(fogType);
}