<p>I'm working on a universal shader, and have a function for calculating reflections and a function for textures. When I run the shader, it seems to give up and discard all fragments. The texture and reflection work fine when run independently, however, when I try to calculate both the texture and the reflection at the same time, it gives up. Even if I leave the result of the reflection alone and don't do anything with it, the fragment gets discarded.</p>

<pre><code>in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;

uniform vec3 ViewPos;

uniform sampler2D texture_diffuse1;
uniform samplerCube skybox;

vec3 CalcReflection(vec3 normal, vec3 frag, vec3 view, float shine);

void main() {
    // properties
    vec3 norm = normalize(Normal);

    //Both of these statements work as long as the other isn't called
    vec4 texColor = vec4(texture(texture_diffuse1, TexCoords).rgb, 1.0); 

    vec4 reflection = vec4(CalcReflection(norm, FragPos, ViewPos, mat.shininess), 1.0);


    FragColor = texColor; //I'm not doing anything with reflection, yet it still discards the fragment
}

vec3 CalcReflection(vec3 normal, vec3 frag, vec3 view) {
    vec3 I = normalize(frag - view);
    vec3 R = reflect(I, normal);
    return vec3(texture(skybox, R).rgb);
}
</code></pre>

<p>I'm not too worried about blending the texture and reflection yet, but to start on that I need to know why this doesn't work.</p>

<p>The answer is probably obvious, but I've been stuck on this for a while and need a fresh perspective</p>

<p>Edit: Added more things from my actual code (skybox definition, alpha values)</p>

CC BY-SA 4.0
2018-05-05T09:20:56.070Z
How is 'skybox' defined ? Have you tried to output with alpha=1 also, e.g.   FragColor=vec4(texColor,1); - You will need to set the output type to vec4 for FragColor.
PaulHK
CC BY-SA 4.0
2018-05-06T22:34:07.783Z
Do you have [OpenGL debug output](https://www.khronos.org/opengl/wiki/Debug_Output) turned on? If not, that would be my first step, and see if it gives you any errors for this shader. My guess is there's some problem binding uniforms/textures when both diffuse and reflection are turned on.
Nathan Reed
CC BY-SA 4.0
2018-05-08T03:54:32.397Z
I didn't know about that, i'll try it and get more info, thanks
u1F98E
<opengl><glsl>
GLSL can't calculate texture and reflection
u1F98E
# GLSL can't calculate texture and reflection

(Asked by: username_0 on 2018-05-05)

I'm working on a universal shader, and have a function for calculating reflections and a function for textures. When I run the shader, it seems to give up and discard all fragments. The texture and reflection work fine when run independently, however, when I try to calculate both the texture and the reflection at the same time, it gives up. Even if I leave the result of the reflection alone and don't do anything with it, the fragment gets discarded.

```
in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;

uniform vec3 ViewPos;

uniform sampler2D texture_diffuse1;
uniform samplerCube skybox;

vec3 CalcReflection(vec3 normal, vec3 frag, vec3 view, float shine);

void main() {
    // properties
    vec3 norm = normalize(Normal);

    //Both of these statements work as long as the other isn't called
    vec4 texColor = vec4(texture(texture_diffuse1, TexCoords).rgb, 1.0); 

    vec4 reflection = vec4(CalcReflection(norm, FragPos, ViewPos, mat.shininess), 1.0);

    FragColor = texColor; //I'm not doing anything with reflection, yet it still discards the fragment
}

vec3 CalcReflection(vec3 normal, vec3 frag, vec3 view) {
    vec3 I = normalize(frag - view);
    vec3 R = reflect(I, normal);
    return vec3(texture(skybox, R).rgb);
}

```

I'm not too worried about blending the texture and reflection yet, but to start on that I need to know why this doesn't work.

The answer is probably obvious, but I've been stuck on this for a while and need a fresh perspective

Edit: Added more things from my actual code (skybox definition, alpha values)

**Tags:** opengl, glsl

> **Comments:**
> **username_1**: How is 'skybox' defined ? Have you tried to output with alpha=1 also, e.g.   FragColor=vec4(texColor,1); - You will need to set the output type to vec4 for FragColor.  
> **username_2**: Do you have [OpenGL debug output](https://www.khronos.org/opengl/wiki/Debug_Output) turned on? If not, that would be my first step, and see if it gives you any errors for this shader. My guess is there's some problem binding uniforms/textures when both diffuse and reflection are turned on.  
> **username_0**: I didn't know about that, i'll try it and get more info, thanks  

---

## 0 answers

