Assign to each TerrainTile a random color

This commit is contained in:
Sebastian 2023-10-05 12:33:47 +02:00
parent 9e09df3cf8
commit db7c533206
5 changed files with 21 additions and 1 deletions

BIN
client/res/hexagon.blend Normal file

Binary file not shown.

View File

@ -44,6 +44,7 @@ public class TerrainRenderer {
GL20.glEnableVertexAttribArray(2); GL20.glEnableVertexAttribArray(2);
GL13.glActiveTexture(GL13.GL_TEXTURE0); GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, terrainTile.getModel().getModelTexture().getTextureID()); GL11.glBindTexture(GL11.GL_TEXTURE_2D, terrainTile.getModel().getModelTexture().getTextureID());
shader.loadTerrainColor(terrainTile.getColor());
} }
private void unbindTexturedModel() { private void unbindTexturedModel() {

View File

@ -4,6 +4,7 @@ import core.engine.entity.Camera;
import core.engine.entity.Light; import core.engine.entity.Light;
import utils.MatrixGraphicUtils; import utils.MatrixGraphicUtils;
import utils.vectors.Matrix4f; import utils.vectors.Matrix4f;
import utils.vectors.Vector3f;
public class TerrainShader extends ShaderProgram{ public class TerrainShader extends ShaderProgram{
private static final String VERTEX_FILE = "src/main/java/core/engine/shader/terrainVertexShader.glsl"; private static final String VERTEX_FILE = "src/main/java/core/engine/shader/terrainVertexShader.glsl";
@ -14,6 +15,7 @@ public class TerrainShader extends ShaderProgram{
private int location_viewMatrix; private int location_viewMatrix;
private int location_lightPosition; private int location_lightPosition;
private int location_lightColor; private int location_lightColor;
private int location_terrainColor;
public TerrainShader() { public TerrainShader() {
super(VERTEX_FILE, FRAGMENT_FILE); super(VERTEX_FILE, FRAGMENT_FILE);
} }
@ -25,6 +27,7 @@ public class TerrainShader extends ShaderProgram{
this.location_viewMatrix = super.getUniformLocation("viewMatrix"); this.location_viewMatrix = super.getUniformLocation("viewMatrix");
this.location_lightColor = super.getUniformLocation("lightColor"); this.location_lightColor = super.getUniformLocation("lightColor");
this.location_lightPosition = super.getUniformLocation("lightPosition"); this.location_lightPosition = super.getUniformLocation("lightPosition");
this.location_terrainColor = super.getUniformLocation("terrainColor");
} }
@Override @Override
@ -51,4 +54,8 @@ public class TerrainShader extends ShaderProgram{
super.loadVector(location_lightPosition, light.getPosition()); super.loadVector(location_lightPosition, light.getPosition());
super.loadVector(location_lightColor, light.getColor()); super.loadVector(location_lightColor, light.getColor());
} }
public void loadTerrainColor(Vector3f color) {
super.loadVector(location_terrainColor, color);
}
} }

View File

@ -8,6 +8,7 @@ out vec4 out_Color;
uniform sampler2D textureSampler; uniform sampler2D textureSampler;
uniform vec3 lightColor; uniform vec3 lightColor;
uniform vec3 terrainColor;
void main(void) { void main(void) {
vec3 unitNormal = normalize(surfaceNormal); vec3 unitNormal = normalize(surfaceNormal);
@ -17,5 +18,5 @@ void main(void) {
float brightness = max(nDotl, 0.2); float brightness = max(nDotl, 0.2);
vec3 diffusde = brightness * lightColor; vec3 diffusde = brightness * lightColor;
out_Color = texture(textureSampler, pass_textureCoords); out_Color = /*vec4(diffusde, 1.0) **/ vec4(terrainColor, 1);
} }

View File

@ -13,6 +13,8 @@ public class TerrainTile {
private float rotX, rotY, rotZ; private float rotX, rotY, rotZ;
private float scale; private float scale;
private Vector3f color;
public TerrainTile(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, float scale) { public TerrainTile(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, float scale) {
this.model = model; this.model = model;
this.position = position; this.position = position;
@ -20,6 +22,7 @@ public class TerrainTile {
this.rotY = rotY; this.rotY = rotY;
this.rotZ = rotZ; this.rotZ = rotZ;
this.scale = scale; this.scale = scale;
this.color = new Vector3f((float) Math.random(), (float) Math.random(), (float) Math.random());
} }
public TexturedModel getModel() { public TexturedModel getModel() {
@ -69,4 +72,12 @@ public class TerrainTile {
public void setScale(float scale) { public void setScale(float scale) {
this.scale = scale; this.scale = scale;
} }
public Vector3f getColor() {
return color;
}
public void setColor(Vector3f color) {
this.color = color;
}
} }