'OpenGL: moving vertex shader calculations to the fragment shader results in a black screen
I am trying to move my vertex shader to the fragment shader to create a Phong shader but what ever I try results in a blank screen. It seems like I may be doing something wrong in the fragment shader but to me it looks fine.
Vertex shader:
attribute vec4 vPosition;
attribute vec4 vNormal;
attribute vec2 vTexCoord;
varying vec2 texCoord;
varying vec3 fN;
varying vec3 fV;
varying vec3 fL;
uniform mat4 ModelView;
uniform mat4 Projection;
uniform vec4 LightPosition;
uniform float Shininess;
void main()
{
vec4 vpos = vPosition;
fN = (ModelView * vNormal).xyz;
fV = -(ModelView * vPosition).xyz;
fL = LightPosition.xyz - (ModelView * vPosition).xyz;
gl_Position = Projection * ModelView * vpos;
texCoord = vTexCoord;
}
Fragment shader:
varying vec3 fN;
varying vec3 fV;
varying vec3 fL;
varying vec2 texCoord;
uniform float texScale;
uniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct;
uniform float Shininess;
uniform sampler2D texture;
void main()
{
vec3 N = normalize(fN);
vec3 V = normalize(fV);
vec3 L = normalize(fL);
vec3 H = normalize(L+V);
vec4 ambient = AmbientProduct;
float Kd = max(dot(L,N),0.0);
vec4 diffuse = Kd * DiffuseProduct;
float Ks = pow(max(dot(N,H),0.0),Shininess);
vec4 specular = Ks * SpecularProduct;
if(dot(L,N) < 0.0) {
specular=vec4(0.0,0.0,0.0,1.0);
}
gl_FragColor = (ambient + diffuse + specular);
gl_FragColor.a = 1.0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
