Quantcast
Channel: Questions in topic: "hlsl"
Viewing all articles
Browse latest Browse all 206

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

$
0
0
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;

Viewing all articles
Browse latest Browse all 206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>