vegetation: Removed index variable in impostor shader

It was used for texture coordinates, but is now
precomputed in the vertex array
This commit is contained in:
Michaël Lemaire 2015-12-15 00:14:06 +01:00
parent da5219c01f
commit d2b4a1ea5e
5 changed files with 7 additions and 11 deletions

View file

@ -6,7 +6,7 @@
#include "OpenGLPart.h"
#include "DefinitionWatcher.h"
#include <map>
#include <vector>
namespace paysages {
namespace opengl {

View file

@ -53,14 +53,13 @@ OpenGLVegetationImpostor::~OpenGLVegetationImpostor() {
}
void OpenGLVegetationImpostor::render(OpenGLShaderProgram *program, const OpenGLVegetationInstance *instance,
int instance_index, const Vector3 &camera_location) {
if (instance_index == 0 or texture_changed) {
const Vector3 &camera_location) {
if (texture_changed) {
texture_changed = false;
state->set("impostorTexture", texture);
}
int index = getIndex(camera_location, instance->getBase());
state->setInt("index", index);
state->set("offset", instance->getBase());
state->set("size", 2.0 * instance->getSize());
program->draw(vertices, state, index * 4, 4);
@ -142,7 +141,7 @@ void OpenGLVegetationImpostor::setVertex(int i, float u, float v) {
Matrix4 rotation = matrixForIndex(index);
Vector3 vertex = rotation.multPoint(Vector3(1.0, u, -(v - 0.5)));
vertices->set(index * 4 + i, vertex, u, v);
vertices->set(index * 4 + i, vertex, (u + (double)px) / (double)parts, (v + (double)py) / (double)parts);
}
}
}

View file

@ -21,8 +21,7 @@ class OPENGLSHARED_EXPORT OpenGLVegetationImpostor {
/**
* Render a single instance using this impostor.
*/
void render(OpenGLShaderProgram *program, const OpenGLVegetationInstance *instance, int instance_index,
const Vector3 &camera_location);
void render(OpenGLShaderProgram *program, const OpenGLVegetationInstance *instance, const Vector3 &camera_location);
/**
* Prepare the texture grid for a given model.

View file

@ -115,9 +115,8 @@ void OpenGLVegetationLayer::render() {
lock_instances->acquire();
// TODO Instanced rendering
int index = 0;
for (auto instance : instances) {
impostor->render(parent->getProgram(), instance, index++, *camera_location);
impostor->render(parent->getProgram(), instance, *camera_location);
}
lock_instances->release();

View file

@ -3,7 +3,6 @@ in highp vec2 uv;
uniform highp mat4 viewMatrix;
uniform highp vec3 offset;
uniform float size;
uniform int index;
out vec3 unprojected;
out vec2 texcoord;
uniform float waterOffset;
@ -11,6 +10,6 @@ uniform float waterOffset;
void main(void)
{
unprojected = offset + size * vertex; // + vec3(0, waterOffset, 0)
texcoord = vec2(0.25 * (uv.s + float(mod(index, 4))), 0.25 * (uv.t + float(index / 4)));
texcoord = uv;
gl_Position = viewMatrix * vec4(unprojected, 1.0);
}