[ad_1]
I’ve been making an attempt to get lighting to work with my grass shader and I wished so as to add considerably a traditional map? it’s simply two normlas that type a gradient I assume.
However what I get is nothing.. no shadows in any respect for some motive… I’m certain that I’ve calculated my normals appropriately:
And right here is the nothing that I get:
It ought to considerably make the grass look spherical however I get nothing.
I attempted to get the TBN matrix and multiply it by the sunshine following the opengl tutorial website however nonetheless nothing.
Listed below are my fragment and vertex shaders:
#model 430 core
in vec2 TexCoords;
in vec3 FragPos;
in vec3 Regular;
in vec3 LightDir;
in vec3 ViewPos;
out vec4 pixelColor;
// Lighting
float normal1 = -1.0;
float normal2 = 1.0;
float ambientStrength = 0.4;
vec3 LightColor = vec3(1.0, 1.0, 1.0);
void principal() {
vec4 outcome;
vec4 col1 = vec4(0.183, 0.171, 0.140, 1);
vec4 col2 = vec4(0.871, 0.910, 0.816, 1);
float t = invLerp(0.2, 1.0, TexCoords.y);
vec4 objectColor = combine(col1, col2, t);
// ambient
vec3 ambient = ambientStrength * LightColor;
// diffuse
float t1 = invLerp(0.4, 0.6, TexCoords.x);
float regular = combine(normal1.x, normal2.x, t1);
vec3 diff = min(dot(vec3(regular.x, 0.0, 0.0), LightDir).xxx, 0.0);
vec3 diffuse = diff * LightColor;
//vec3 normalizedColor = (vec3(regular, 0.0, 0.0) + 1.0) * 0.5;
//outcome = vec4(normalizedColor, 1.0);
outcome = vec4( (ambient + diffuse) * objectColor.xyz, 1.0);
pixelColor = outcome;
}
Vertex shader:
#model 430 core
structure (location = 0) in vec3 aPosition;
structure (location = 1) in vec3 aNormal;
structure (location = 2) in vec3 aTangent;
structure (location = 3) in vec2 aTexCoords;
struct GrassInstance {
vec3 place;
float top;
float angle;
};
structure(std430, binding = 0) buffer GrassData {
GrassInstance outcome[];
};
out vec2 TexCoords;
out vec3 FragPos;
out vec3 Regular;
out vec3 LightDir;
uniform mat4 mannequin;
uniform mat4 view;
uniform mat4 projection;
uniform float time;
mat4 rotateY(float a){
mat4 mat = mat4(cos(a), 0.0, sin(a), 0.0,
0.0, 1.0, 0.0, 0.0,
-sin(a), 0.0, cos(a), 0.0,
0.0, 0.0, 0.0, 1.0);
return mat;
}
void principal() {
// calculate tbn matrix
vec3 T = normalize(vec3(mannequin * vec4(aTangent, 0.0)));
vec3 N = normalize(vec3(mannequin * vec4(aNormal, 0.0)));
T = normalize(T - dot(T, N) * N);
vec3 B = cross(N, T);
mat3 TBN = mat3(T, B, N);
//
float angle = radians(outcome[gl_InstanceID].angle);
float top = outcome[gl_InstanceID].top;
TexCoords = aTexCoords;
Regular = mat3(transpose(inverse(mannequin))) * aNormal;
Regular = normalize(Regular * TBN);
LightDir = vec3(0.0, 0.0, 1.0) * TBN;
vec4 pos = vec4(aPosition, 1.0);
pos = pos * rotateY(angle);
FragPos = vec3(mannequin * pos) * TBN;
gl_Position = projection * view * mannequin * vec4((pos.xyz * vec3(1.0, 0.5 + top, 1.0)) + outcome[gl_InstanceID].place, 1.0);
}
[ad_2]