Created
November 2, 2024 23:04
-
-
Save prnthp/7c53d972b221a79ce6d3169101916483 to your computer and use it in GitHub Desktop.
SelectivePassthroughHDRP.shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "HDRP/SelectivePassthroughHDRP" | |
{ | |
Properties | |
{ | |
_MainTex("Texture", 2D) = "white" {} | |
_Inflation("Inflation", float) = 0 | |
_InvertedAlpha("Inverted Alpha", float) = 1 | |
[Header(DepthTest)] | |
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 4 //"LessEqual" | |
[Enum(UnityEngine.Rendering.BlendOp)] _BlendOpColor("Blend Color", Float) = 2 //"ReverseSubtract" | |
[Enum(UnityEngine.Rendering.BlendOp)] _BlendOpAlpha("Blend Alpha", Float) = 3 //"Min" | |
} | |
HLSLINCLUDE | |
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" | |
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" | |
TEXTURE2D(_MainTex); | |
SAMPLER(sampler_MainTex); | |
float _Inflation; | |
float _InvertedAlpha; | |
struct Attributes | |
{ | |
float3 positionOS : POSITION; | |
float2 uv : TEXCOORD0; | |
float3 normalOS : NORMAL; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct Varyings | |
{ | |
float4 positionCS : SV_POSITION; | |
float2 uv : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
Varyings Vert(Attributes input) | |
{ | |
Varyings output; | |
UNITY_SETUP_INSTANCE_ID(input); | |
UNITY_TRANSFER_INSTANCE_ID(input, output); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); | |
float3 worldPos = TransformObjectToWorld(input.positionOS + input.normalOS * _Inflation); | |
output.positionCS = TransformWorldToHClip(worldPos); | |
output.uv = input.uv; | |
return output; | |
} | |
float4 Frag(Varyings input) : SV_Target | |
{ | |
UNITY_SETUP_INSTANCE_ID(input); | |
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); | |
float4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv); | |
float alpha = lerp(col.r, 1 - col.r, _InvertedAlpha); | |
return float4(0, 0, 0, alpha); | |
} | |
ENDHLSL | |
SubShader | |
{ | |
Tags | |
{ | |
"RenderPipeline" = "HDRenderPipeline" | |
"RenderType" = "Transparent" | |
"Queue" = "Transparent+100" // or "Queue" = "5100" | |
} | |
Pass | |
{ | |
Name "Forward" | |
ZWrite Off | |
ZTest [_ZTest] | |
BlendOp [_BlendOpColor], [_BlendOpAlpha] | |
Blend Zero One, One One | |
HLSLPROGRAM | |
#pragma multi_compile_instancing | |
#pragma vertex Vert | |
#pragma fragment Frag | |
#pragma target 4.5 | |
ENDHLSL | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment