Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 linnspitz · Feb 21 at 10:17 AM · shadersgraphicsuniversalhlsl

How to not have custom node variables be global across all material instances

Hi there! I wrote a shader in HLSL but I needed to switch to Shader Graph cause I wanted easy, flexible lighting. I'm working in URP with Unity version 2020.3.25f1. However I needed to put some of the shader's functionality in a custom node, mainly because I need to set a float array via C#. So I have a custom function (from file) that has a float array variable that I'm filling up via script. It's working except that this float array seems to be consistent amongst all material instances (even though I'm accessing the variable via the skinned mesh renderer). Is this intended behavior and/or is there a way to circumvent this issue? Thank you so much for the replies!

This is the code in the custom function file. _YPoints is the array I'm setting.

 float _YPoints[20];
 int _NrOfPlanes = 1;
 int _UseSlicing;
 
 #include "ProjectionDist.cginc"
 
 void GetMask_float(float4 pos, bool _IsPositive, out bool Out){
     Out = false;
     pos = mul(unity_ObjectToWorld, pos);
     bool mask = 0;
     int n = 0;
     for (int j = 0; j < _NrOfPlanes; j++){
         float t = getYDist(pos, _YPoints[j]);
         if (t >= 0) n++;
     }
     int positive = int(round(_IsPositive));
     Out = (positive == (n%2));
     if (!_UseSlicing) Out = true;
 }

EDIT: I also tried putting my code into a custom function in string mode and cleaned the whole thing up. But it seems like i cant set any variables from C# in a custom function string.

 float _YPoints[20];
 int _NrOfPlanes = 0;
 int _UseSlicing = 0;
 
     Out = false;
     pos = mul(unity_ObjectToWorld, pos);
     int n = 0;
     for (int j = 0; j < _NrOfPlanes; j++){
         float t = pos.y - _YPoints[j];
         if (t >= 0) n++;
     }
     Out = (_IsPositive == (n%2));
     if (!_UseSlicing) Out = true;
 

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

0 Replies

· Add your reply
  • Sort: 

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

167 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

Related Questions

Cross-project shader support 0 Answers

How to get surface shaders to work in URP? 2 Answers

Simple Unlit HLSL Shader with Rim Lighting? 1 Answer

Has Unity 2018 removed DX11 quad tessellation? 0 Answers

Wierd shading in UV seams 0 Answers


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