bumpmapping OpenTK GLcontrol

时间:2014-01-12 15:15:39

标签: c# shader opentk

我必须在GLSL中制作着色器,我正在使用OpenTK,而我正在用C#Windows Forms编写。 我在GLControl中使用此着色器时遇到一些问题 这是我的顶点着色器

attribute vec3 tangent;
attribute vec3 binormal;
varying vec3 position;
varying vec3 lightvec;
void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
position = gl_Vertex.xyz;
mat3 TBNMatrix = mat3(tangent, binormal, gl_Normal);
lightvec = gl_LightSource[0].position.xyz - position;
lightvec *= TBNMatrix;
}

这是我的片段着色器

uniform sampler2D base;
uniform sampler2D normalMap;
uniform vec3 CAMERA_POSITION;
varying vec3 position;
varying vec3 lightvec;
void main()
{
vec3 norm = texture2D(normalMap, gl_TexCoord[0].st).rgb * 2.0 - 1.0;
vec3 baseColor = texture2D(base, gl_TexCoord[0].st).rgb;
float dist = length(lightvec);
vec3 lightVector = normalize(lightvec);
float nxDir = max(0.0, dot(norm, lightVector));
vec4 diffuse = gl_LightSource[0].diffuse * nxDir;
float specularPower = 0.0;
if(nxDir != 0.0)
{
vec3 cameraVector = normalize(CAMERA_POSITION - position.xyz);
vec3 halfVector = normalize(lightVector + cameraVector);
float nxHalf = max(0.0,dot(norm, halfVector));
specularPower = pow(nxHalf, gl_FrontMaterial.shininess);
}
vec4 specular = gl_LightSource[0].specular * specularPower;
gl_FragColor = gl_LightSource[0].ambient +
(diffuse * vec4(baseColor.rgb,1.0)) +
specular;
}

我应该使用GL.Uniform()吗?我不知道如何使用这个着色器...

0 个答案:

没有答案