- Home /
Why SetFloat method seems not to affect the value within a Material Property Block?
Hello there. I'm trying to figure why the SetFloat method doesn't seem to change a float contained within my custom shader. Here's the code
foreach (var r in renderers)
{
var id = r.gameObject.GetInstanceID();
var tag = r.gameObject.tag;
DrawingSettings drawingSettings = new DrawingSettings();
drawingSettings.overrideMaterial = mat;
mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
mpb.SetColor("_CategoryColor", ColorEncoding.EncodeTagAsColor(tag));
mpb.SetFloat("_OutputMode", 1.0f);
r.SetPropertyBlock(mpb);
Debug.Log("Output mode set to: " + mpb.GetFloat("_OuputMode"));
drawingSettings.SetShaderPassName(0, new ShaderTagId("DepthOnly"));
drawingSettings.SetShaderPassName(1, new ShaderTagId("SRPDefaultUnlit"));
drawingSettings.SetShaderPassName(2, new ShaderTagId("Vertex"));
FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.all);
context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
}
Debug.Log always reports "0" value, despite I set "_OutputMode" to 1. Any ideas?
Answer by Rizzutp · Jan 21, 2020 at 09:29 AM
Ok, thanks man! I'm deeply sorry for the typo! Now the SetFloat property works, however, the output of my shader is not affected. Here's the code in HLSL:
In few words, I would like that my objects should be rendered with two differet type of colors, depending on the value assumed by _OutputMode. However, the code seems not to respond, always choosing as a result _ObjectColor.
float4 UnlitPassFragment (VertexOutput input) : SV_TARGET {
float4 result = _ObjectColor;
if(_OutputMode == 0.0)
{
float4 result = _ObjectColor;
}
else if (_OutputMode == 1.0)
{
float4 result = _CategoryColor;
}
return result;
}
Properties are declared as it follows:
Properties {
_ObjectColor ("Object Color", Color) = (1,1,1,1)
_CategoryColor ("Category Color", Color) = (0,1,0,1)
_OutputMode("Output Mode", float) = 0.0
}
Your answer
Follow this Question
Related Questions
Specular artifacts on iOS using standard PBR shader on Lightweight render pipeline 0 Answers
Standard Shader Still Visible through Stencil Shader 0 Answers
COLORMASK & writing to multiple render targets In Deferred doesn't work as expected in DX9 1 Answer
Image Effect - Screen coordinates 1 Answer
What is "sampler_ScreenTextures_linear_clamp" and what other options do I have in shaders? 1 Answer