我想知道如何使用顶点法线来实现闪电效果?目前我所拥有的是我可以将顶点和纹理坐标发送到着色器并使用它们但是使用法线,我不知道如何在着色器程序中使用它们.以下是我到目前为止的情况.
// 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) 我目前正在解析与.obj文件关联的.mtl文件。我可以正确地渲染模型,但是如何使用.mtl文件?我应该将其值发送到哪里?如何使用?当前,在OpenGL中找不到使用.mtl文件的任何内容。他们只是展示他们如何解析它。
编辑:这是在OpenGL中的方法。我还创建了自己的OBJ解析器。请注意,代码只是为您简化了我的工作方式而缩短了。
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, cc * sizeof(GLfloat), v, GL_STATIC_DRAW);
GLuint tcbuffer;
glGenBuffers(1, &tcbuffer);
glBindBuffer(GL_ARRAY_BUFFER, tcbuffer);
glBufferData(GL_ARRAY_BUFFER, tcc * sizeof(GLfloat), vt, GL_STATIC_DRAW);
GLuint ncbuffer;
glGenBuffers(1, &ncbuffer);
glBindBuffer(GL_ARRAY_BUFFER, ncbuffer);
glBufferData(GL_ARRAY_BUFFER, ncc * sizeof(GLfloat), vn, GL_STATIC_DRAW);
glEnableVertexAttribArray(m_vert);
glBindBuffer(GL_ARRAY_BUFFER, vbufferid);
glVertexAttribPointer(m_vert, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(m_texcoord);
glBindBuffer(GL_ARRAY_BUFFER, tcbufferid);
glVertexAttribPointer(m_texcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(m_color);
glBindBuffer(GL_ARRAY_BUFFER, cbufferid);
glVertexAttribPointer(m_color, 4, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(m_vertexnormal);
glBindBuffer(GL_ARRAY_BUFFER, ncbufferid);
glVertexAttribPointer(m_vertexnormal, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, …Run Code Online (Sandbox Code Playgroud)