标签:style blog http color io 使用 ar strong 2014
本系列主要参考《Unity Shaders and Effects Cookbook》一书(感谢原书作者),同时会加上一点个人理解或拓展。
这里是本书所有的插图。这里是本书所需的代码和资源(当然你也可以从官网下载)。
========================================== 分割线 ==========================================
在这篇里,我们将会学习另一种混合模式,叠加(Overlay)混合模式。这种混合模式使用了条件判断语句来决定最终的像素值。因此,这里用到的计算会稍微复杂一点(其实也很简单啦)。
我们再复习一下叠加所用的计算公式:
,其中a是基色,b是混合色。
fixed OverlayBlendMode(fixed basePixel, fixed blendPixel) {
if (basePixel < 0.5) {
return (2.0 * basePixel * blendPixel);
} else {
return (1.0 - 2.0 * (1.0 - basePixel) * (1.0 - blendPixel));
}
} fixed4 frag(v2f_img i) : COLOR {
//Get the colors from the RenderTexture and the uv‘s
//from the v2f_img struct
fixed4 renderTex = tex2D(_MainTex, i.uv);
fixed4 blendTex = tex2D(_BlendTex, i.uv);
fixed4 blendedImage = renderTex;
blendedImage.r = OverlayBlendMode(renderTex.r, blendTex.r);
blendedImage.g = OverlayBlendMode(renderTex.g, blendTex.g);
blendedImage.b = OverlayBlendMode(renderTex.b, blendTex.b);
// Adjust amount of Blend Mode with a lerp
renderTex = lerp(renderTex, blendedImage, _Opacity);
return renderTex;
}【Unity Shaders】使用Unity Render Textures实现画面特效——画面特效中的叠加(Overlay)混合模式
标签:style blog http color io 使用 ar strong 2014
原文地址:http://blog.csdn.net/candycat1992/article/details/39379027