vec3 inPosition;
layout(location = 1) in vec3 inTangent;
layout(location = 2) in vec3 inBitangent;
layout(location = 3) in vec3 inNormal;
layout(location = 4) in vec2 inTexCoord;
layout(binding = 0) uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
} ubo;
layout(location = 0) out vec2 fragTexCoord;
layout(location = 1) out vec3 TangentLightDirection;
vec3 lightDirection = vec3(0, 0, 1);
void main()
{
vec3 T = mat3(ubo.model) * inTangent;
vec3 B = mat3(ubo.model) * inBitangent;
vec3 N = mat3(ubo.model) * inNormal;
mat3 TBN = transpose(mat3(T, B, N));
TangentLightDirection = TBN * lightDirection;
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
fragTexCoord = inTexCoord;
}
Похоже
А как дальше в фрагментарном считать? Сейчас вот так layout(location = 0) in vec2 fragTexCoord; layout(location = 1) in vec3 TangentLightDirection; layout(binding = 1) uniform sampler2D terrainTextures[5]; layout(binding = 2) uniform sampler2D terrainNormals[5]; layout(binding = 3) uniform sampler2D normalMap; layout(binding = 4) uniform sampler2D textureMask; layout(location = 0) out vec4 outColor; vec3 lightDirection = vec3(0, 0, 1); void main() { vec3 normalColor; normalColor.xy = texture(normalMap, fragTexCoord).ag * 2.0 - 1.0; normalColor.z = sqrt(1.0 - normalColor.x * normalColor.x - normalColor.y * normalColor.y); float diff = max(dot(normalColor, lightDirection), 0.0); vec4 splat_alpha = texture(textureMask, fragTexCoord); outColor = texture(terrainTextures[0], fragTexCoord*4.0); outColor = outColor*diff; }
Обсуждают сегодня