Rain: Avoid making a draw call that won't be used and make some cleanup

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14811 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
vincentlj
2013-12-27 16:37:24 +00:00
parent 224b246f17
commit 9826af0747
4 changed files with 11 additions and 31 deletions

View File

@@ -1,6 +1,5 @@
#version 130
uniform sampler2D tex;
uniform float bdiscard = 0.0;
uniform sampler2D normals_and_depth;
uniform mat4 invproj;
uniform vec2 screen;
@@ -16,8 +15,6 @@ void main()
EnvPos /= EnvPos.w;
float len = dot(vec3(1.0), abs(texture2D(normals_and_depth, xy).xyz));
float alpha = (len < 0.2) ? 1. : clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.);
if (bdiscard < 0.5)
discard;
gl_FragColor = texture2D(tex, gl_PointCoord.xy);
gl_FragColor.a *= alpha;
}

View File

@@ -1,3 +1,4 @@
#version 130
uniform float screenw;
void main()

View File

@@ -1,3 +1,4 @@
#version 130
uniform float time;
uniform vec3 campos;
uniform mat4 viewm;
@@ -24,4 +25,5 @@ void main()
start.xyz += campos;
currentPosition = (viewm * start).xyz;
gl_Position = vec4(0.);
}

View File

@@ -280,7 +280,8 @@ public:
glUniform1f(lscreenw, screenw);
glDrawArrays(GL_POINTS, 0, count);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
}
};
@@ -308,16 +309,6 @@ public:
count = 2500;
area = 3500;
// Fill in the mesh buffer
buf.Vertices.clear();
buf.Indices.clear();
buf.Vertices.set_used(count);
buf.Indices.set_used(count);
buf.Primitive = EPT_POINT_SPRITES;
buf.setHardwareMappingHint(EHM_STATIC);
u32 i;
float x, y, z, vertices[7500];
for (i = 0; i < count; i++)
@@ -326,8 +317,6 @@ public:
y = ((rand() % 2400)) / 100.0f;
z = ((rand() % area) - area/2) / 100.0f;
buf.Indices[i] = i;
buf.Vertices[i] = S3DVertex(x, y, z, 0, 0, 0, SColor(255, 255, 0, 0), 0, 0);
vertices[3 * i] = x;
vertices[3 * i + 1] = y;
vertices[3 * i + 2] = z;
@@ -340,24 +329,17 @@ public:
~RainNode()
{
delete gpupart;
delete gpupart;
}
virtual void render()
{
gpupart->simulate();
gpupart->render();
// We need to let irrlicht render something so it updates its internal states
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
{
gpupart->simulate();
gpupart->render();
// We need to force irrlicht to update its internal states
IVideoDriver * const drv = irr_driver->getVideoDriver();
mat.setTexture(1, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
drv->setTransform(ETS_WORLD, AbsoluteTransformation);
drv->setMaterial(mat);
drv->drawMeshBuffer(&buf);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
static_cast<COpenGLDriver*>(drv)->setRenderStates3DMode();
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
@@ -384,8 +366,6 @@ private:
core::aabbox3d<f32> box;
u32 count;
s32 area;
scene::SMeshBuffer buf;
};
// The rain manager