Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Rizzutp · Jan 21, 2020 at 12:21 AM · shaderrenderingmaterialpropertyblock

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Jan 21, 2020 at 12:56 AM

"_OuputMode" is not "_OutputMode"

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

197 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges