2

Hey I currently have a system in OpenGL that uses glBlendFunc for bleding diffrent shaders but I would like to do something like this

fragColor = currentColor * lightAmount;

I tried to use gl_Color but its depricated and my engine will not let me use it.

Swiftprog
  • 61
  • 6
  • no i need to assign to fragColor since i am using GLSL 330 if i just assign fragColor to lightingamount everything in my scene gets whiteish – Swiftprog Jul 24 '16 at 17:42
  • You can't. There are extensions for OpenGL ES that allow this on some platforms. See previous similar question: http://stackoverflow.com/questions/16531185/reading-current-framebuffer. Or this, even though it deals with depth values, is basically the same: http://stackoverflow.com/questions/23362076/opengl-how-to-access-depth-buffer-values-or-gl-fragcoord-z-vs-rendering-d. – Reto Koradi Jul 24 '16 at 18:05
  • What are `currentColor` and `lightAmount` exactly? – peppe Jul 24 '16 at 21:14
  • Currenycolor is nothing but a wish I would like to swap that out with what I rendered in an earlier shader program pass, and lightAmount is what I get after calculating light – Swiftprog Jul 24 '16 at 21:28

1 Answers1

4

According to this document there is no built-in access for the fragment color in the fragment shader. What you could do is render your previous passes in another textures, send those textures to the GPU (as uniforms) and do the blending in your last pass.

cmourglia
  • 2,423
  • 1
  • 17
  • 33
  • Same solution as I had :) – Swiftprog Jul 25 '16 at 12:25
  • How would i go about loading the sampler2D? i have rendered my light pass and "diffuse" pass into seperate textures then i have sent those to a combinepasses shader but i am not sure what the texcoords should be for the samplers – Swiftprog Jul 25 '16 at 15:10
  • 1
    You can have texcoords associated with the quad you are rendering, use their vertex coordinates, or use gl_FragCoord and the viewport size – cmourglia Jul 25 '16 at 17:32
  • do you have a good solution to how i should blend my light pass and base pass? currently i do BasePass / (1.0-LightPass) but it gets too bright and not correct – Swiftprog Jul 25 '16 at 20:43
  • This is another issue that is not linked to this one, you should ask another question. – cmourglia Jul 25 '16 at 21:40