Skip to content

Commit

Permalink
feat: prepare shader for hdrp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rofli Sanches committed May 26, 2021
1 parent 455377e commit b1d8ff7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Resources/Shaders/DearImGui-Mesh.shader
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,26 @@
ENDCG
}
}

// shader for HD render pipeline
SubShader
{
Tags { "RenderType" = "Transparent" "RenderPipeline" = "HDRenderPipeline" "PreviewType" = "Plane" }
LOD 100

Lighting Off
Cull Off ZWrite On ZTest Always
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
Name "DEARIMGUI HDRP"

HLSLPROGRAM
#pragma vertex ImGuiPassVertex
#pragma fragment ImGuiPassFrag
#include "./PassesHD.hlsl"
ENDHLSL
}
}
}
22 changes: 22 additions & 0 deletions Resources/Shaders/DearImGui-Procedural.shader
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@
ENDCG
}
}

// shader for HD render pipeline
SubShader
{
Tags { "RenderType" = "Transparent" "RenderPipeline" = "HDRenderPipeline" "PreviewType" = "Plane" }
LOD 100

Lighting Off
Cull Off ZWrite On ZTest Always
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
Name "DEARIMGUI HDRP"

HLSLPROGRAM
#pragma vertex ImGuiPassVertex
#pragma fragment ImGuiPassFrag
#include "./PassesHD.hlsl"
ENDHLSL
}
}
}
37 changes: 37 additions & 0 deletions Resources/Shaders/PassesHD.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef DEARIMGUI_HDRP_INCLUDED
#define DEARIMGUI_HDRP_INCLUDED

#include "UnityCG.cginc"
#include "./Common.hlsl"

sampler2D _Texture;

half4 unpack_color(uint c)
{
half4 color = half4(
(c) & 0xff,
(c >> 8) & 0xff,
(c >> 16) & 0xff,
(c >> 24) & 0xff
) / 255;
#ifndef UNITY_COLORSPACE_GAMMA
color.rgb = GammaToLinearSpace(color.rgb);
#endif
return color;
}

Varyings ImGuiPassVertex(ImVert input)
{
Varyings output = (Varyings)0;
output.vertex = UnityObjectToClipPos(float4(input.vertex, 0, 1));
output.uv = float2(input.uv.x, 1 - input.uv.y);
output.color = unpack_color(input.color);
return output;
}

half4 ImGuiPassFrag(Varyings input) : SV_Target
{
return input.color * tex2D(_Texture, input.uv);
}

#endif
10 changes: 10 additions & 0 deletions Resources/Shaders/PassesHD.hlsl.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1d8ff7

Please sign in to comment.