I have a float[][] array in my terrainFragmentShader to load render the biomes, however the code simply does not work. No errors are being cast and when I remove the code biomeMap[int(pass_textureCoordinates.x)][int(pass_textureCoordinates.y)] by either deleting that section or manually setting it, it loads the appropriate texture.
vec4 textureColour = texture(backgroundTexture, pass_textureCoordinates);
float c = biomeMap[int(pass_textureCoordinates.x)][int(pass_textureCoordinates.y)];
if(c < 0)
textureColour = texture(sandTexture, pass_textureCoordinates);
else if(c < 32)
textureColour = texture(stoneTexture, pass_textureCoordinates);
All three textures load just fine and are rendered when not using this method and the biomes are being properly loaded and initialized.
Loading:
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][y], biomeMap[x][y]);
}
}
}
Initializing:
location_biomeMap = new int[Terrain.VERTEX_COUNT][Terrain.VERTEX_COUNT];
for(int x = 0; x < Terrain.VERTEX_COUNT; x++) {
for(int y = 0; y < Terrain.VERTEX_COUNT; y++) {
location_biomeMap[x][y] = super.getUniformLocation("biomeMap[" + x + "][" + y + "]");
}
}
And finally here is the entire terrainFragmentShader:
#version 400 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[128][128];
uniform float offsetX;
uniform float offsetZ;
const int levels = 32;
void main(void){
vec4 textureColour = texture(backgroundTexture, pass_textureCoordinates);
float c = biomeMap[int(pass_textureCoordinates.x)][int(pass_textureCoordinates.y)];
if(c < 0)
textureColour = texture(sandTexture, pass_textureCoordinates);
else if(c < 32)
textureColour = texture(stoneTexture, pass_textureCoordinates);
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDotl = dot(unitNormal,unitLightVector);
float brightness = max(nDotl, 0.25);
vec3 unitVectorToCamera = normalize(toCameraVector);
vec3 lightDirection = -unitLightVector;
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
vec3 totalDiffuse = brightness * lightColour;
out_Color = vec4(totalDiffuse,1.0) * textureColour;
}
Why isn't the biome not loading? Is it an issue in me not getting the appropriate [x][y] from the pass_textureCoordinates?