diff --git a/Effects/landmass.eff b/Effects/landmass.eff index cf2fd86a5..ad54d0aac 100644 --- a/Effects/landmass.eff +++ b/Effects/landmass.eff @@ -16,6 +16,116 @@ 6 7 + + + + /sim/rendering/landmass-shader + /sim/rendering/shader-effects + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + GL_EXT_geometry_shader4 + + + + true + + material/ambient + material/diffuse + material/specular + ambient-and-diffuse + + transparent + transparent + smooth + back + + render-bin/bin-number + render-bin/bin-name + + + 0 + noise + + + 1 + texture[0]/image + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + + texture[0]/internal-format + + + + 2 + texture[2]/image + texture[2]/filter + texture[2]/wrap-s + texture[2]/wrap-t + + texture[2]/internal-format + + + + Shaders/landmass-g.vert + Shaders/landmass.geom + Shaders/landmass.frag + 16 + triangles + triangle-strip + + tangent + 6 + + + binormal + 7 + + + + NoiseTex + sampler-3d + 0 + + + BaseTex + sampler-2d + 1 + + + NormalTex + sampler-2d + 2 + + + depth_factor + float + 0.01 + + + canopy_height + float + 10.0 + + + snowlevel + float + + snow-level + + + + diff --git a/Shaders/landmass-g.vert b/Shaders/landmass-g.vert new file mode 100644 index 000000000..fe89ab7a3 --- /dev/null +++ b/Shaders/landmass-g.vert @@ -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; +} diff --git a/Shaders/landmass.geom b/Shaders/landmass.geom new file mode 100644 index 000000000..16254ac14 --- /dev/null +++ b/Shaders/landmass.geom @@ -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(); +}