1
0
Fork 0

Another go at the landmass geometry shader, using fewer varying parameters

Author: Tim Moore <timoore@redhat.com>
This commit is contained in:
timoore 2010-04-30 15:20:36 +00:00
parent 9e12bcb88c
commit 74f70ee3e4
2 changed files with 15 additions and 11 deletions

View file

@ -15,18 +15,14 @@
// model position of original terrain poly; the bottom of the forest. // model position of original terrain poly; the bottom of the forest.
varying vec4 rawposIn; varying vec4 rawposIn;
// model forest top
varying vec4 rawTopIn;
// model normal // model normal
varying vec3 NormalIn; varying vec3 NormalIn;
varying vec4 ecPosIn; varying vec4 ecPosIn;
varying vec4 ecTopIn;
varying vec3 ecNormalIn; varying vec3 ecNormalIn;
// eye spacce tangent and binormal // eye spacce tangent and binormal
varying vec3 VTangentIn; varying vec3 VTangentIn;
varying vec3 VBinormalIn; varying vec3 VBinormalIn;
// screen-space position of top // screen-space position of top
varying vec4 positionTopIn;
// constant color component // constant color component
varying vec4 constantColorIn; varying vec4 constantColorIn;
@ -40,15 +36,15 @@ void main(void)
rawposIn = gl_Vertex; rawposIn = gl_Vertex;
ecPosIn = gl_ModelViewMatrix * gl_Vertex; ecPosIn = gl_ModelViewMatrix * gl_Vertex;
NormalIn = normalize(gl_Normal); NormalIn = normalize(gl_Normal);
rawTopIn = rawposIn + vec4(0.0, 0.0, canopy_height, 0.0); //rawTopIn = rawposIn + vec4(0.0, 0.0, canopy_height, 0.0);
ecTopIn = gl_ModelViewMatrix * rawTopIn; //ecTopIn = gl_ModelViewMatrix * rawTopIn;
ecNormalIn = gl_NormalMatrix * NormalIn; ecNormalIn = gl_NormalMatrix * NormalIn;
VTangentIn = gl_NormalMatrix * tangent; VTangentIn = gl_NormalMatrix * tangent;
VBinormalIn = gl_NormalMatrix * binormal; VBinormalIn = gl_NormalMatrix * binormal;
gl_FrontColor = gl_Color; gl_FrontColor = gl_Color;
gl_Position = ftransform(); gl_Position = ftransform();
positionTopIn = gl_ModelViewProjectionMatrix * rawTopIn; //positionTopIn = gl_ModelViewProjectionMatrix * rawTopIn;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
constantColorIn = gl_FrontMaterial.emission constantColorIn = gl_FrontMaterial.emission
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient); + gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);

View file

@ -9,13 +9,10 @@
// See landmass-g.vert for a description of the inputs. // See landmass-g.vert for a description of the inputs.
varying in vec4 rawposIn[]; varying in vec4 rawposIn[];
varying in vec3 NormalIn[]; varying in vec3 NormalIn[];
varying in vec4 rawTopIn[];
varying in vec4 ecPosIn[]; varying in vec4 ecPosIn[];
varying in vec4 ecTopIn[];
varying in vec3 ecNormalIn[]; varying in vec3 ecNormalIn[];
varying in vec3 VTangentIn[]; varying in vec3 VTangentIn[];
varying in vec3 VBinormalIn[]; varying in vec3 VBinormalIn[];
varying in vec4 positionTopIn[];
varying in vec4 constantColorIn[]; varying in vec4 constantColorIn[];
uniform float canopy_height; uniform float canopy_height;
@ -67,14 +64,25 @@ void doSideVertex(in int vertIdx, in int sideIdx, vec4 pos, in vec4 ecpos,
void main(void) void main(void)
{ {
vec4 rawTopDisp = vec4(0.0, 0.0, canopy_height, 0.0);
vec4 ecTopDisp = gl_ModelViewMatrix * rawTopDisp;
vec4 mvpTopDisp = gl_ModelViewProjectionMatrix * rawTopDisp;
// model forest top
vec4 rawTopIn[3];
vec4 ecTopIn[3];
vec4 positionTopIn[3];
rawSideNormal[0] = normalize(cross((rawposIn[1] - rawposIn[0]).xyz, rawSideNormal[0] = normalize(cross((rawposIn[1] - rawposIn[0]).xyz,
NormalIn[0])); NormalIn[0]));
rawSideNormal[1] = normalize(cross((rawposIn[2] - rawposIn[1]).xyz, rawSideNormal[1] = normalize(cross((rawposIn[2] - rawposIn[1]).xyz,
NormalIn[1])); NormalIn[1]));
rawSideNormal[2] = normalize(cross((rawposIn[0] - rawposIn[2]).xyz, rawSideNormal[2] = normalize(cross((rawposIn[0] - rawposIn[2]).xyz,
NormalIn[2])); NormalIn[2]));
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i) {
sideNormal[i] = gl_NormalMatrix * rawSideNormal[i]; sideNormal[i] = gl_NormalMatrix * rawSideNormal[i];
rawTopIn[i] = rawposIn[i] + rawTopDisp;
ecTopIn[i] = ecPosIn[i] + ecTopDisp;
positionTopIn[i] = gl_PositionIn[i] + mvpTopDisp;
}
if (canopy_height > 0.01) { if (canopy_height > 0.01) {
// Sides // Sides
doSideVertex(0, 0, rawTopIn[0], ecTopIn[0], positionTopIn[0]); doSideVertex(0, 0, rawTopIn[0], ecTopIn[0], positionTopIn[0]);