Skip to content

Commit

Permalink
Fix texture dimension mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
alelievr committed Apr 25, 2023
1 parent 023e231 commit e4aad25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ static void EndCameraRendering(ScriptableRenderContext ctx, Camera camera)
RenderTexture target = camera.targetTexture;
ui.DoRenderUI(ctx, cmd, target);

uiProperties.SetTexture("_MainTex", ui.renderTexture);
uiProperties.SetTexture("_MainTex2D", ui.renderTexture);
uiProperties.SetTexture("_MainTex2DArray", ui.renderTexture);
uiProperties.SetInt("_Is2DArray", ui.renderTexture.dimension == TextureDimension.Tex2DArray ? 1 : 0);

cmd.SetRenderTarget(target);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Shader "Hidden/HDRP/UI_Compositing"
{
Properties
{
_MainTex("Main Texture", 2DArray) = "white" {}
_MainTex2D("Main Texture", 2D) = "white" {}
_MainTex2DArray("Main Texture", 2DArray) = "white" {}
}

HLSLINCLUDE
Expand All @@ -11,7 +12,9 @@ Shader "Hidden/HDRP/UI_Compositing"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"

// We don't support XR so it's fine to do that + this makes it compatible with camera Render Textures
TEXTURE2D(_MainTex);
TEXTURE2D(_MainTex2D);
TEXTURE2D_ARRAY(_MainTex2DArray);
int _Is2DArray;

struct Attributes
{
Expand Down Expand Up @@ -40,7 +43,10 @@ Shader "Hidden/HDRP/UI_Compositing"
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);
float2 uv = varyings.uv;
return SAMPLE_TEXTURE2D_X_LOD(_MainTex, s_linear_clamp_sampler, uv, 0);
if (_Is2DArray == 0)
return SAMPLE_TEXTURE2D_LOD(_MainTex2D, s_linear_clamp_sampler, uv, 0);
else
return SAMPLE_TEXTURE2D_ARRAY_LOD(_MainTex2DArray, s_linear_clamp_sampler, uv, 0, 0); // VR not supported
}
ENDHLSL

Expand Down

0 comments on commit e4aad25

Please sign in to comment.