Render random colorized TerrainTiles
This commit is contained in:
parent
11f5fa99fe
commit
2464231d41
@ -4,7 +4,7 @@ import utils.vectors.Vector3f;
|
||||
|
||||
public class Camera {
|
||||
|
||||
private Vector3f position = new Vector3f(0,2,0);
|
||||
private Vector3f position = new Vector3f(0,50,0);
|
||||
private float pitch = 90;
|
||||
private float yaw = 180;
|
||||
private float roll;
|
||||
|
@ -40,19 +40,17 @@ public class TerrainRenderer {
|
||||
for(TerrainTile terrainTile : terrainTiles) {
|
||||
prepareTexturedModel(terrainTile.getModel());
|
||||
prepareInstance(terrainTile);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, terrainTile.getModel().getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
shader.loadColor(terrainTile.getColor());
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, terrainTile.getModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
unbindTexturedModel();
|
||||
}
|
||||
|
||||
private void prepareTexturedModel(TexturedModel model) {
|
||||
RawModel rawModel = model.getRawModel();
|
||||
GL30.glBindVertexArray(rawModel.getVaoID());
|
||||
private void prepareTexturedModel(RawModel model) {
|
||||
GL30.glBindVertexArray(model.getVaoID());
|
||||
GL20.glEnableVertexAttribArray(0);
|
||||
GL20.glEnableVertexAttribArray(1);
|
||||
GL20.glEnableVertexAttribArray(2);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getModelTexture().getTextureID());
|
||||
}
|
||||
|
||||
private void unbindTexturedModel() {
|
||||
|
@ -4,6 +4,7 @@ import core.engine.entity.Camera;
|
||||
import core.engine.entity.Light;
|
||||
import utils.MatrixGraphicUtils;
|
||||
import utils.vectors.Matrix4f;
|
||||
import utils.vectors.Vector3f;
|
||||
|
||||
public class TerrainShader extends ShaderProgram{
|
||||
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_lightPosition;
|
||||
private int location_lightColor;
|
||||
private int location_color;
|
||||
public TerrainShader() {
|
||||
super(VERTEX_FILE, FRAGMENT_FILE);
|
||||
}
|
||||
@ -25,6 +27,7 @@ public class TerrainShader extends ShaderProgram{
|
||||
this.location_viewMatrix = super.getUniformLocation("viewMatrix");
|
||||
this.location_lightColor = super.getUniformLocation("lightColor");
|
||||
this.location_lightPosition = super.getUniformLocation("lightPosition");
|
||||
this.location_color = super.getUniformLocation("color");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,4 +54,8 @@ public class TerrainShader extends ShaderProgram{
|
||||
super.loadVector(location_lightPosition, light.getPosition());
|
||||
super.loadVector(location_lightColor, light.getColor());
|
||||
}
|
||||
|
||||
public void loadColor(Vector3f color) {
|
||||
super.loadVector(location_color, color);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
#version 400 core
|
||||
|
||||
in vec2 pass_textureCoords;
|
||||
in vec3 surfaceNormal;
|
||||
in vec3 toLightVector;
|
||||
|
||||
out vec4 out_Color;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 color;
|
||||
|
||||
void main(void) {
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
@ -17,5 +16,5 @@ void main(void) {
|
||||
float brightness = max(nDotl, 0.2);
|
||||
vec3 diffusde = brightness * lightColor;
|
||||
|
||||
out_Color = vec4(1,1,1,1);
|
||||
out_Color = vec4(color,1);
|
||||
}
|
@ -33,10 +33,10 @@ public class Terrain {
|
||||
if(y % 2 == 0) {
|
||||
xPos -= 0.866f;
|
||||
}
|
||||
generatedTerrainTiles.add(new TerrainTile(hexagontexturedModel, new Vector3f(xPos , 0, y * -1.4999994f), 0, 0, 0,1));
|
||||
Vector3f randomColor = new Vector3f((float) Math.random(), (float) Math.random(), (float) Math.random());
|
||||
generatedTerrainTiles.add(new TerrainTile(hexagonRawModel, new Vector3f(xPos , 0, y * -1.4999994f), 0, 0, 0,1, randomColor));
|
||||
}
|
||||
}
|
||||
generatedTerrainTiles.add(new TerrainTile(hexagontexturedModel, new Vector3f(0 , 0, 0), 0, 0, 0,1));
|
||||
|
||||
System.out.println(31 * 1.7319988f);
|
||||
|
||||
|
@ -8,21 +8,23 @@ import utils.vectors.Vector3f;
|
||||
|
||||
public class TerrainTile {
|
||||
|
||||
private TexturedModel model;
|
||||
private RawModel model;
|
||||
private final Vector3f position;
|
||||
private final float rotX, rotY, rotZ;
|
||||
private final float scale;
|
||||
private Vector3f color;
|
||||
|
||||
public TerrainTile(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, float scale) {
|
||||
public TerrainTile(RawModel model, Vector3f position, float rotX, float rotY, float rotZ, float scale, Vector3f color) {
|
||||
this.model = model;
|
||||
this.position = position;
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
this.scale = scale;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public TexturedModel getModel() {
|
||||
public RawModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
@ -45,4 +47,8 @@ public class TerrainTile {
|
||||
public float getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public Vector3f getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user