Skip to content

Instantly share code, notes, and snippets.

@smokelore
Last active October 23, 2017 18:00
Show Gist options
  • Save smokelore/b6b0cd162256758972532c89bc4424b8 to your computer and use it in GitHub Desktop.
Save smokelore/b6b0cd162256758972532c89bc4424b8 to your computer and use it in GitHub Desktop.
Shader "CookbookShaders/Ch08/Blend Mode/ScreenImageEffect.shader"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_BlendTex ("Blend Texture", 2D) = "white" {}
_BlendOpacity ("Blend Opacity", Range(0, 1)) = 1
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
// declare corresponding CGPROGRAM variables
uniform sampler2D _MainTex;
uniform sampler2D _BlendTex;
fixed _BlendOpacity;
fixed4 frag(v2f_img i) : COLOR
{
// Get the colors from the RenderTexture and the UVs from the v2f_img struct
fixed4 renderTex = tex2D(_MainTex, i.uv);
fixed4 blendTex = tex2D(_BlendTex, i.uv);
// perform Screen blend mode
fixed4 blendedTex = (1.0 - (1.0 - renderTex) * (1.0 - blendTex));
// lerp between no blending and full blending
renderTex = lerp(renderTex, blendedTex, _BlendOpacity);
return renderTex;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment