ho3/resources/shaders/directlight.vertex

46 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2024-06-08 17:55:56 +00:00
attribute vec3 vPosition;
attribute vec2 vTexCoord;
uniform mat4 ProjectionMatrix;
2024-06-06 13:25:38 +00:00
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
varying vec2 texCoord;
varying vec3 vertexPos;
void main()
{
2024-06-08 17:55:56 +00:00
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
gl_Position = ProjectionMatrix * realVertexPos;
vertexPos = gl_Position.xyz;
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
texCoord = vTexCoord.st;
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
//vertexPos = vPosition.xyz;
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
//vec3 cVec = (CamPos - vPosition.xyz);
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
/*
vec3 lVec = normalize(gl_LightSource[0].position.xyz);
vec3 cVec = (CamPos - vPosition.xyz);
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
vertexPos = vPosition.xyz;
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
// Используем производные для вычисления тангентного и бинормального вектора
vec3 dp1 = dFdx(vPosition.xyz);
vec3 dp2 = dFdy(vPosition.xyz);
vec2 duv1 = dFdx(vTexCoord.st);
vec2 duv2 = dFdy(vTexCoord.st);
vec3 tangent = normalize(dp1 * duv2.y - dp2 * duv1.y);
vec3 binormal = normalize(dp2 * duv1.x - dp1 * duv2.x);
// Создаем матрицу тангенциального пространства
mat3 tbnMatrix = mat3(tangent, binormal, normal);
tbnMatrix = ModelRotateMatrix * tbnMatrix;
lightVec = lVec * tbnMatrix;
camVec = cVec * tbnMatrix;*/
2024-06-06 13:25:38 +00:00
}