2
我試圖在opengl 3+上使用C++實現香椿着色器,但一個星期後,我只有一個顏色的香椿色調沒有紋理。與紋理的香椿着色器
頂點文件:
#version 330
// Incoming per vertex... position and normal
in vec4 vVertex;
in vec3 vNormal;
smooth out float textureCoordinate;
uniform vec3 vLightPosition;
uniform mat4 mvpMatrix;
uniform mat4 mvMatrix;
uniform mat3 normalMatrix;
void main(void)
{
// Get surface normal in eye coordinates
vec3 vEyeNormal = normalMatrix * vNormal;
// Get vertex position in eye coordinates
vec4 vPosition4 = mvMatrix * vVertex;
vec3 vPosition3 = vPosition4.xyz/vPosition4.w;
// Get vector to light source
vec3 vLightDir = normalize(vLightPosition - vPosition3);
// Dot product gives us diffuse intensity
textureCoordinate = max(0.0, dot(vEyeNormal, vLightDir));
// Don't forget to transform the geometry!
gl_Position = mvpMatrix * vVertex;
}
片段文件:
//
#version 330
uniform sampler1D colorTable;
out vec4 vFragColor;
smooth in float textureCoordinate;
void main(void)
{
vFragColor = texture(colorTable, textureCoordinate);
}
誰能給我一拿到手的這個shader與紋理的工作?
THX
thx爲答案,但什麼是modelTexture?我加入了vec4 vTexture0;平滑vec2 vTexCoords;在主vTexCoords = vTexture0.st; vec2 vTexCoords;和vFragColor = texture(colorTable,textureCoordinate)* texture(?????,vTexCoords);可以試圖給出一個工作的例子?謝謝 – Winter 2011-04-27 01:00:21