diff --git a/src/render/opengl/OpenGLVegetation.h b/src/render/opengl/OpenGLVegetation.h index 7703e68..c150eda 100644 --- a/src/render/opengl/OpenGLVegetation.h +++ b/src/render/opengl/OpenGLVegetation.h @@ -6,7 +6,7 @@ #include "OpenGLPart.h" #include "DefinitionWatcher.h" -#include +#include namespace paysages { namespace opengl { diff --git a/src/render/opengl/OpenGLVegetationImpostor.cpp b/src/render/opengl/OpenGLVegetationImpostor.cpp index ea5f50e..fa31f0c 100644 --- a/src/render/opengl/OpenGLVegetationImpostor.cpp +++ b/src/render/opengl/OpenGLVegetationImpostor.cpp @@ -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); } } } diff --git a/src/render/opengl/OpenGLVegetationImpostor.h b/src/render/opengl/OpenGLVegetationImpostor.h index 7d2aab5..b8d57fa 100644 --- a/src/render/opengl/OpenGLVegetationImpostor.h +++ b/src/render/opengl/OpenGLVegetationImpostor.h @@ -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. diff --git a/src/render/opengl/OpenGLVegetationLayer.cpp b/src/render/opengl/OpenGLVegetationLayer.cpp index 388d5b4..c9a8a53 100644 --- a/src/render/opengl/OpenGLVegetationLayer.cpp +++ b/src/render/opengl/OpenGLVegetationLayer.cpp @@ -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(); diff --git a/src/render/opengl/shaders/vegetation.vert b/src/render/opengl/shaders/vegetation.vert index 2df3f8d..ce5efec 100644 --- a/src/render/opengl/shaders/vegetation.vert +++ b/src/render/opengl/shaders/vegetation.vert @@ -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); }