1
0
Fork 0

Use geometry shader to give more relief to landmass

This commit is contained in:
fredb 2010-03-29 06:13:43 +00:00
parent 7ebe34e95c
commit e0056383f3
3 changed files with 204 additions and 0 deletions

View file

@ -16,6 +16,116 @@
<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
</generate>
<technique n="8">
<predicate>
<and>
<property>/sim/rendering/landmass-shader</property>
<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>
<extension-supported>GL_EXT_geometry_shader4</extension-supported>
</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>
<type>noise</type>
</texture-unit>
<texture-unit>
<unit>1</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>2</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>
<program>
<vertex-shader>Shaders/landmass-g.vert</vertex-shader>
<geometry-shader>Shaders/landmass.geom</geometry-shader>
<fragment-shader>Shaders/landmass.frag</fragment-shader>
<geometry-vertices-out type="int">16</geometry-vertices-out>
<geometry-input-type>triangles</geometry-input-type>
<geometry-output-type>triangle-strip</geometry-output-type>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
</program>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value type="float">0.01</value>
</uniform>
<uniform>
<name>canopy_height</name>
<type>float</type>
<value type="float">10.0</value>
</uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value type="float">
<use>snow-level</use>
</value>
</uniform>
</pass>
</technique>
<technique n="9">
<predicate>
<and>

19
Shaders/landmass-g.vert Normal file
View file

@ -0,0 +1,19 @@
varying vec4 rawposIn;
varying vec3 NormalIn;
varying vec3 VTangentIn;
varying vec3 VBinormalIn;
attribute vec3 tangent;
attribute vec3 binormal;
void main(void)
{
rawposIn = gl_Vertex;
NormalIn = normalize(gl_Normal);
VTangentIn = gl_NormalMatrix * tangent;
VBinormalIn = gl_NormalMatrix * binormal;
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}

75
Shaders/landmass.geom Normal file
View file

@ -0,0 +1,75 @@
#version 120
#extension GL_EXT_geometry_shader4 : enable
varying in vec4 rawposIn[];
varying in vec3 NormalIn[];
varying in vec3 VTangentIn[];
varying in vec3 VBinormalIn[];
varying out vec4 rawpos;
varying out vec4 ecPosition;
varying out vec3 VNormal;
varying out vec3 VTangent;
varying out vec3 VBinormal;
varying out vec3 Normal;
varying out vec4 constantColor;
uniform float canopy_height;
void createVertex(int i, int j, float offset, float s)
{
rawpos = rawposIn[i] + offset * vec4(NormalIn[i], 0.0);
ecPosition = gl_ModelViewMatrix * rawpos;
if ( s == 0.0 )
{
vec4 v;
if (j < i)
{
v = rawposIn[j] - rawposIn[i];
Normal = normalize(cross( NormalIn[i], v.xyz ));
}
else
{
v = rawposIn[i] - rawposIn[j];
Normal = normalize(cross( NormalIn[j], v.xyz ));
}
}
else
{
Normal = NormalIn[i];
}
VNormal = normalize(gl_NormalMatrix * Normal);
VTangent = VTangentIn[i];
VBinormal = VBinormalIn[i];
gl_FrontColor = gl_FrontColorIn[i];
constantColor = gl_FrontMaterial.emission
+ gl_FrontColorIn[i] * (gl_LightModel.ambient + gl_LightSource[0].ambient);
gl_Position = gl_ProjectionMatrix * ecPosition;
gl_TexCoord[0] = gl_TexCoordIn[i][0];
EmitVertex();
}
void main(void)
{
createVertex(0, 1, canopy_height, 0.0);
createVertex(0, 1, 0.0, 0.0);
createVertex(1, 0, canopy_height, 0.0);
createVertex(1, 0, 0.0, 0.0);
EndPrimitive();
createVertex(1, 2, canopy_height, 0.0);
createVertex(1, 2, 0.0, 0.0);
createVertex(2, 1, canopy_height, 0.0);
createVertex(2, 1, 0.0, 0.0);
EndPrimitive();
createVertex(2, 0, canopy_height, 0.0);
createVertex(2, 0, 0.0, 0.0);
createVertex(0, 2, canopy_height, 0.0);
createVertex(0, 2, 0.0, 0.0);
EndPrimitive();
createVertex(0, 1, canopy_height, 1.0);
createVertex(1, 2, canopy_height, 1.0);
createVertex(2, 0, canopy_height, 1.0);
EndPrimitive();
}