Another go at the landmass geometry shader, using fewer varying parameters
Author: Tim Moore <timoore@redhat.com>
This commit is contained in:
parent
9e12bcb88c
commit
74f70ee3e4
2 changed files with 15 additions and 11 deletions
|
@ -15,18 +15,14 @@
|
|||
|
||||
// model position of original terrain poly; the bottom of the forest.
|
||||
varying vec4 rawposIn;
|
||||
// model forest top
|
||||
varying vec4 rawTopIn;
|
||||
// model normal
|
||||
varying vec3 NormalIn;
|
||||
varying vec4 ecPosIn;
|
||||
varying vec4 ecTopIn;
|
||||
varying vec3 ecNormalIn;
|
||||
// eye spacce tangent and binormal
|
||||
varying vec3 VTangentIn;
|
||||
varying vec3 VBinormalIn;
|
||||
// screen-space position of top
|
||||
varying vec4 positionTopIn;
|
||||
// constant color component
|
||||
varying vec4 constantColorIn;
|
||||
|
||||
|
@ -40,15 +36,15 @@ void main(void)
|
|||
rawposIn = gl_Vertex;
|
||||
ecPosIn = gl_ModelViewMatrix * gl_Vertex;
|
||||
NormalIn = normalize(gl_Normal);
|
||||
rawTopIn = rawposIn + vec4(0.0, 0.0, canopy_height, 0.0);
|
||||
ecTopIn = gl_ModelViewMatrix * rawTopIn;
|
||||
//rawTopIn = rawposIn + vec4(0.0, 0.0, canopy_height, 0.0);
|
||||
//ecTopIn = gl_ModelViewMatrix * rawTopIn;
|
||||
ecNormalIn = gl_NormalMatrix * NormalIn;
|
||||
VTangentIn = gl_NormalMatrix * tangent;
|
||||
VBinormalIn = gl_NormalMatrix * binormal;
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_Position = ftransform();
|
||||
positionTopIn = gl_ModelViewProjectionMatrix * rawTopIn;
|
||||
//positionTopIn = gl_ModelViewProjectionMatrix * rawTopIn;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
constantColorIn = gl_FrontMaterial.emission
|
||||
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||
|
|
|
@ -9,13 +9,10 @@
|
|||
// See landmass-g.vert for a description of the inputs.
|
||||
varying in vec4 rawposIn[];
|
||||
varying in vec3 NormalIn[];
|
||||
varying in vec4 rawTopIn[];
|
||||
varying in vec4 ecPosIn[];
|
||||
varying in vec4 ecTopIn[];
|
||||
varying in vec3 ecNormalIn[];
|
||||
varying in vec3 VTangentIn[];
|
||||
varying in vec3 VBinormalIn[];
|
||||
varying in vec4 positionTopIn[];
|
||||
varying in vec4 constantColorIn[];
|
||||
|
||||
uniform float canopy_height;
|
||||
|
@ -67,14 +64,25 @@ void doSideVertex(in int vertIdx, in int sideIdx, vec4 pos, in vec4 ecpos,
|
|||
|
||||
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,
|
||||
NormalIn[0]));
|
||||
rawSideNormal[1] = normalize(cross((rawposIn[2] - rawposIn[1]).xyz,
|
||||
NormalIn[1]));
|
||||
rawSideNormal[2] = normalize(cross((rawposIn[0] - rawposIn[2]).xyz,
|
||||
NormalIn[2]));
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int i = 0; i < 3; ++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) {
|
||||
// Sides
|
||||
doSideVertex(0, 0, rawTopIn[0], ecTopIn[0], positionTopIn[0]);
|
||||
|
|
Loading…
Reference in a new issue