我想知道如何使用顶点法线来实现闪电效果?目前我所拥有的是我可以将顶点和纹理坐标发送到着色器并使用它们但是使用法线,我不知道如何在着色器程序中使用它们.以下是我到目前为止的情况.
// vertex shader
layout(location = 0) in vec4 vert;
layout(location = 1) in vec4 color;
layout(location = 2) in vec2 texcoord;
uniform mat4 m_model;
uniform mat4 m_view;
uniform mat4 m_proj;
void main() {
gl_Position = m_proj * m_view * m_model * vert;
}
// fragment shader
in vec2 fragtexcoord;
out vec4 color;
uniform sampler2D textureunit;
void main(void) {
color = texture(textureunit, fragtexcoord);
}
Run Code Online (Sandbox Code Playgroud)
编辑 以下是我的着色器.
顶点着色器
layout(location = 0) in vec4 vert;
layout(location = 1) in vec4 color;
layout(location …Run Code Online (Sandbox Code Playgroud) 我正在尝试阅读本教程:
https://aerotwist.com/tutorials/an-introduction-to-shaders-part-2/
但我无法跟进。基本上,代码使用直接在GPU上运行的着色器创建定向光。这是代码:
// same name and type as VS
varying vec3 vNormal;
void main() {
// calc the dot product and clamp
// 0 -> 1 rather than -1 -> 1
vec3 light = vec3(0.5,0.2,1.0);
// ensure it's normalized
light = normalize(light);
// calculate the dot product of
// the light to the vertex normal
float dProd = max(0.0, dot(vNormal, light));
// feed into our frag colour
gl_FragColor = vec4(dProd, dProd, dProd, 1.0);
}
Run Code Online (Sandbox Code Playgroud)
具体来说,我不明白的这一行是:
float dProd = max(0.0, …Run Code Online (Sandbox Code Playgroud)