简体   繁体   中英

OpenGL ES Overlay Blend Mode with Point Sprites

I'm trying to emulate Photoshop's Overlay blend mode on a point sprite. Is this possible in OpenGL ES?

EDIT - This might help you along:

Please note: I do not take credit for the code below; I found it on the powervr forums: http://www.imgtec.com/forum/forum_posts.asp?TID=949

uniform sampler2D s_renderTexture;
uniform sampler2D s_overlayMap;
varying mediump vec2 myTexCoord;

void main()

{
     //Get the Texture colour values
     lowp vec3 baseColor = texture2D(s_renderTexture, myTexCoord).rgb;
     lowp float overlayTexture = texture2D(s_overlayMap, myTexCoord).r;
     lowp vec3 finalMix = baseColor + (overlayTexture - 0.5) * (1.0 - abs(2.0 * baseColor - 1.0));

     //Set the Fragments colour

     gl_FragColor = vec4( finalMix, 1.0 );

} 

Sure, call this before rendering the point sprites:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);

This should result in additive blending.

Here's a visual reference on the different blending mode combinations: http://zanir.wz.cz/?p=60&lang=en

It's an old page, but it's a nice reference.

For more on opengl-es blending: http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml

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