0

This is my texture shader program

 version 330 core
out vec4 FragColor;

 struct Light {
   vec3 direction;     
   vec3 ambient;
   vec3 diffuse;
   vec3 specular;
};

 struct Material {
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;
    float shininess;
}; uniform Material material;

uniform vec3 viewPos;
uniform Light light;
in vec3 FragPos;  
in vec3 Normal; 
in vec2 TexCoord; 
uniform sampler2D texture1;

void main()
 {  
   vec3 ambient = 0.2 * (light.ambient * material.ambient );

  // diffuse
  vec3 norm = normalize( Normal );
  vec3 lightDir = normalize( -light.direction );
  float diff = max( dot( norm, lightDir) , 0.0 );
  vec3 diffuse = light.diffuse * diff * material.diffuse;

 // specular
 vec3 viewDir = normalize( viewPos - FragPos );
 vec3 reflectDir = reflect( -lightDir , norm );
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = light.specular * spec * material.specular;
vec3 result = ambient + diffuse + specular;
FragColor =  texture( texture1 , TexCoord )  * vec4( result , 1.0 );

}

Everthing works as expected. my question is that if i don't send any image data the objects render black and i will have situations where a object will have no texture attached to it.

Is their any way in glsl to solve this problem or should i send a bool varible to the shader and apply if condition

4

1 回答 1

0

对于材料的每个方面,您必须以不同的方式修改纹理,例如,如果您有颜色吸收元素,则必须根据此值更改颜色,并且您对材料的每个方面都执行类似的操作,检查纹理是否存在,如果它没有,只是不渲染它

于 2019-06-12T08:50:00.540 回答