Hello, i was doing a tutorial on youtube about lwjgl and GLSL shaders.One of there newer videos cover blendMaps which work fine and good, but I would like it to be randomly generated blending as in some soil here and some flower texture there.Here’s my code for the terrainFragmentShader:
#version 400 core
in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec3 toCameraVector;
in float visibility;
out vec3 position;
out vec4 out_Colour;
uniform sampler2D backgroundTexture;
uniform sampler2D rTexture;
uniform sampler2D gTexture;
uniform sampler2D bTexture;
uniform sampler2D blendMap;
uniform vec3 lightColor;
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColor;
void main(void) {
vec4 blendMapColor = texture(blendMap,pass_textureCoords);
float backTextureAmount = 1 - (blendMapColor.r + blendMapColor.g + blendMapColor.b);
vec2 tiledCoords = pass_textureCoords * 40.0;
vec4 backgroundTextureColor = texture(backgroundTexture,tiledCoords) * backTextureAmount;
vec4 rTextureColor = texture(rTexture,tiledCoords) * blendMapColor.r;
vec4 gTextureColor = texture(gTexture,tiledCoords) * blendMapColor.g;
vec4 bTextureColor = texture(bTexture,tiledCoords) * blendMapColor.b;
vec4 totalColor = backgroundTextureColor + rTextureColor + gTextureColor + bTextureColor;
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDot1 = dot(unitNormal,unitLightVector);
float brightness = max(nDot1,0.4);
vec3 diffuse = brightness * lightColor;
vec3 unitVectorToCamera = normalize(toCameraVector);
vec3 lightDirection = -unitLightVector;
vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
float specularFactor = dot(reflectedLightDirection,unitVectorToCamera);
specularFactor = max(specularFactor,0.0);
float dampedFactor = pow(specularFactor,shineDamper);
vec3 finalSpecular = dampedFactor * reflectivity * lightColor;
out_Colour = vec4(diffuse,1.0) * totalColor + vec4(finalSpecular,1.0);
out_Colour = mix(vec4(skyColor,1.0),out_Colour,visibility);
}
Any help appreciated!