2

I'm currently trying to blend a bunch of sprites together in Three.js. What I've found is that giving my sprite shader negative gl_FragColor.rgba values interacts perfectly with my postprocessing shader, whereas positive values are bland without adjustment. I'd rather not adjust my postproccessing shader as it already does exactly what it needs to with other objects.

Here's the difference:

Positive gl_FragColor.rgba values:

enter image description here

Negative gl_FragColor.rgba values:

enter image description here

I'd rather not anger the OpenGL Specification Gods as I've heard you can get inconsistent behaviour across vendors and drivers depending on what you do.

Is there something in the spec that either disallows negative values, or states such behavior is undefined? Or are such shenanigans generally safe?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
aggregate1166877
  • 2,196
  • 23
  • 38
  • What is the type of the texture which you write negative values to? If it supports negative values, then you should be fine, that by itself shouldn't trigger undefined behaviour. – Permille Aug 13 '23 at 02:14
  • @Permille The final texture has all-positive values. What receives the negative values is the post-processing shader, which then outputs positive values from the negative input. – aggregate1166877 Aug 16 '23 at 06:41
  • From research I've done in the meantime, it seams that no standard C/C++ systems are capable of unsigned float values, because hardware very rarely supports such things. Apparently, part of the rationale is that unsigned float logic is weird to implement hardware side, and no one likes emulating such things in software. At least, that's on the CPU. I'd *hope* shader languages and GPUs follow similar logic. I'm guessing this should be ok as GPUs will *probably* only have signed float color values. But that's just a guess, I have not found anything conclusively stating this is good or bad. – aggregate1166877 Aug 16 '23 at 06:46

0 Answers0