Reputation: 33
I've been trying to study opengl for a fun side project and ran into some issue while learning.
Below is a fragment shader:
#version 330 core
in vec3 Normal;
in vec3 Position;
in vec2 TexCoords;
out vec4 color;
uniform vec3 cameraPos;
uniform samplerCube skybox;
struct Material{
sampler2D diffuse0;
sampler2D specular0;
sampler2D emitter0;
sampler2D reflection0;
float shininess;
};
uniform Material material;
void main(){
vec3 I = normalize(Position - cameraPos);
vec3 R = reflect(I, normalize(Normal));
float intensity = 0;
intensity += texture(material.reflection0, TexCoords).x;
vec4 rfl = texture(skybox, R);
//this line doesnt produce anything
color = rfl * intensity;
}
When i used the code above, my model is completely gone from view.
But, if i debug it out separately such as changing the line
color = rfl * intensity;
to
color = rfl;
This actually renders and returns the following picture
And changing that line to
color = vec4(intensity);
It renders and returns the following picture
I've tried changing
color = rfl * some constant
//or
color = vec4(0.5) * intensity
And both rendered my model normally. I'm stumped as to why it doesnt render when i tried multiplying both rfl and intensity together. I think it might be because there are values that the multiplication to fail, but i have no idea what they might be.
Upvotes: 1
Views: 464
Reputation: 46
Then you change
color = rfl * intensity;
to
color = rfl;
GLSL compiler will drop
uniform Material material;
due optimization. Same happens with skybox when you change line to:
color = intensity;
Make sure that you binding of texture uniforms is correct.
Upvotes: 1