1
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

For multidimensional arrays in GLSL you need either one of two requirements:

  • Support the extension GL_ARB_arrays_of_arrays or
  • Use GLSL version 430 (in which the mentioned extension became core)
\$\endgroup\$
9
  • \$\begingroup\$ I changed the core version 430, however nothing noticeable changed. Could you elaborate on how to support the extension? \$\endgroup\$ Jul 9, 2017 at 21:06
  • \$\begingroup\$ You don't need to do anything to support it, if it is supported by your driver you can just enable it. Try #extension GL_ARB_arrays_of_arrays: enable \$\endgroup\$
    – cozmic
    Jul 9, 2017 at 21:12
  • \$\begingroup\$ Or require it, this is basically the same as enabling but throws an error if it is unsupported #extension GL_ARB_arrays_of_arrays:require \$\endgroup\$
    – cozmic
    Jul 9, 2017 at 21:13
  • \$\begingroup\$ Also, did you also change the version tag in your shader to #version 430 core? Because it needs this to compile against this version, not just the context version \$\endgroup\$
    – cozmic
    Jul 9, 2017 at 21:15
  • \$\begingroup\$ I set the version to 430 in both the vertex and fragment shader and set the extension to be required, however it is still not working. \$\endgroup\$ Jul 9, 2017 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .