Hi everyone,
I’m working with a 3D Object Scene Layer in Unity (HDRP), and I’m trying to change the color of buildings based on a specific property of the layer. However, all buildings keep the same color, and I can’t figure out what’s causing the issue.
Possible causes I’ve considered:
Has anyone encountered a similar issue or has suggestions on how to debug this?
Thanks in advance for the help.
The first code block shows how I assign the material to the layer, while the second one is the shader code and at the moment the building color is always _FilteredColor.
var layerAttributes = ArcGISImmutableArray<String>.CreateBuilder();
layerAttributes.Add("CODICE");
layer.SetAttributesToVisualize(layerAttributes.MoveToArray());
layer.MaterialReference = customMaterial;
Shader "HDRP/FilteredBuildings"
{
Properties
{
_BaseColor ("Base Color", Color) = (0,0,1,1)
_FilteredColor ("Filtered Color", Color) = (1,0,0,1)
[HideInInspector]_CODICE ("CODICE", Float) = 0
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
ENDHLSL
SubShader
{
Tags { "RenderPipeline"="HDRenderPipeline" }
Pass
{
Name "Forward"
Tags { "LightMode"="ForwardOnly" }
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
float CODICE : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float CODICE : TEXCOORD0;
};
float4 _BaseColor;
float4 _FilteredColor;
Varyings vert (Attributes IN)
{
Varyings OUT;
OUT.positionCS = TransformObjectToHClip(IN.positionOS);
OUT.CODICE = IN.CODICE;
return OUT;
}
float4 frag (Varyings IN) : SV_Target
{
return (IN.CODICE == 0) ? _FilteredColor : _BaseColor ;
}
ENDHLSL
}
}
}