简体   繁体   中英

OpenGL's glBlendFunc

Is there a way in OpenGL's glBlendFunc to scale up the destination RGB? (ie (10,50,5) to (20,100,10)

it seems the only thing you can do is add source rgb (multiplied by some factors that are <1)

If you want to use this blend function for all draw operations / all objects (and have an initial non-zero value of course) what you could do is to interpret the colors exponentially. Imagine what is written in the color buffer is the exponent to some base, eg 2, so adding to the exponent will essentially multiply by 2 to the power of what you added.

Then you need to introduce a post processing step if you're not already doing this. There you read the color value and take 2 to the power of the color, which will give you the final color.

Initial values have to be logarithmic, of course.

If you however want to only multiply the colors for some draw operations (I hope only the last ones in your scene) you have to split the procedure further: First draw the "normal" content where you use normal color blending. Then convert the colors into a logarithmic scale (you can use a separate texture for this), use this for the next draw operations which should multiply the colors (but you tell OpenGL to add colors), then convert back to linear scale by taking the power.

Of course you can also use e as the base, in which case you use the natural logarithm and the exp function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM