Render Texture And Shaders
Hey! So for a project I am working on I have a render texture rendering a gameobject to a RawImage in the Scene. The raw image has a Shader attached as its material to make the background of the texture transparent. This works great, but causes the "viewing object" I appear black instead of it's actual color. If anyone has any idea's as to why this is happening, I would grealty appreciate the assistance! Below is the shader, and attached images are of the rawimage in game view, and raw image in inspector view. This project is using HDRP.
Shader "Custom/AlphaBlend"
{
Properties{
_Color("Color", Color) = (1,1,1,1)
_TransparentColor("Transparent Color", Color) = (1,1,1,1)
_Threshold("Threshhold", Float) = 0.1
_MainTex("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
fixed4 _Color;
fixed4 _TransparentColor;
half _Threshold;
void surf(Input IN, inout SurfaceOutput o)
{
// Read color from the texture
half4 c = tex2D(_MainTex, IN.uv_MainTex);
// Output colour will be the texture color * the vertex colour
half4 output_col = c * _Color;
// calculate the difference between the texture color and the transparent color
half3 transparent_diff = c.xyz - _TransparentColor.xyz;
half transparent_diff_squared = dot(transparent_diff,transparent_diff);
// if colour is too close to the transparent one, discard it.
if (transparent_diff_squared < _Threshold)
discard;
// output albedo and alpha just like a normal shader
o.Albedo = output_col.rgb;
o.Alpha = output_col.a;
}
ENDCG
}
FallBack "Diffuse"
}
Your answer
Follow this Question
Related Questions
RenderTexture Scope Effect 0 Answers
How to make dynamic ripple with shader? 0 Answers
PostProcess Outline Shader GVR alignment 0 Answers
Correct way to modify a Texture2d with a shader? 0 Answers
Transparent plane with RenderTexture - no show shadows? 3 Answers