1
0
Fork 0

Landmass update: add a triangle for the ground and don't apply relief on it

This commit is contained in:
fredb 2010-04-02 07:06:39 +00:00
parent d73a93f284
commit 5d76d5f3f5
4 changed files with 29 additions and 10 deletions

View file

@ -80,7 +80,7 @@
<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-vertices-out type="int">20</geometry-vertices-out>
<geometry-input-type>triangles</geometry-input-type>
<geometry-output-type>triangle-strip</geometry-output-type>
<attribute>

View file

@ -7,6 +7,7 @@ varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 Normal;
varying vec4 constantColor;
varying float bump;
uniform sampler3D NoiseTex;
uniform sampler2D BaseTex;
@ -53,16 +54,26 @@ float ray_intersect(sampler2D reliefMap, vec2 dp, vec2 ds)
void main (void)
{
vec3 V = normalize(ecPosition.xyz);
float a = dot(VNormal, -V);
vec2 s = vec2(dot(V, VTangent), dot(V, VBinormal));
s *= depth_factor / a;
vec2 ds = s;
vec2 dp = gl_TexCoord[0].st;
float d = ray_intersect(NormalTex, dp, ds);
vec2 uv;
vec3 N;
if ( bump > 0.9 )
{
vec3 V = normalize(ecPosition.xyz);
float a = dot(VNormal, -V);
vec2 s = vec2(dot(V, VTangent), dot(V, VBinormal));
s *= depth_factor / a;
vec2 ds = s;
vec2 dp = gl_TexCoord[0].st;
float d = ray_intersect(NormalTex, dp, ds);
vec2 uv = dp + ds * d;
vec3 N = texture2D(NormalTex, uv).xyz * 2.0 - 1.0;
uv = dp + ds * d;
N = texture2D(NormalTex, uv).xyz * 2.0 - 1.0;
}
else
{
uv = gl_TexCoord[0].st;
N = vec3(0.0, 0.0, 1.0);
}
vec4 noisevec = texture3D(NoiseTex, (rawpos.xyz)*0.01*scale);

View file

@ -13,6 +13,7 @@ varying out vec3 VTangent;
varying out vec3 VBinormal;
varying out vec3 Normal;
varying out vec4 constantColor;
varying out float bump;
uniform float canopy_height;
@ -41,6 +42,7 @@ void createVertex(int i, int j, float offset, float s)
VNormal = normalize(gl_NormalMatrix * Normal);
VTangent = VTangentIn[i];
VBinormal = VBinormalIn[i];
bump = s;
gl_FrontColor = gl_FrontColorIn[i];
constantColor = gl_FrontMaterial.emission
@ -72,4 +74,8 @@ void main(void)
createVertex(1, 2, canopy_height, 1.0);
createVertex(2, 0, canopy_height, 1.0);
EndPrimitive();
createVertex(0, 1, 0.0, 0.0);
createVertex(1, 2, 0.0, 0.0);
createVertex(2, 0, 0.0, 0.0);
EndPrimitive();
}

View file

@ -5,6 +5,7 @@ varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 Normal;
varying vec4 constantColor;
varying float bump;
attribute vec3 tangent;
attribute vec3 binormal;
@ -17,6 +18,7 @@ void main(void)
VNormal = gl_NormalMatrix * gl_Normal;
VTangent = gl_NormalMatrix * tangent;
VBinormal = gl_NormalMatrix * binormal;
bump = 1.0;
gl_FrontColor = gl_Color;
constantColor = gl_FrontMaterial.emission