Proper texture tiling for terrain meshes

This commit is contained in:
austin 2021-10-06 19:38:34 -04:00
parent c295a18a22
commit 26064dc198
5 changed files with 36 additions and 17 deletions

View File

@ -2,8 +2,8 @@
"gameplayGenerateWorld" : false,
"gameplayPhysicsCellRadius" : 2,
"displayWidth" : 2560,
"displayHeight" : 1600,
"displayWidth" : 1920,
"displayHeight" : 1080,
"graphicsFOV" : 90.0,

View File

@ -118,7 +118,7 @@ void main(){
//}
//result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
FragColor = vec4(result, texture(material.diffuse, TexCoord).a);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
FragColor = vec4(result, 1);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
}
// calculates the color when using a directional light.
@ -233,5 +233,5 @@ vec3 blendedTextureColor(vec2 texPos, vec4 tex1, vec4 tex2, vec4 tex3, vec4 tex4
// float percentTex2 = (texPos.x - 0) * (texPos.y - 1);
// float percentTex3 = (texPos.x - 1) * (texPos.y - 0);
// float percentTex4 = (texPos.x - 0) * (texPos.y - 0);
return vec3(0,0,0);//mix(mix(tex1,tex2,texPos.x),mix(tex3,tex4,texPos.x),texPos.y).rgb;
return mix(mix(tex1,tex2,texPos.x),mix(tex3,tex4,texPos.x),texPos.y).rgb;
}

View File

@ -10,9 +10,11 @@ import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.terrain.processing.TerrainInterpolator;
import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import electrosphere.renderer.Mesh;
import electrosphere.renderer.Model;
import electrosphere.renderer.ModelUtils;
import electrosphere.renderer.ShaderProgram;
import electrosphere.renderer.texture.Texture;
import electrosphere.util.Utilities;
import org.joml.Quaternionf;
import org.joml.Vector3f;
@ -35,7 +37,17 @@ public class DrawCell {
CollisionObject physicsObject;
static Texture groundTextureOne;
static Texture groundTextureTwo;
static Texture groundTextureThree;
static Texture groundTextureFour;
static {
groundTextureOne = new Texture("/Textures/Ground/Dirt1.png");
groundTextureTwo = new Texture("/Textures/wheat1.png");
groundTextureThree = new Texture("/Textures/Ground/Dirt1.png");
groundTextureFour = new Texture("/Textures/Ground/Dirt1.png");
}
DrawCell(){
@ -52,12 +64,7 @@ public class DrawCell {
* ITS NOT EVEN UP TO DATE!
* 06/13/2021
*
* @param drawArray
* @param drawWidth
* @param cellX
* @param cellY
* @param cellWidth
* @param program
* //@param drawArray
*/
public static DrawCell generateTerrainCell(
int cellX,
@ -84,6 +91,12 @@ public class DrawCell {
Globals.entityManager.deregisterEntity(modelEntity);
}
Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(heightmap, program, stride);
Mesh terrainMesh = terrainModel.meshes.get(0);
terrainMesh.useTextureList = true;
terrainMesh.textureList.add(groundTextureOne);
terrainMesh.textureList.add(groundTextureTwo);
terrainMesh.textureList.add(groundTextureThree);
terrainMesh.textureList.add(groundTextureFour);
String terrainModelPath = Globals.assetManager.registerModel(terrainModel);
modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath);
modelEntity.putData(EntityDataStrings.TERRAIN_IS_TERRAIN, true);

View File

@ -94,7 +94,7 @@ public class DrawCellManager {
cellX = discreteX;
cellY = discreteY;
program = Globals.defaultMeshShader;
program = Globals.terrainShaderProgram;
drawRadius = Globals.userSettings.getGraphicsPerformanceLODChunkRadius();
drawStepdownInterval = Globals.userSettings.getGameplayPhysicsCellRadius();

View File

@ -73,7 +73,7 @@ public class Mesh {
boolean hasBones = true;
public boolean hasTextureCoords = true;
public List<Texture> textureList;
public List<Texture> textureList = new ArrayList();
public boolean useTextureList;
public String textureListArrayUniformName;
@ -758,11 +758,7 @@ public class Mesh {
}
}
if(useTextureList){
for(Texture texture : textureList){
}
}
@ -774,6 +770,16 @@ public class Mesh {
glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "shadowMap"), 3);
}
if(useTextureList){
int i = 0;
glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "groundTextures"),4);
for(Texture texture : textureList){
// glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "groundTextures[" + 4+i*2 + "]"),4+i*2);
texture.bind(4+i*2);
i++;
}
}
if(setBones){
//