2015-12-06 64 views
0

enter image description here與通光的變化通過幾何着色器

我使用FragmentShader和VertexShader目前,和作品精絕。我無法讓我的幾何着色器正常工作。我絕對是新手,下面是我嘗試過的。

我使用VBO,照明和紋理以及一些幾何圖形,但在使用GeometryShader之前它工作正常。我唯一改變的是變量名稱,因爲我必須在幾何着色器中獲得輸入並給出輸出。所以我在這些變量名的後面加了1,這些變量名將從幾何着色器到片段着色器。

此外我還添加了以#開頭的標頭,這些標頭以前不在那裏。我正在使用GL_TRIANGLES進行繪製。

VertexShader

uniform mat4 local2clip; 
uniform mat4 local2eye; 
uniform mat4 normal_matrix; 
uniform mat4 world2eye; 

uniform vec4 light_ambient; 
uniform vec4 light_diffuse; 
uniform vec4 light_specular; 
uniform vec4 light_pos; 


uniform vec4 mat_ambient; 
uniform vec4 mat_diffuse; 
uniform vec4 mat_specular; 
uniform float mat_shine; 

//varying vec3 v_normal; // vertex normal 
out vec2 FtexCoord; 

void main(){ 

     gl_Position = local2clip * position; 

     N =  normalize(vec3(normal_matrix * normal)); //v_normal 
     vec4 Lpos = world2eye * light_pos;     //light pos. in eye 
     vec4 Vpos = local2eye * position;     //pos_in_eye 
     L = normalize(vec3(Lpos - Vpos));     //light_vector 

     R = normalize(reflect(-L, N)); 
     V = normalize(vec3(-Vpos));       //eye vector 

     vec3 halfv = normalize(L+V); 
     FtexCoord = texCoord; 

     //pcolor = color1; 
} 

這是我FragmentShader

#version 330 compatibility 

uniform int use_texture; 

in vec4 pcolor; 

in vec3 N1; 
in vec3 L1; 
in vec3 R1; 
in vec3 V1; 


uniform mat4 local2clip; 
uniform mat4 local2eye; 
uniform mat4 normal_matrix; 
uniform mat4 world2eye; 

uniform vec4 light_ambient; 
uniform vec4 light_diffuse; 
uniform vec4 light_specular; 
uniform vec4 light_pos; 

uniform vec4 mat_ambient; 
uniform vec4 mat_diffuse; 
uniform vec4 mat_specular; 
uniform float mat_shine; 

uniform sampler2D Tex1; 
in vec2 FtexCoord1; 

void main() { 

     vec4 ambient = light_ambient * mat_ambient; 
     float NdotL; 
     if (dot(N1,L1) <0.0) NdotL = 0.0; 
     else NdotL = dot(N1, L1); 

     vec4 diffuse = light_diffuse * mat_diffuse * NdotL; 

     float RdotV; 
     RdotV = dot(R1, V1); 

     if (NdotL == 0.0) RdotV = 0.0; 
     if (RdotV <0.0) RdotV = 0.0; 

     vec4 specular = light_specular * mat_specular * pow(RdotV,mat_shine); 

     vec4 texcolor; 


     if(use_texture == 1) { 
      texcolor = texture2D(Tex1, FtexCoord1); 
      gl_FragColor = texcolor; 
     } 
     else 
      gl_FragColor = (diffuse + ambient + specular); 
} 

這是我的幾何着色器

#version 330 

layout (triangles) in; 
layout (triangle_strip, max_vertices = 3) out; 

out vec3 N1; 
out vec3 L1; 
out vec3 R1; 
out vec3 V1; 

in vec3 N[3]; 
in vec3 L[3]; 
in vec3 R[3]; 
in vec3 V[3]; 

uniform mat4 local2clip; 
uniform mat4 local2eye; 
uniform mat4 normal_matrix; 
uniform mat4 world2eye; 

uniform vec4 light_ambient; 
uniform vec4 light_diffuse; 
uniform vec4 light_specular; 
uniform vec4 light_pos; 

uniform vec4 mat_ambient; 
uniform vec4 mat_diffuse; 
uniform vec4 mat_specular; 
uniform float mat_shine; 

//varying vec3 v_normal; // vertex normal 
out vec2 FtexCoord1; 

in vec2 FtexCoord[3]; 

void main(void) 
{ 
    int i; 



    for (i = 0; i < gl_in.length(); i++) 
    { 
     N1=N[i]; 
     L1=L[i]; 
     R1=R[i]; 
     V1=R[i]; 

     FtexCoord1=FtexCoord[i]; 

     gl_Position = gl_in[i].gl_Position; 
     EmitVertex(); 
    } 
    EndPrimitive(); 
} 

我只想說什麼都在那裏早些時候從頂點着色器傳遞到片段着色器通過幾何着色器,以便我可以稍後操作着色器。但光線並未顯示出同樣的效果。如圖片所示。

+0

我不標示這是你以前的問題的副本的唯一原因是因爲你改變了[你以前的一個(HTTP ://stackoverflow.com/questions/34112683/passthrough-geometry-shader-not-working)是一個完全不同的問題。所以我會將它恢復原狀,並把它作爲一個單獨的問題留下。 –

+0

@NicolBolas:謝謝你讓我知道。由於鏡面反射而產生的光芒發生了變化。不知道爲什麼會發生這種情況。 –

回答

0

有在code.It一個小蟲子應該是V1=V[i];而不是V1=R[i];