Photoshop混合模式到不带着色器的OpenGL ES [英] Photoshop blending mode to OpenGL ES without shaders

查看:94
本文介绍了Photoshop混合模式到不带着色器的OpenGL ES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在OpenGL ES 1.1代码(着色器)中模仿Photoshop混合模式(乘",屏幕"等).

I need to imitate Photoshop blending modes ("multiply", "screen" etc.) in my OpenGL ES 1.1 code (without shaders).

有一些有关如何使用 HLSL进行此操作的文档:

There are some docs on how to do this with HLSL:

  • http://www.nathanm.com/photoshop-blending-math/ (archive)
  • http://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/

我至少需要工作在屏幕模式下.

I need at least working Screen mode.

我可以看一下固定管道上的任何实现吗?

Are there any implementations on fixed pipeline I may look at?

推荐答案

大多数photoshop混合模式都基于Porter-Duff混合模式.

Most photoshop blend-modes are based upon the Porter-Duff blendmodes.

这些要求您所有的图像(纹理,渲染缓冲区)都在预乘的色彩空间中.通常通过将所有像素值乘以alpha值,然后再将它们存储在纹理中来完成此操作.例如.在非预乘颜色空间中,一个全透明像素将看起来像黑色.如果您不熟悉此颜色空间,请花一两个小时在网络上阅读一下.这是一个很好的概念,是类似Photoshop的构图所必需的.

These requires that all your images (textures, renderbuffer) are in premultiplied color-space. This is usually done by multiplying all pixel-values with the alpha-value before storing them in a texture. E.g. a full transparent pixel will look like black in non-premultiplied color space. If you're unfamiliar with this color-space spend an hour or two reading about it on the web. It's a neat and good concept and required for photoshop-like compositions.

无论如何-拥有该格式的图像后,您可以使用以下命令启用SCREEN:

Anyway - once you have your images in that format you can enable SCREEN using:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR)

使用OpenGL | ES管道无法使用完整的MULTIPLY模式.如果您仅使用全不透明像素,则可以使用以下方法进行伪造:

The full MULTIPLY mode is not possible with the OpenGL|ES pipeline. If you only work with full opaque pixels you can fake it using:

glBlendFunc(GL_ZERO, GL_SRC_COLOR)

纹理和帧缓冲区中透明像素的结果将是错误的.

The results for transparent pixels either in your texture and your framebuffer will be wrong though.

这篇关于Photoshop混合模式到不带着色器的OpenGL ES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆