如何使用OBJ文件中的法线进行漫反射照明?

时间:2016-11-24 13:52:42

标签: opengl lighting

我正在尝试实现漫反射照明。我的顶点和片段着色器看起来像这样:

#version 150

attribute vec3 position;
attribute vec3 color;
attribute vec3 normal;

out vec3 inColor;
out vec3 inNormal;
out vec3 inPosition;

uniform mat4 transform;

void main(void) {

        gl_Position = transform * vec4(position,  1.0);
        inColor = color;
        inNormal = normal;
        inPosition = position;
    }

------------------------------------
#version 150

out vec4 outColor;
in vec3 inColor;
in vec3 inNormal;
in vec3 inPosition;

uniform vec3 lightPosition;

void main(void) {    
    vec3 lightVector = normalize(lightPosition - inPosition);
    float brightness =  clamp(dot(lightVector, inNormal), 0, 1);
    outColor = vec4(brightness, brightness, brightness, 1.0f);
}

问题是:从OBJ文件加载后,我想对法线做什么?

0 个答案:

没有答案