I have created a terrainFragmentShader with an int array attached to a float array as you will soon see. By looking at the console output I know that the correct values are being uploaded but when I try to get them... Well, I'm not sure. No errors appear in the console but no texture appears on the terrain - not even the default one that I load before I get before calling the float from the map.
Here is my terrainVertexShader and the map I've previously mentioned is the biomeMap[]. I am certain that the size is correct
#version 430 core
in vec2 pass_textureCoordinates;
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec3 toCameraVector;
in int biomeSize;
out vec4 out_Color;
uniform sampler2D backgroundTexture;
uniform sampler2D sandTexture;
uniform sampler2D stoneTexture;
uniform vec3 lightColour;
uniform float shineDamper;
uniform float reflectivity;
uniform float biomeMap[16384];
void main(void) {
vec4 textureColour = texture(backgroundTexture, pass_textureCoordinates);
float c = biomeMap[int(pass_textureCoordinates.x) * 128 + int(pass_textureCoordinates.y)];
if(c < 110)
textureColour = texture(sandTexture, pass_textureCoordinates);
else if(c < 150)
textureColour = texture(stoneTexture, pass_textureCoordinates);
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDot = dot(unitNormal, unitLightVector);
float brightness = max(nDot, 0.25);
vec3 diffuse = brightness * lightColour;
out_Color = vec4(diffuse,1.0) * textureColour;
}
Here is my TerrainShader class:
public class TerrainShader extends ShaderProgram {
private static final String VERTEX_FILE = "src/shaders/terrainVertexShader.txt";
private static final String FRAGMENT_FILE = "src/shaders/terrainFragmentShader.txt";
private int location_backgroundTexture;
private int location_sandTexture;
private int location_stoneTexture;
private int location_biomeMap[];
public TerrainShader() {
super(VERTEX_FILE, FRAGMENT_FILE);
}
@Override
protected void bindAttributes() {
super.bindAttribute(0, "position");
super.bindAttribute(1, "textureCoordinates");
super.bindAttribute(2, "normal");
}
@Override
protected void getAllUniformLocations() {
location_backgroundTexture = super.getUniformLocation("backgroundTexture");
location_sandTexture = super.getUniformLocation("sandTexture");
location_stoneTexture = super.getUniformLocation("stoneTexture");
location_biomeMap = new int[16384];
for(int i = 0; i < location_biomeMap.length; i++) {
location_biomeMap[i] = super.getUniformLocation("biomeMap[" + i + "]");
}
}
public void connectTextures() {
super.loadInt(location_backgroundTexture, 0);
super.loadInt(location_sandTexture, 1);
super.loadInt(location_stoneTexture, 2);
}
public void loadBiomes(float[][] biomeMap) {
for(int x = 0; x < Terrain.VERTEX_COUNT; x++) {
for(int y = 0; y < Terrain.VERTEX_COUNT; y++) {
super.loadFloat(location_biomeMap[x * Terrain.VERTEX_COUNT + y], biomeMap[x][y] * 128 + 127);
}
}
}
}
I tried using a double array but it never worked so I am using a flat-multidimensional array instead. The array is working perfectly inside java but whenever I try to get the float, nothing happens - as if the file just returns nothing as the color without giving an error.
vec4 textureColour = texture(backgroundTexture, pass_textureCoordinates);
Loads the background, grass in this case, then it goes onto the next line:
float c = biomeMap[int(pass_textureCoordinates.x) * 128 + int(pass_textureCoordinates.y)];
if(c < 110)
textureColour = texture(sandTexture, pass_textureCoordinates);
else if(c < 150)
textureColour = texture(stoneTexture, pass_textureCoordinates);
The float c is a value between 0 and 255 and I try to assign a different texture depending on the value. I am going to add a blend at a later date but I'd like to get this basic version first.
Why is it not loading any texture? The issue seems to be getting the float from the biomeMap as when I manually set it, it works just fine. Terrain.VERTEX_COUNT is equal to 128.
↧