Search Unity

Entity highlighting in jobs : material UV / Atlas / Shader

Discussion in 'Entity Component System' started by Antypodish, Sep 15, 2019.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    This topic flies about in my mind for quite while now. But now decided to actually post a question.
    I see few topics scattered around, reading changing UV, material, or mesh.
    I may have missed something obvious, but so far, my research shows rather old results.

    Currently for highlighting entities, I am using
    Code (CSharp):
    1. ecb.SetSharedComponent <RenderMesh>
    It works well in general, when highlighting and then returning color back to original.
    Changing 1000 entities in a frame is not much of a big deal. Yet I don't feel this is right approach to do highlighting. Also, this method is not as much flexible, as only limited by the predefined render meshes.

    Now I would like scale this a bit up, by being able highlighting smoothly well over 1000 entities in a frame, without starting seeing significant spikes across threads. Is not something I want to do every frame. But just like selecting blocks / units.

    That leads me to a question, that must be now more optimal way, to design highlight system. Either by UV changing for atlas texture, or shader color properties changing form a job.

    Some older (2018) topics discusses vertices UV manipulations (by @tertle)
    https://forum.unity.com/threads/using-ecs-to-update-a-mesh.543862/#post-3590108

    Another 2018 topics shows cool example, but I never had chance to get into much details
    And I think there were few more relevant, but unable find atm.

    Any thoughts and suggestions?
     
  2. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    I know it is not really helpful, but I came across this the other day. I am quite interested in seeing how he went about it. Seems like it would be similar to what you are after as well.

     
    florianhanke and Antypodish like this.
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    This is cool finding.
    In fact, I posted a question on the video comments.

    Edit:
    Another video of channel author Bosheng Li, indicates using
    MaterialPropertyBlock
    https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html

    Spiral Galaxy 70,000 stars generation, features review. [Unity ECS] ~110FPS

     
    Last edited: Sep 15, 2019
    MostHated likes this.
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Have you looked into DrawMeshInstancedIndirect.
    To draw a massive amount of meshes and have control over color/uv or anything else you can think of on a per instance basis you must go this path.
    It uses computer shaders so it means you will have write your own shader for that.
     
    Antypodish likes this.
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Thx for an input. This gives a good direction, to the approach.
     
  6. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    There are 2 ways I know of, both require a custom shader. The only problem is that you have to bypass the render system v2 and loose it’s functionality (culling, lod, etc)

    Drawmeshinstanced - this uses material property block and therefore requires you to batch in 1023 “chunks” - it was compatible with render mesh v1 (so made sense at its time)

    Drawmeshinstancedindirect, this has no batching requirements, but you have to bypass the render mesh v2
     
  7. FM-Productions

    FM-Productions

    Joined:
    May 1, 2017
    Posts:
    72
    Hello!
    I saw that my post was quoted, as far as I can remember I could achieve the color swapping by using material property blocks too, and I think my solution used DrawMeshInstanced (which was on the main thread).
    I haven't really followed up with new updates on the project, since I hit a roadblock trying to port an OOP library I wanted to use in the project library to be compatible with ecs, but couldn't do it with my thinking back then.

    I don't know how much has changed in the DOTS eco system since I used it the last time, but from my prior experiences, you seem to be on the right track.
    Good luck!
     
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    If I understood correctly, does that means loosing current DOTS, LOD and culling LOD and culling of DOTS?
    If that is the case, this may rise a bit of concerns for my project need.
    Not sure yet however.
     
    Last edited: Sep 15, 2019
  9. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    Yes, that's what I mean (with exception of loosing current DOTS - not sure what you meant by that)

    It depends on your project if the trade off is worth it
     
  10. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    My comma was most likely misplaced, introducing confusion of meaning.

    I should rephrase
    Loosing LOD and culling of DOTS. But not rather than for example LOD and culling of PyhsX, or otherwise Unity classical approach.

    I just wanted 100% to ensure, that I follow correctly.
     
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    In meantime I just read regarding custom shader culling in,

    Spiral Galaxy, CPU & GPU Frustum Culling. [Unity ECS]



     
    tarahugger likes this.
  12. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
  13. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    I typically find that CPU culling is usually cheaper than sending the unculled data to the GPU.
     
  14. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Perhaps 50,000 cars might toot you guys horn? lol. It gets a bit nuts (not that it isn't already at 50) at 100k. 50k I guess isn't *that* much compared to some of the other numbers you guys are throwing out there.

    https://i.imgur.com/a91Ky6O.gifv
     
    Last edited: Sep 15, 2019
  15. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    We using DMII for army units, cause of custom animation and other related stuff. And until unity release some customization for instances in RMv2 I suggest you write your render system on DMII, only for drawing. And when thing become, you’ll replace it’s easily.
     
    Antypodish and GilCat like this.
  16. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    I remember reading this thread back while. Then I thought I was following it, but apparently not ;)
    It has really good extensive content with code examples.
    Thx for referencing it.

    From the sngdan link, there are examples, of using shader as culling. Which may be something to consider?

    Maybe I have missed response from that link, while reading through, but anyone knows, if Unity DOTS uses shader based, or some form of component based culling?

    I was just wanting ask what is DMII, as search internet pointed me at diabetes (yeah not much Unity related :) ).
    Then I clicked and realized, you talking about
    Graphics.DrawMeshInstancedIndirect

    Funny to watch :)
    However, they got rather static texture. Can each car be of different colors?
     
  17. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
  18. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    If my memory doesn't faills me, I recall some discussion, or maybe Unite talk, which mentioned this approach, used in
    Massive Battle in the Spellsouls Universe, to animate minions.
     
  19. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Joachim extracted it from Nordeus demo and a bit cleaned it.
     
    Last edited: Sep 17, 2019
  20. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    I think in this talk briefly mentioning it
    Unite Austin 2017 Keynote - Performance Demo ft. Nordeus [6/7]
    (40k->100k minions)
     
  21. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Right, I am still new to whole rendering and shaders thingy with DOTS. I took moment break from it.

    My vision concept was a bit different than actual application, which lead me to numerous confusions.
    I thought I use rendering in jobs. But actually is outside by passing relevant arrays / matrices.
    But I think now I am start grasping the concept.

    So I managed eventually render some stuff with
    Graphics.DrawMeshInstanced
    Code (CSharp):
    1. Graphics.DrawMeshInstanced ( renderData.mesh, 0, renderData.material, _matrices, len, _propertyBlock ) ;
    For this case I use propertyBlock to manipulate shader data.
    Code (CSharp):
    1. _propertyBlock.SetFloatArray ( Shader.PropertyToID ( "_QuaterGauge_Energy" ), l_floats ) ;
    I used this as reference point
    However following is to be considered for me as some next step.
    While I have rendered instances and manipulated shaders properties, my following question is, how I properly disable default Unity rendering?
    As I have now duplicates of rendered instances.
    Mi thought is and I would understand now approach, taken in above code example, to not add default DOTS RenderMesh component, but use custom. Above code example suggests RenderData as ISharedComponentData, which holds mesh and material.
    Seems sensible route?



    Next thing, I have issue, with copy native to manage data.
    I have asked similar question, in dedicated thread.
    https://forum.unity.com/threads/how-correctly-use-memcpy-to-copy-nativearray-matrix4x4-to-matrix4x4.760352/
    So I think is better to respond there, to keep it separate.

    Following question in spoiler, is resolved in link above.


    In particular
    NativeArray <Matrix4x4> to Matrix4x4 [] ;

    In quoted example, it uses
    Code (CSharp):
    1. Utils.CopyNativeToManaged ( ref _matrices, matricesBuffer, i, len) ;
    But I presume Utils is custom library? I am failing finding correct namespace.

    Where
    _matrices is Matrix4x4 []
    matricesBuffer is NativeArray <Matrix4x4>

    So I looked into MemCpy
    Code (CSharp):
    1. UnsafeUtility.MemCpy ( _matrices, matricesBuffer, len );
    That fails, as it requires pointers I believe? Pointers isn't my strongest area of knowledge. VS warring says something in this lines,
    "Can not convert from Matrix4x4 [] (or NativeArray <Matrix4x4>) to void"

    Currently I am searching for solution to MemCpy, but in meantime, if someone kindly drop me a direction, I would appreciate much.
     
    Last edited: Oct 14, 2019
  22. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Custom components are the best solution at the moment. But I believe I read that built-in instancing property support is coming in the next DOTS release which might be as soon as this week.
     
  23. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Thx @DreamingImLatios. It is definitely exciting to watch space, for upcoming features.
    Do you maybe remember references by any chance for this information? Link would be appreciated.

    I just hope, I won't need make any major changes to custom shaders. But expect some changes in components.
    Lets wait and see what Unity team will come up with. :rolleyes:
     
  24. sschoener

    sschoener

    Joined:
    Aug 18, 2014
    Posts:
    73
    I think he's referring to this post.
     
    Antypodish likes this.
  25. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    That is good reference, even if doesn't state specifically date.
    But good to know, is right the corner.

    I may just work on different part of game until then, and come back to it, when release happens.
     
  26. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    I am still playing around shader and DrawMeshInstanced.
    I thought I had figure out, but there is one issue, I try to tackle.

    For simplicity I focus on two instances.
    upload_2019-10-16_13-52-33.png
    Left OK = 0.3, right NOT OK should be 0.9 but is also 0.3.

    I got shader, with rings and 4 colors on outer ring (red, blue, pink, green ),
    I can set perfectly fine, each individual color of the shader, using
    propertyBlock.SetFloatArray
    However, problem I have now, is that each entitiy sharing same material, has same shader settings.
    Even tho, I know I pass different shader properties.

    In my case I use
    Code (CSharp):
    1.  
    2. propertyBlock.SetFloatArray ( i_shaderPropertyID_QuaterGauge_Energy, a_shaderProperties ) ;
    3. Graphics.DrawMeshInstanced ( renderData.mesh, 0, renderData.material, a_matrices, na_matrices.Length, propertyBlock, UnityEngine.Rendering.ShadowCastingMode.Off, false ) ;
    I know rendered positions are correct, based on passed a_matrices
    upload_2019-10-16_13-24-54.png
    na_matrices.Length is = 2;

    And propertyBlock appears to be ok.
    upload_2019-10-16_13-26-6.png

    However, now only first index 0 is taken into consideration. In current case, value 0.3. Which on the image above, results 30% of blue line.(30% of quarter circle). If I set value of index 0 to 0.5, it will go to 50% on both entities.

    My understanding is, that each index in propertyBlock, should result different variation of rendered shader, using same material / mesh.

    I can set different % values for each of 4 colors on the outer circle at the same time, if I pass relevant arrays of properties for each shader property ID, to each propertyBlock using SetFloatArray. Then render. Like, red 20%, blue 30%, green 50%, pink 90%. That works. But each entity will have same resulted shader, even next index of block properties will have different values.

    So as the result, weather I have 1, 2, or 100 of entities, they have same shader state.
    I can animate filling % 0 to 100%. But all animations for every entity are exactly the same.
    As I mentioned, it appears is taking only first index 0.

    So what I am missing?
    All entities use custom shared component, with material and mesh.

    Code (CSharp):
    1.     public struct CustomShaderRenderMeshSharedComponent : ISharedComponentData, IEquatable <CustomShaderRenderMeshSharedComponent>
    2.     {
    3.  
    4.         public Material material ;
    5.         public Mesh mesh ;
    6.  
    7.         public bool Equals ( CustomShaderRenderMeshSharedComponent other )
    8.         {
    9.             return mesh == other.mesh &&
    10.                 material == other.material ;
    11.         }
    12.         public override int GetHashCode ()
    13.         {
    14.             int hash = 0;
    15.             if ( !ReferenceEquals (mesh, null)) hash ^= mesh.GetHashCode () ;
    16.             if ( !ReferenceEquals (material, null)) hash ^= material.GetHashCode () ;
    17.             return hash ;
    18.         }
    19.  
    20.     }
    Does that has something to do? Maybe how hash is set?
    But again, they suppose use same material and mesh. Ins't it?

    What else I am missing?
     

    Attached Files:

    Last edited: Oct 16, 2019
  27. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Show your shader, I guess you, maybe, not set instanced buffer properly :)
     
    Last edited: Oct 16, 2019
  28. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Not sure how useful that will be, as I use shader graph, but I attached. One compiled, and two (zipped) actual shader graph.

    If I find it useful, I will probably rewrite it manually.

    I need admit, I haven't set any index, for buffer.
    But I recall now and searching, regarding custom shader for Graphics DrawMeshInstanced.
    https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstanced.html
    Graphics.

    DrawMeshInstancedIndirect got some shader examples, but I haven't touched it yet.
    https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstancedIndirect.html
    .
     

    Attached Files:

  29. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Ah it's SG, I prefer write shaders manually :) And it's SRP, I'm not digged in to SRP shaders deeply yet (I mean complex shaders like I write usual) I only ported my Height Fog to LWRP. But anyway, show me not compiled shader but generated shader code, it's not so different from what we usually can see in HLSL\GLSL:
    upload_2019-10-16_15-54-53.png
     
    Last edited: Oct 16, 2019
  30. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Yeah I was thinking between LRP and HDRP. Decided for now LRP as I don't need HDRP at this stage. More like I just wanted try do some.

    I did write some shader in past, but I am far from being fluent in it. So rather me playing shader debug game, I just dumped quick prototype in shader graph.

    I look through some old threads from end of 2018.
    Along with
    GPU instancing from documents
    https://docs.unity3d.com/Manual/GPUInstancing.html
    There is indication into
    Code (CSharp):
    1. UNITY_INSTANCING_BUFFER_START(Props)
    2.            UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
    3.         UNITY_INSTANCING_BUFFER_END(Props)
    Where _color is part of input property
    Code (CSharp):
    1. Properties {
    2.         _Color ("Color", Color) = (1,1,1,1)
    3.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    4.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    5.         _Metallic ("Metallic", Range(0,1)) = 0.0
    6.     }
    is this you may be referring to?

    So I assume, I don't need pass any index to shader. Just ensuring, I have right part of the code included?

    Which Rendering solution did you took in your project?
    Is that Graphics.DrawMeshInstancedIndirect ? Or something else?
    You mentioned quite recently
     
  31. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Most parts is RenderMeshSystemV2 , but animation is our custom Graphics.DrawMeshInstancedIndirect.
     
    Antypodish likes this.
  32. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Thx for clarification.

    In meantime, I have asked in Graphics forum section, about block property with shader graph.
    https://forum.unity.com/threads/how...or-materialpropertyblock.761927/#post-5073503

    Quick respond was, that current Shader Graph does not support (as of yet) per instance rendering. Saying that, there is some SRP solution on github.

    So I will look quickly into that github solution. But perhaps I will be better of, dusting of my shader writing.
     
  33. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    When you use Graphics.DrawMeshInstanced you must have per instance properties in order to change them with material property blocks.
    Shader graph doesn't generate instanced properties (last time i've checked) so you must do that manually.
     
    Last edited: Oct 16, 2019
    Antypodish likes this.
  34. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Oh, I didn;t realized this option exists., or I forgot about it. :)
    Here it is.
    Code (CSharp):
    1. Shader "Unlit Master"
    2. {
    3.     Properties
    4.     {
    5.         Vector1_684FC52D("RingThickness ", Range(0, 1)) = 0.1
    6. Vector1_E673978F("Opacity ", Range(0, 1)) = 0.7
    7. _QuaterGauge_Life("QuaterGauge_Life ", Range(0, 1)) = 0.5
    8. _QuaterGauge_LifeColor("QuaterGauge_LifeColor", Color) = (1,0,0,0)
    9. _QuaterGauge_Energy("QuaterGauge_Energy ", Range(0, 1)) = 0.5
    10. _QuaterGauge_EnergyColor("QuaterGauge_EnergyColor", Color) = (0,0.8806818,1,0)
    11. _QuaterGauge_Food("QuaterGauge_Food ", Range(0, 1)) = 0.5
    12. _QuaterGauge_FoodColor("QuaterGauge_FoodColor", Color) = (0.1166723,1,0.0518868,0)
    13. _QuaterGauge_Grow("QuaterGauge_Grow ", Range(0, 1)) = 0.5
    14. _QuaterGauge_GrowColor("QuaterGauge_GrowColor", Color) = (1,0,0.8821888,0)
    15. _FactionColor("FactionColor", Color) = (1,0,0.7531939,0)
    16.  
    17.     }
    18.     SubShader
    19.     {
    20.         Tags
    21.         {
    22.             "RenderPipeline"="LightweightPipeline"
    23.             "RenderType"="Transparent"
    24.             "Queue"="Transparent+0"
    25.         }
    26.         Pass
    27.         {
    28.             // Material options generated by graph
    29.  
    30.             Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
    31.  
    32.             Cull Back
    33.  
    34.             ZTest LEqual
    35.  
    36.             ZWrite Off
    37.  
    38.             HLSLPROGRAM
    39.             // Required to compile gles 2.0 with standard srp library
    40.             #pragma prefer_hlslcc gles
    41.             #pragma exclude_renderers d3d11_9x
    42.             #pragma target 2.0
    43.  
    44.             // -------------------------------------
    45.             // Lightweight Pipeline keywords
    46.             #pragma shader_feature _SAMPLE_GI
    47.  
    48.             // -------------------------------------
    49.             // Unity defined keywords
    50.             #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    51.             #pragma multi_compile _ LIGHTMAP_ON
    52.             #pragma multi_compile_fog
    53.  
    54.             //--------------------------------------
    55.             // GPU Instancing
    56.             #pragma multi_compile_instancing
    57.          
    58.             #pragma vertex vert
    59.             #pragma fragment frag
    60.  
    61.             // Defines generated by graph
    62.  
    63.             // Lighting include is needed because of GI
    64.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
    65.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
    66.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
    67.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl"
    68.             #include "Packages/com.unity.render-pipelines.lightweight/Shaders/UnlitInput.hlsl"
    69.  
    70.             CBUFFER_START(UnityPerMaterial)
    71.             float Vector1_684FC52D;
    72.             float Vector1_E673978F;
    73.             float _QuaterGauge_Life;
    74.             float4 _QuaterGauge_LifeColor;
    75.             float _QuaterGauge_Energy;
    76.             float4 _QuaterGauge_EnergyColor;
    77.             float _QuaterGauge_Food;
    78.             float4 _QuaterGauge_FoodColor;
    79.             float _QuaterGauge_Grow;
    80.             float4 _QuaterGauge_GrowColor;
    81.             float4 _FactionColor;
    82.             CBUFFER_END
    83.  
    84.             float Vector1_998B2294;
    85.             struct VertexDescriptionInputs
    86.             {
    87.                 float3 ObjectSpacePosition;
    88.             };
    89.  
    90.             struct SurfaceDescriptionInputs
    91.             {
    92.                 half4 uv0;
    93.             };
    94.  
    95.  
    96.             void Unity_Subtract_float(float A, float B, out float Out)
    97.             {
    98.                 Out = A - B;
    99.             }
    100.  
    101.             void Unity_Ellipse_float(float2 UV, float Width, float Height, out float Out)
    102.             {
    103.                 float d = length((UV * 2 - 1) / float2(Width, Height));
    104.                 Out = saturate((1 - d) / fwidth(d));
    105.             }
    106.  
    107.             struct Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79
    108.             {
    109.                 half4 uv0;
    110.             };
    111.  
    112.             void SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(float Vector1_19FD9BE1, float Vector1_ABC77F7B, Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 IN, out float OutVector1)
    113.             {
    114.                 float _Property_F1F9523F_Out_0 = Vector1_19FD9BE1;
    115.                 float _Ellipse_597A69D_Out_4;
    116.                 Unity_Ellipse_float(IN.uv0.xy, _Property_F1F9523F_Out_0, _Property_F1F9523F_Out_0, _Ellipse_597A69D_Out_4);
    117.                 float _Property_B79B322E_Out_0 = Vector1_ABC77F7B;
    118.                 float _Ellipse_A7EA0A5E_Out_4;
    119.                 Unity_Ellipse_float(IN.uv0.xy, _Property_B79B322E_Out_0, _Property_B79B322E_Out_0, _Ellipse_A7EA0A5E_Out_4);
    120.                 float _Subtract_AF084043_Out_2;
    121.                 Unity_Subtract_float(_Ellipse_597A69D_Out_4, _Ellipse_A7EA0A5E_Out_4, _Subtract_AF084043_Out_2);
    122.                 OutVector1 = _Subtract_AF084043_Out_2;
    123.             }
    124.  
    125.             void Unity_Rotate_Radians_float(float2 UV, float2 Center, float Rotation, out float2 Out)
    126.             {
    127.                 //rotation matrix
    128.                 UV -= Center;
    129.                 float s = sin(Rotation);
    130.                 float c = cos(Rotation);
    131.  
    132.                 //center rotation matrix
    133.                 float2x2 rMatrix = float2x2(c, -s, s, c);
    134.                 rMatrix *= 0.5;
    135.                 rMatrix += 0.5;
    136.                 rMatrix = rMatrix*2 - 1;
    137.  
    138.                 //multiply the UVs by the rotation matrix
    139.                 UV.xy = mul(UV.xy, rMatrix);
    140.                 UV += Center;
    141.  
    142.                 Out = UV;
    143.             }
    144.  
    145.             void Unity_PolarCoordinates_float(float2 UV, float2 Center, float RadialScale, float LengthScale, out float2 Out)
    146.             {
    147.                 float2 delta = UV - Center;
    148.                 float radius = length(delta) * 2 * RadialScale;
    149.                 float angle = atan2(delta.x, delta.y) * 1.0/6.28 * LengthScale;
    150.                 Out = float2(radius, angle);
    151.             }
    152.  
    153.             void Unity_Multiply_float (float2 A, float2 B, out float2 Out)
    154.             {
    155.                 Out = A * B;
    156.             }
    157.  
    158.             void Unity_ColorMask_float(float3 In, float3 MaskColor, float Range, out float Out, float Fuzziness)
    159.             {
    160.                 float Distance = distance(MaskColor, In);
    161.                 Out = saturate(1 - (Distance - Range) / max(Fuzziness, 1e-5));
    162.             }
    163.  
    164.             void Unity_Multiply_float (float A, float B, out float Out)
    165.             {
    166.                 Out = A * B;
    167.             }
    168.  
    169.             void Unity_Add_float(float A, float B, out float Out)
    170.             {
    171.                 Out = A + B;
    172.             }
    173.  
    174.             void Unity_Multiply_float (float4 A, float4 B, out float4 Out)
    175.             {
    176.                 Out = A * B;
    177.             }
    178.  
    179.             void Unity_Add_float4(float4 A, float4 B, out float4 Out)
    180.             {
    181.                 Out = A + B;
    182.             }
    183.  
    184.             struct Bindings_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9
    185.             {
    186.                 half4 uv0;
    187.             };
    188.  
    189.             void SG_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9(float Vector1_26FD1ECE, float Vector1_149F3F26, float Vector1_5541101A, float4 Color_47E5A8C1, Bindings_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9 IN, out float4 OutVector4)
    190.             {
    191.                 float4 Color_950DB4C6 = IsGammaSpace() ? float4(0.4528302, 0.4528302, 0.4528302, 0) : float4(SRGBToLinear(float3(0.4528302, 0.4528302, 0.4528302)), 0);
    192.                 float _Property_9CDE886C_Out_0 = Vector1_26FD1ECE;
    193.                 float _Property_4BA70374_Out_0 = Vector1_5541101A;
    194.                 float2 _Rotate_508ACFBA_Out_3;
    195.                 Unity_Rotate_Radians_float(IN.uv0.xy, float2 (0.5, 0.5), _Property_4BA70374_Out_0, _Rotate_508ACFBA_Out_3);
    196.                 float2 _PolarCoordinates_7886DF3B_Out_4;
    197.                 Unity_PolarCoordinates_float(_Rotate_508ACFBA_Out_3, float2 (0.5, 0.5), 0, 1.8, _PolarCoordinates_7886DF3B_Out_4);
    198.                 float2 _Multiply_BACCAAE1_Out_2;
    199.                 Unity_Multiply_float((_Property_9CDE886C_Out_0.xx), _PolarCoordinates_7886DF3B_Out_4, _Multiply_BACCAAE1_Out_2);
    200.                 float _Vector1_1000A148_Out_0 = 0.53;
    201.                 float _ColorMask_36EB291F_Out_3;
    202.                 Unity_ColorMask_float((float3(_Multiply_BACCAAE1_Out_2, 0.0)), IsGammaSpace() ? float3(0.1767641, 1, 0) : SRGBToLinear(float3(0.1767641, 1, 0)), _Vector1_1000A148_Out_0, _ColorMask_36EB291F_Out_3, 0);
    203.                 float _Property_80EF0A7D_Out_0 = Vector1_149F3F26;
    204.                 float _Multiply_588AE589_Out_2;
    205.                 Unity_Multiply_float(_Property_80EF0A7D_Out_0, 0.62, _Multiply_588AE589_Out_2);
    206.                 float _Add_4FD98B14_Out_2;
    207.                 Unity_Add_float(_Multiply_588AE589_Out_2, 0.38, _Add_4FD98B14_Out_2);
    208.                 float _Multiply_A1C926EE_Out_2;
    209.                 Unity_Multiply_float(_Vector1_1000A148_Out_0, _Add_4FD98B14_Out_2, _Multiply_A1C926EE_Out_2);
    210.                 float _ColorMask_55E70428_Out_3;
    211.                 Unity_ColorMask_float((float3(_Multiply_BACCAAE1_Out_2, 0.0)), IsGammaSpace() ? float3(0.1767641, 1, 0) : SRGBToLinear(float3(0.1767641, 1, 0)), _Multiply_A1C926EE_Out_2, _ColorMask_55E70428_Out_3, 0);
    212.                 float _Subtract_EDE7574E_Out_2;
    213.                 Unity_Subtract_float(_ColorMask_36EB291F_Out_3, _ColorMask_55E70428_Out_3, _Subtract_EDE7574E_Out_2);
    214.                 float4 _Multiply_AE9F44D6_Out_2;
    215.                 Unity_Multiply_float(Color_950DB4C6, (_Subtract_EDE7574E_Out_2.xxxx), _Multiply_AE9F44D6_Out_2);
    216.                 float4 _Property_1CA5A3A0_Out_0 = Color_47E5A8C1;
    217.                 float _Multiply_4BECACE1_Out_2;
    218.                 Unity_Multiply_float(_ColorMask_36EB291F_Out_3, _ColorMask_55E70428_Out_3, _Multiply_4BECACE1_Out_2);
    219.                 float4 _Multiply_4B8D2432_Out_2;
    220.                 Unity_Multiply_float(_Property_1CA5A3A0_Out_0, (_Multiply_4BECACE1_Out_2.xxxx), _Multiply_4B8D2432_Out_2);
    221.                 float4 _Add_2CF0FCBB_Out_2;
    222.                 Unity_Add_float4(_Multiply_AE9F44D6_Out_2, _Multiply_4B8D2432_Out_2, _Add_2CF0FCBB_Out_2);
    223.                 OutVector4 = _Add_2CF0FCBB_Out_2;
    224.             }
    225.  
    226.             struct VertexDescription
    227.             {
    228.                 half3 Position;
    229.             };
    230.  
    231.             VertexDescription PopulateVertexData(VertexDescriptionInputs IN)
    232.             {
    233.                 VertexDescription description = (VertexDescription)0;
    234.                 description.Position = IN.ObjectSpacePosition;
    235.                 return description;
    236.             }
    237.  
    238.             struct SurfaceDescription
    239.             {
    240.                 half3 Color;
    241.                 half Alpha;
    242.                 half AlphaClipThreshold;
    243.             };
    244.  
    245.             SurfaceDescription PopulateSurfaceData(SurfaceDescriptionInputs IN)
    246.             {
    247.                 SurfaceDescription surface = (SurfaceDescription)0;
    248.                 float _Vector1_D1DB42F1_Out_0 = 1;
    249.                 float _Property_6ED2FBAB_Out_0 = Vector1_684FC52D;
    250.                 float _Subtract_DCA9DFF1_Out_2;
    251.                 Unity_Subtract_float(_Vector1_D1DB42F1_Out_0, _Property_6ED2FBAB_Out_0, _Subtract_DCA9DFF1_Out_2);
    252.                 Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 _RingShaderSubGraph_28FDE7C6;
    253.                 _RingShaderSubGraph_28FDE7C6.uv0 = IN.uv0;
    254.                 float _RingShaderSubGraph_28FDE7C6_OutVector1_1;
    255.                 SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(_Vector1_D1DB42F1_Out_0, _Subtract_DCA9DFF1_Out_2, _RingShaderSubGraph_28FDE7C6, _RingShaderSubGraph_28FDE7C6_OutVector1_1);
    256.                 float _Property_747ED74B_Out_0 = _QuaterGauge_Food;
    257.                 float _Vector1_7DFD42F4_Out_0 = 3.23;
    258.                 float4 _Property_69D0A643_Out_0 = _QuaterGauge_FoodColor;
    259.                 Bindings_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9 _LifeInstanceQuaterGauge_C1173FFE;
    260.                 _LifeInstanceQuaterGauge_C1173FFE.uv0 = IN.uv0;
    261.                 float4 _LifeInstanceQuaterGauge_C1173FFE_OutVector4_1;
    262.                 SG_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _Property_747ED74B_Out_0, _Vector1_7DFD42F4_Out_0, _Property_69D0A643_Out_0, _LifeInstanceQuaterGauge_C1173FFE, _LifeInstanceQuaterGauge_C1173FFE_OutVector4_1);
    263.                 float _Property_84D3AEC4_Out_0 = _QuaterGauge_Grow;
    264.                 float _Vector1_1BD4DF35_Out_0 = -1.48;
    265.                 float4 _Property_E3C820CF_Out_0 = _QuaterGauge_GrowColor;
    266.                 Bindings_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9 _LifeInstanceQuaterGauge_188FF531;
    267.                 _LifeInstanceQuaterGauge_188FF531.uv0 = IN.uv0;
    268.                 float4 _LifeInstanceQuaterGauge_188FF531_OutVector4_1;
    269.                 SG_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _Property_84D3AEC4_Out_0, _Vector1_1BD4DF35_Out_0, _Property_E3C820CF_Out_0, _LifeInstanceQuaterGauge_188FF531, _LifeInstanceQuaterGauge_188FF531_OutVector4_1);
    270.                 float4 _Add_8B4E053_Out_2;
    271.                 Unity_Add_float4(_LifeInstanceQuaterGauge_C1173FFE_OutVector4_1, _LifeInstanceQuaterGauge_188FF531_OutVector4_1, _Add_8B4E053_Out_2);
    272.                 float _Property_E4305AC_Out_0 = _QuaterGauge_Life;
    273.                 float _Vector1_5632D15C_Out_0 = 1.66;
    274.                 float4 _Property_DA664AF7_Out_0 = _QuaterGauge_LifeColor;
    275.                 Bindings_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9 _LifeInstanceQuaterGauge_E38EFC6A;
    276.                 _LifeInstanceQuaterGauge_E38EFC6A.uv0 = IN.uv0;
    277.                 float4 _LifeInstanceQuaterGauge_E38EFC6A_OutVector4_1;
    278.                 SG_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _Property_E4305AC_Out_0, _Vector1_5632D15C_Out_0, _Property_DA664AF7_Out_0, _LifeInstanceQuaterGauge_E38EFC6A, _LifeInstanceQuaterGauge_E38EFC6A_OutVector4_1);
    279.                 float _Property_4D060DF5_Out_0 = _QuaterGauge_Energy;
    280.                 float _Vector1_C6C0570E_Out_0 = 0.1;
    281.                 float4 _Property_ED41A36F_Out_0 = _QuaterGauge_EnergyColor;
    282.                 Bindings_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9 _LifeInstanceQuaterGauge_6FCC829;
    283.                 _LifeInstanceQuaterGauge_6FCC829.uv0 = IN.uv0;
    284.                 float4 _LifeInstanceQuaterGauge_6FCC829_OutVector4_1;
    285.                 SG_LifeInstanceQuaterGauge_3ce9bc203e6e5e640a6a43af9635a8c9(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _Property_4D060DF5_Out_0, _Vector1_C6C0570E_Out_0, _Property_ED41A36F_Out_0, _LifeInstanceQuaterGauge_6FCC829, _LifeInstanceQuaterGauge_6FCC829_OutVector4_1);
    286.                 float4 _Add_5E63B617_Out_2;
    287.                 Unity_Add_float4(_LifeInstanceQuaterGauge_E38EFC6A_OutVector4_1, _LifeInstanceQuaterGauge_6FCC829_OutVector4_1, _Add_5E63B617_Out_2);
    288.                 float4 _Add_E2DCD5CC_Out_2;
    289.                 Unity_Add_float4(_Add_8B4E053_Out_2, _Add_5E63B617_Out_2, _Add_E2DCD5CC_Out_2);
    290.                 float _Vector1_36B84BEF_Out_0 = 0.85;
    291.                 float _Property_6635B9D4_Out_0 = Vector1_684FC52D;
    292.                 float _Subtract_47AA4610_Out_2;
    293.                 Unity_Subtract_float(_Vector1_36B84BEF_Out_0, _Property_6635B9D4_Out_0, _Subtract_47AA4610_Out_2);
    294.                 Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 _RingShaderSubGraph_99DC60D2;
    295.                 _RingShaderSubGraph_99DC60D2.uv0 = IN.uv0;
    296.                 float _RingShaderSubGraph_99DC60D2_OutVector1_1;
    297.                 SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(_Vector1_36B84BEF_Out_0, _Subtract_47AA4610_Out_2, _RingShaderSubGraph_99DC60D2, _RingShaderSubGraph_99DC60D2_OutVector1_1);
    298.                 float4 _Property_CCCB3114_Out_0 = _FactionColor;
    299.                 float4 _Multiply_730ACEF8_Out_2;
    300.                 Unity_Multiply_float((_RingShaderSubGraph_99DC60D2_OutVector1_1.xxxx), _Property_CCCB3114_Out_0, _Multiply_730ACEF8_Out_2);
    301.                 float4 _Add_18C622C4_Out_2;
    302.                 Unity_Add_float4(_Add_E2DCD5CC_Out_2, _Multiply_730ACEF8_Out_2, _Add_18C622C4_Out_2);
    303.                 float _Add_813BA9B0_Out_2;
    304.                 Unity_Add_float(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _RingShaderSubGraph_99DC60D2_OutVector1_1, _Add_813BA9B0_Out_2);
    305.                 surface.Color = (_Add_18C622C4_Out_2.xyz);
    306.                 surface.Alpha = _Add_813BA9B0_Out_2;
    307.                 surface.AlphaClipThreshold = 0.5;
    308.                 return surface;
    309.             }
    310.  
    311.             struct GraphVertexInput
    312.             {
    313.                 float4 vertex : POSITION;
    314.                 float3 normal : NORMAL;
    315.                 float4 tangent : TANGENT;
    316.                 float4 texcoord0 : TEXCOORD0;
    317.                 float4 texcoord1 : TEXCOORD1;
    318.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    319.             };
    320.  
    321.  
    322.             struct GraphVertexOutput
    323.             {
    324.                 float4 position : POSITION;
    325.  
    326.                 // Interpolators defined by graph
    327.                 float3 WorldSpacePosition : TEXCOORD3;
    328.                 float3 WorldSpaceNormal : TEXCOORD4;
    329.                 float3 WorldSpaceTangent : TEXCOORD5;
    330.                 float3 WorldSpaceBiTangent : TEXCOORD6;
    331.                 float3 WorldSpaceViewDirection : TEXCOORD7;
    332.                 half4 uv0 : TEXCOORD8;
    333.                 half4 uv1 : TEXCOORD9;
    334.  
    335.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    336.                 UNITY_VERTEX_OUTPUT_STEREO
    337.             };
    338.  
    339.             GraphVertexOutput vert (GraphVertexInput v)
    340.             {
    341.                 GraphVertexOutput o = (GraphVertexOutput)0;
    342.                 UNITY_SETUP_INSTANCE_ID(v);
    343.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
    344.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    345.  
    346.                 // Vertex transformations performed by graph
    347.                 float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex).xyz;
    348.                 float3 WorldSpaceNormal = normalize(mul(v.normal,(float3x3)UNITY_MATRIX_I_M));
    349.                 float3 WorldSpaceTangent = normalize(mul((float3x3)UNITY_MATRIX_M,v.tangent.xyz));
    350.                 float3 WorldSpaceBiTangent = cross(WorldSpaceNormal, WorldSpaceTangent.xyz) * v.tangent.w;
    351.                 float3 WorldSpaceViewDirection = _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz;
    352.                 float4 uv0 = v.texcoord0;
    353.                 float4 uv1 = v.texcoord1;
    354.                 float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0)).xyz;
    355.  
    356.                 VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
    357.  
    358.                 // Vertex description inputs defined by graph
    359.                 vdi.ObjectSpacePosition = ObjectSpacePosition;
    360.  
    361.                 VertexDescription vd = PopulateVertexData(vdi);
    362.                 v.vertex.xyz = vd.Position;
    363.  
    364.                 o.position = TransformObjectToHClip(v.vertex.xyz);
    365.                 // Vertex shader outputs defined by graph
    366.                 o.WorldSpacePosition = WorldSpacePosition;
    367.                 o.WorldSpaceNormal = WorldSpaceNormal;
    368.                 o.WorldSpaceTangent = WorldSpaceTangent;
    369.                 o.WorldSpaceBiTangent = WorldSpaceBiTangent;
    370.                 o.WorldSpaceViewDirection = WorldSpaceViewDirection;
    371.                 o.uv0 = uv0;
    372.                 o.uv1 = uv1;
    373.  
    374.                 return o;
    375.             }
    376.  
    377.             half4 frag (GraphVertexOutput IN ) : SV_Target
    378.             {
    379.                 UNITY_SETUP_INSTANCE_ID(IN);
    380.                 UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
    381.  
    382.                 // Pixel transformations performed by graph
    383.                 float3 WorldSpacePosition = IN.WorldSpacePosition;
    384.                 float3 WorldSpaceNormal = IN.WorldSpaceNormal;
    385.                 float3 WorldSpaceTangent = IN.WorldSpaceTangent;
    386.                 float3 WorldSpaceBiTangent = IN.WorldSpaceBiTangent;
    387.                 float3 WorldSpaceViewDirection = IN.WorldSpaceViewDirection;
    388.                 float4 uv0 = IN.uv0;
    389.                 float4 uv1 = IN.uv1;
    390.  
    391.              
    392.                 SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;
    393.                 // Surface description inputs defined by graph
    394.                 surfaceInput.uv0 = uv0;
    395.  
    396.  
    397.                 SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
    398.                 float3 Color = float3(0.5, 0.5, 0.5);
    399.                 float Alpha = 1;
    400.                 float AlphaClipThreshold = 0;
    401.                 // Surface description remap performed by graph
    402.                 Color = surf.Color;
    403.                 Alpha = surf.Alpha;
    404.                 AlphaClipThreshold = surf.AlphaClipThreshold;
    405.  
    406.              
    407.          #if _AlphaClip
    408.                 clip(Alpha - AlphaClipThreshold);
    409.         #endif
    410.                 return half4(Color, Alpha);
    411.             }
    412.             ENDHLSL
    413.         }
    414.         Pass
    415.         {
    416.             Name "ShadowCaster"
    417.             Tags{"LightMode" = "ShadowCaster"}
    418.  
    419.             ZWrite On ZTest LEqual
    420.  
    421.             // Material options generated by graph
    422.             Cull Back
    423.  
    424.             HLSLPROGRAM
    425.             // Required to compile gles 2.0 with standard srp library
    426.             #pragma prefer_hlslcc gles
    427.             #pragma exclude_renderers d3d11_9x
    428.             #pragma target 2.0
    429.  
    430.             //--------------------------------------
    431.             // GPU Instancing
    432.             #pragma multi_compile_instancing
    433.  
    434.             #pragma vertex ShadowPassVertex
    435.             #pragma fragment ShadowPassFragment
    436.  
    437.             // Defines generated by graph
    438.  
    439.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
    440.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
    441.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl"
    442.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
    443.  
    444.             CBUFFER_START(UnityPerMaterial)
    445.             float Vector1_684FC52D;
    446.             float Vector1_E673978F;
    447.             float _QuaterGauge_Life;
    448.             float4 _QuaterGauge_LifeColor;
    449.             float _QuaterGauge_Energy;
    450.             float4 _QuaterGauge_EnergyColor;
    451.             float _QuaterGauge_Food;
    452.             float4 _QuaterGauge_FoodColor;
    453.             float _QuaterGauge_Grow;
    454.             float4 _QuaterGauge_GrowColor;
    455.             float4 _FactionColor;
    456.             CBUFFER_END
    457.  
    458.             float Vector1_998B2294;
    459.             struct VertexDescriptionInputs
    460.             {
    461.                 float3 ObjectSpacePosition;
    462.             };
    463.  
    464.             struct SurfaceDescriptionInputs
    465.             {
    466.                 half4 uv0;
    467.             };
    468.  
    469.  
    470.             void Unity_Subtract_float(float A, float B, out float Out)
    471.             {
    472.                 Out = A - B;
    473.             }
    474.  
    475.             void Unity_Ellipse_float(float2 UV, float Width, float Height, out float Out)
    476.             {
    477.                 float d = length((UV * 2 - 1) / float2(Width, Height));
    478.                 Out = saturate((1 - d) / fwidth(d));
    479.             }
    480.  
    481.             struct Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79
    482.             {
    483.                 half4 uv0;
    484.             };
    485.  
    486.             void SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(float Vector1_19FD9BE1, float Vector1_ABC77F7B, Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 IN, out float OutVector1)
    487.             {
    488.                 float _Property_F1F9523F_Out_0 = Vector1_19FD9BE1;
    489.                 float _Ellipse_597A69D_Out_4;
    490.                 Unity_Ellipse_float(IN.uv0.xy, _Property_F1F9523F_Out_0, _Property_F1F9523F_Out_0, _Ellipse_597A69D_Out_4);
    491.                 float _Property_B79B322E_Out_0 = Vector1_ABC77F7B;
    492.                 float _Ellipse_A7EA0A5E_Out_4;
    493.                 Unity_Ellipse_float(IN.uv0.xy, _Property_B79B322E_Out_0, _Property_B79B322E_Out_0, _Ellipse_A7EA0A5E_Out_4);
    494.                 float _Subtract_AF084043_Out_2;
    495.                 Unity_Subtract_float(_Ellipse_597A69D_Out_4, _Ellipse_A7EA0A5E_Out_4, _Subtract_AF084043_Out_2);
    496.                 OutVector1 = _Subtract_AF084043_Out_2;
    497.             }
    498.  
    499.             void Unity_Add_float(float A, float B, out float Out)
    500.             {
    501.                 Out = A + B;
    502.             }
    503.  
    504.             struct VertexDescription
    505.             {
    506.                 half3 Position;
    507.             };
    508.  
    509.             VertexDescription PopulateVertexData(VertexDescriptionInputs IN)
    510.             {
    511.                 VertexDescription description = (VertexDescription)0;
    512.                 description.Position = IN.ObjectSpacePosition;
    513.                 return description;
    514.             }
    515.  
    516.             struct SurfaceDescription
    517.             {
    518.                 half Alpha;
    519.                 half AlphaClipThreshold;
    520.             };
    521.  
    522.             SurfaceDescription PopulateSurfaceData(SurfaceDescriptionInputs IN)
    523.             {
    524.                 SurfaceDescription surface = (SurfaceDescription)0;
    525.                 float _Vector1_D1DB42F1_Out_0 = 1;
    526.                 float _Property_6ED2FBAB_Out_0 = Vector1_684FC52D;
    527.                 float _Subtract_DCA9DFF1_Out_2;
    528.                 Unity_Subtract_float(_Vector1_D1DB42F1_Out_0, _Property_6ED2FBAB_Out_0, _Subtract_DCA9DFF1_Out_2);
    529.                 Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 _RingShaderSubGraph_28FDE7C6;
    530.                 _RingShaderSubGraph_28FDE7C6.uv0 = IN.uv0;
    531.                 float _RingShaderSubGraph_28FDE7C6_OutVector1_1;
    532.                 SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(_Vector1_D1DB42F1_Out_0, _Subtract_DCA9DFF1_Out_2, _RingShaderSubGraph_28FDE7C6, _RingShaderSubGraph_28FDE7C6_OutVector1_1);
    533.                 float _Vector1_36B84BEF_Out_0 = 0.85;
    534.                 float _Property_6635B9D4_Out_0 = Vector1_684FC52D;
    535.                 float _Subtract_47AA4610_Out_2;
    536.                 Unity_Subtract_float(_Vector1_36B84BEF_Out_0, _Property_6635B9D4_Out_0, _Subtract_47AA4610_Out_2);
    537.                 Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 _RingShaderSubGraph_99DC60D2;
    538.                 _RingShaderSubGraph_99DC60D2.uv0 = IN.uv0;
    539.                 float _RingShaderSubGraph_99DC60D2_OutVector1_1;
    540.                 SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(_Vector1_36B84BEF_Out_0, _Subtract_47AA4610_Out_2, _RingShaderSubGraph_99DC60D2, _RingShaderSubGraph_99DC60D2_OutVector1_1);
    541.                 float _Add_813BA9B0_Out_2;
    542.                 Unity_Add_float(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _RingShaderSubGraph_99DC60D2_OutVector1_1, _Add_813BA9B0_Out_2);
    543.                 surface.Alpha = _Add_813BA9B0_Out_2;
    544.                 surface.AlphaClipThreshold = 0.5;
    545.                 return surface;
    546.             }
    547.  
    548.             struct GraphVertexInput
    549.             {
    550.                 float4 vertex : POSITION;
    551.                 float3 normal : NORMAL;
    552.                 float4 tangent : TANGENT;
    553.                 float4 texcoord0 : TEXCOORD0;
    554.                 float4 texcoord1 : TEXCOORD1;
    555.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    556.             };
    557.  
    558.  
    559.             struct VertexOutput
    560.             {
    561.                 float2 uv           : TEXCOORD0;
    562.                 float4 clipPos      : SV_POSITION;
    563.                 // Interpolators defined by graph
    564.                 float3 WorldSpacePosition : TEXCOORD3;
    565.                 float3 WorldSpaceNormal : TEXCOORD4;
    566.                 float3 WorldSpaceTangent : TEXCOORD5;
    567.                 float3 WorldSpaceBiTangent : TEXCOORD6;
    568.                 float3 WorldSpaceViewDirection : TEXCOORD7;
    569.                 half4 uv0 : TEXCOORD8;
    570.                 half4 uv1 : TEXCOORD9;
    571.  
    572.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    573.                 UNITY_VERTEX_OUTPUT_STEREO
    574.             };
    575.  
    576.             float3 _LightDirection;
    577.  
    578.             VertexOutput ShadowPassVertex(GraphVertexInput v)
    579.             {
    580.                 VertexOutput o;
    581.                 UNITY_SETUP_INSTANCE_ID(v);
    582.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
    583.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    584.  
    585.                 // Vertex transformations performed by graph
    586.                 float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex).xyz;
    587.                 float3 WorldSpaceNormal = normalize(mul(v.normal,(float3x3)UNITY_MATRIX_I_M));
    588.                 float3 WorldSpaceTangent = normalize(mul((float3x3)UNITY_MATRIX_M,v.tangent.xyz));
    589.                 float3 WorldSpaceBiTangent = cross(WorldSpaceNormal, WorldSpaceTangent.xyz) * v.tangent.w;
    590.                 float3 WorldSpaceViewDirection = _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz;
    591.                 float4 uv0 = v.texcoord0;
    592.                 float4 uv1 = v.texcoord1;
    593.                 float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0)).xyz;
    594.  
    595.                 VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
    596.  
    597.                 // Vertex description inputs defined by graph
    598.                 vdi.ObjectSpacePosition = ObjectSpacePosition;
    599.  
    600.                 VertexDescription vd = PopulateVertexData(vdi);
    601.                 v.vertex.xyz = vd.Position;
    602.  
    603.                 // Vertex shader outputs defined by graph
    604.                 o.WorldSpacePosition = WorldSpacePosition;
    605.                 o.WorldSpaceNormal = WorldSpaceNormal;
    606.                 o.WorldSpaceTangent = WorldSpaceTangent;
    607.                 o.WorldSpaceBiTangent = WorldSpaceBiTangent;
    608.                 o.WorldSpaceViewDirection = WorldSpaceViewDirection;
    609.                 o.uv0 = uv0;
    610.                 o.uv1 = uv1;
    611.  
    612.              
    613.                 float3 positionWS = TransformObjectToWorld(v.vertex.xyz);
    614.                 float3 normalWS = TransformObjectToWorldNormal(v.normal);
    615.  
    616.                 float4 clipPos = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
    617.  
    618.             #if UNITY_REVERSED_Z
    619.                 clipPos.z = min(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
    620.             #else
    621.                 clipPos.z = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
    622.             #endif
    623.                 o.clipPos = clipPos;
    624.  
    625.                 return o;
    626.             }
    627.  
    628.             half4 ShadowPassFragment(VertexOutput IN ) : SV_TARGET
    629.             {
    630.                 UNITY_SETUP_INSTANCE_ID(IN);
    631.                 UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
    632.  
    633.                 // Pixel transformations performed by graph
    634.                 float3 WorldSpacePosition = IN.WorldSpacePosition;
    635.                 float3 WorldSpaceNormal = IN.WorldSpaceNormal;
    636.                 float3 WorldSpaceTangent = IN.WorldSpaceTangent;
    637.                 float3 WorldSpaceBiTangent = IN.WorldSpaceBiTangent;
    638.                 float3 WorldSpaceViewDirection = IN.WorldSpaceViewDirection;
    639.                 float4 uv0 = IN.uv0;
    640.                 float4 uv1 = IN.uv1;
    641.  
    642.                 SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;
    643.  
    644.                 // Surface description inputs defined by graph
    645.                 surfaceInput.uv0 = uv0;
    646.  
    647.                 SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
    648.  
    649.                 float Alpha = 1;
    650.                 float AlphaClipThreshold = 0;
    651.  
    652.                 // Surface description remap performed by graph
    653.                 Alpha = surf.Alpha;
    654.                 AlphaClipThreshold = surf.AlphaClipThreshold;
    655.  
    656.          #if _AlphaClip
    657.                 clip(Alpha - AlphaClipThreshold);
    658.         #endif
    659.                 return 0;
    660.             }
    661.  
    662.             ENDHLSL
    663.         }
    664.  
    665.         Pass
    666.         {
    667.             Name "DepthOnly"
    668.             Tags{"LightMode" = "DepthOnly"}
    669.  
    670.             ZWrite On
    671.             ColorMask 0
    672.  
    673.             // Material options generated by graph
    674.             Cull Back
    675.  
    676.             HLSLPROGRAM
    677.             // Required to compile gles 2.0 with standard srp library
    678.             #pragma prefer_hlslcc gles
    679.             #pragma exclude_renderers d3d11_9x
    680.             #pragma target 2.0
    681.  
    682.             //--------------------------------------
    683.             // GPU Instancing
    684.             #pragma multi_compile_instancing
    685.  
    686.             #pragma vertex vert
    687.             #pragma fragment frag
    688.  
    689.             // Defines generated by graph
    690.  
    691.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
    692.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
    693.             #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl"
    694.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
    695.  
    696.             CBUFFER_START(UnityPerMaterial)
    697.             float Vector1_684FC52D;
    698.             float Vector1_E673978F;
    699.             float _QuaterGauge_Life;
    700.             float4 _QuaterGauge_LifeColor;
    701.             float _QuaterGauge_Energy;
    702.             float4 _QuaterGauge_EnergyColor;
    703.             float _QuaterGauge_Food;
    704.             float4 _QuaterGauge_FoodColor;
    705.             float _QuaterGauge_Grow;
    706.             float4 _QuaterGauge_GrowColor;
    707.             float4 _FactionColor;
    708.             CBUFFER_END
    709.  
    710.             float Vector1_998B2294;
    711.             struct VertexDescriptionInputs
    712.             {
    713.                 float3 ObjectSpacePosition;
    714.             };
    715.  
    716.             struct SurfaceDescriptionInputs
    717.             {
    718.                 half4 uv0;
    719.             };
    720.  
    721.  
    722.             void Unity_Subtract_float(float A, float B, out float Out)
    723.             {
    724.                 Out = A - B;
    725.             }
    726.  
    727.             void Unity_Ellipse_float(float2 UV, float Width, float Height, out float Out)
    728.             {
    729.                 float d = length((UV * 2 - 1) / float2(Width, Height));
    730.                 Out = saturate((1 - d) / fwidth(d));
    731.             }
    732.  
    733.             struct Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79
    734.             {
    735.                 half4 uv0;
    736.             };
    737.  
    738.             void SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(float Vector1_19FD9BE1, float Vector1_ABC77F7B, Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 IN, out float OutVector1)
    739.             {
    740.                 float _Property_F1F9523F_Out_0 = Vector1_19FD9BE1;
    741.                 float _Ellipse_597A69D_Out_4;
    742.                 Unity_Ellipse_float(IN.uv0.xy, _Property_F1F9523F_Out_0, _Property_F1F9523F_Out_0, _Ellipse_597A69D_Out_4);
    743.                 float _Property_B79B322E_Out_0 = Vector1_ABC77F7B;
    744.                 float _Ellipse_A7EA0A5E_Out_4;
    745.                 Unity_Ellipse_float(IN.uv0.xy, _Property_B79B322E_Out_0, _Property_B79B322E_Out_0, _Ellipse_A7EA0A5E_Out_4);
    746.                 float _Subtract_AF084043_Out_2;
    747.                 Unity_Subtract_float(_Ellipse_597A69D_Out_4, _Ellipse_A7EA0A5E_Out_4, _Subtract_AF084043_Out_2);
    748.                 OutVector1 = _Subtract_AF084043_Out_2;
    749.             }
    750.  
    751.             void Unity_Add_float(float A, float B, out float Out)
    752.             {
    753.                 Out = A + B;
    754.             }
    755.  
    756.             struct VertexDescription
    757.             {
    758.                 half3 Position;
    759.             };
    760.  
    761.             VertexDescription PopulateVertexData(VertexDescriptionInputs IN)
    762.             {
    763.                 VertexDescription description = (VertexDescription)0;
    764.                 description.Position = IN.ObjectSpacePosition;
    765.                 return description;
    766.             }
    767.  
    768.             struct SurfaceDescription
    769.             {
    770.                 half Alpha;
    771.                 half AlphaClipThreshold;
    772.             };
    773.  
    774.             SurfaceDescription PopulateSurfaceData(SurfaceDescriptionInputs IN)
    775.             {
    776.                 SurfaceDescription surface = (SurfaceDescription)0;
    777.                 float _Vector1_D1DB42F1_Out_0 = 1;
    778.                 float _Property_6ED2FBAB_Out_0 = Vector1_684FC52D;
    779.                 float _Subtract_DCA9DFF1_Out_2;
    780.                 Unity_Subtract_float(_Vector1_D1DB42F1_Out_0, _Property_6ED2FBAB_Out_0, _Subtract_DCA9DFF1_Out_2);
    781.                 Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 _RingShaderSubGraph_28FDE7C6;
    782.                 _RingShaderSubGraph_28FDE7C6.uv0 = IN.uv0;
    783.                 float _RingShaderSubGraph_28FDE7C6_OutVector1_1;
    784.                 SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(_Vector1_D1DB42F1_Out_0, _Subtract_DCA9DFF1_Out_2, _RingShaderSubGraph_28FDE7C6, _RingShaderSubGraph_28FDE7C6_OutVector1_1);
    785.                 float _Vector1_36B84BEF_Out_0 = 0.85;
    786.                 float _Property_6635B9D4_Out_0 = Vector1_684FC52D;
    787.                 float _Subtract_47AA4610_Out_2;
    788.                 Unity_Subtract_float(_Vector1_36B84BEF_Out_0, _Property_6635B9D4_Out_0, _Subtract_47AA4610_Out_2);
    789.                 Bindings_RingShaderSubGraph_b2b6911066df1714c88312a104028c79 _RingShaderSubGraph_99DC60D2;
    790.                 _RingShaderSubGraph_99DC60D2.uv0 = IN.uv0;
    791.                 float _RingShaderSubGraph_99DC60D2_OutVector1_1;
    792.                 SG_RingShaderSubGraph_b2b6911066df1714c88312a104028c79(_Vector1_36B84BEF_Out_0, _Subtract_47AA4610_Out_2, _RingShaderSubGraph_99DC60D2, _RingShaderSubGraph_99DC60D2_OutVector1_1);
    793.                 float _Add_813BA9B0_Out_2;
    794.                 Unity_Add_float(_RingShaderSubGraph_28FDE7C6_OutVector1_1, _RingShaderSubGraph_99DC60D2_OutVector1_1, _Add_813BA9B0_Out_2);
    795.                 surface.Alpha = _Add_813BA9B0_Out_2;
    796.                 surface.AlphaClipThreshold = 0.5;
    797.                 return surface;
    798.             }
    799.  
    800.             struct GraphVertexInput
    801.             {
    802.                 float4 vertex : POSITION;
    803.                 float3 normal : NORMAL;
    804.                 float4 tangent : TANGENT;
    805.                 float4 texcoord0 : TEXCOORD0;
    806.                 float4 texcoord1 : TEXCOORD1;
    807.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    808.             };
    809.  
    810.  
    811.             struct VertexOutput
    812.             {
    813.                 float2 uv           : TEXCOORD0;
    814.                 float4 clipPos      : SV_POSITION;
    815.                 // Interpolators defined by graph
    816.                 float3 WorldSpacePosition : TEXCOORD3;
    817.                 float3 WorldSpaceNormal : TEXCOORD4;
    818.                 float3 WorldSpaceTangent : TEXCOORD5;
    819.                 float3 WorldSpaceBiTangent : TEXCOORD6;
    820.                 float3 WorldSpaceViewDirection : TEXCOORD7;
    821.                 half4 uv0 : TEXCOORD8;
    822.                 half4 uv1 : TEXCOORD9;
    823.  
    824.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    825.                 UNITY_VERTEX_OUTPUT_STEREO
    826.             };
    827.  
    828.             VertexOutput vert(GraphVertexInput v)
    829.             {
    830.                 VertexOutput o = (VertexOutput)0;
    831.                 UNITY_SETUP_INSTANCE_ID(v);
    832.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
    833.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    834.  
    835.                 // Vertex transformations performed by graph
    836.                 float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex).xyz;
    837.                 float3 WorldSpaceNormal = normalize(mul(v.normal,(float3x3)UNITY_MATRIX_I_M));
    838.                 float3 WorldSpaceTangent = normalize(mul((float3x3)UNITY_MATRIX_M,v.tangent.xyz));
    839.                 float3 WorldSpaceBiTangent = cross(WorldSpaceNormal, WorldSpaceTangent.xyz) * v.tangent.w;
    840.                 float3 WorldSpaceViewDirection = _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz;
    841.                 float4 uv0 = v.texcoord0;
    842.                 float4 uv1 = v.texcoord1;
    843.                 float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0)).xyz;
    844.  
    845.                 VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
    846.  
    847.                 // Vertex description inputs defined by graph
    848.                 vdi.ObjectSpacePosition = ObjectSpacePosition;
    849.  
    850.                 VertexDescription vd = PopulateVertexData(vdi);
    851.                 v.vertex.xyz = vd.Position;
    852.  
    853.                 // Vertex shader outputs defined by graph
    854.                 o.WorldSpacePosition = WorldSpacePosition;
    855.                 o.WorldSpaceNormal = WorldSpaceNormal;
    856.                 o.WorldSpaceTangent = WorldSpaceTangent;
    857.                 o.WorldSpaceBiTangent = WorldSpaceBiTangent;
    858.                 o.WorldSpaceViewDirection = WorldSpaceViewDirection;
    859.                 o.uv0 = uv0;
    860.                 o.uv1 = uv1;
    861.  
    862.                 o.clipPos = TransformObjectToHClip(v.vertex.xyz);
    863.                 return o;
    864.             }
    865.  
    866.             half4 frag(VertexOutput IN ) : SV_TARGET
    867.             {
    868.                 UNITY_SETUP_INSTANCE_ID(IN);
    869.                 UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
    870.  
    871.                 // Pixel transformations performed by graph
    872.                 float3 WorldSpacePosition = IN.WorldSpacePosition;
    873.                 float3 WorldSpaceNormal = IN.WorldSpaceNormal;
    874.                 float3 WorldSpaceTangent = IN.WorldSpaceTangent;
    875.                 float3 WorldSpaceBiTangent = IN.WorldSpaceBiTangent;
    876.                 float3 WorldSpaceViewDirection = IN.WorldSpaceViewDirection;
    877.                 float4 uv0 = IN.uv0;
    878.                 float4 uv1 = IN.uv1;
    879.  
    880.                 SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;
    881.  
    882.                 // Surface description inputs defined by graph
    883.                 surfaceInput.uv0 = uv0;
    884.  
    885.                 SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
    886.  
    887.                 float Alpha = 1;
    888.                 float AlphaClipThreshold = 0;
    889.  
    890.                 // Surface description remap performed by graph
    891.                 Alpha = surf.Alpha;
    892.                 AlphaClipThreshold = surf.AlphaClipThreshold;
    893.  
    894.          #if _AlphaClip
    895.                 clip(Alpha - AlphaClipThreshold);
    896.         #endif
    897.                 return 0;
    898.             }
    899.             ENDHLSL
    900.         }
    901.     }
    902.     FallBack "Hidden/InternalErrorShader"
    903. }
    904.  
     
  35. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Don't forget that the instanced property must be accessed correctly:
    eg:
    Code (CSharp):
    1.  
    2.            fixed4 frag(v2f i) : SV_Target
    3.            {
    4.                UNITY_SETUP_INSTANCE_ID(i); // necessary only if any instanced properties are going to be accessed in the fragment Shader.
    5.                return UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
    6.            }
    7.  
    And the shader must have #pragma multi_compile_instancing
     
    Antypodish likes this.
  36. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    This part is definitely missing from my generated shader.
    This however exists
    Code (CSharp):
    1. //--------------------------------------
    2.             // GPU Instancing
    3.             #pragma multi_compile_instancing
    Not sure if this lines are also required, but are not in my generated code.
    Code (CSharp):
    1. UNITY_INSTANCING_BUFFER_START(Props)
    2.            UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
    3.         UNITY_INSTANCING_BUFFER_END(Props)
     
  37. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    SG generates it.
    @Antypodish
    upload_2019-10-16_17-23-4.png

    And comment
    #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" cause of that https://issuetracker.unity3d.com/is...r-compilation-error-when-using-gpu-instancing
    And save as shader, after that it will work (Code ugly, fast written, just for showing how it works):
    Code (CSharp):
    1. public class SetCOlor : MonoBehaviour
    2. {
    3.     [Range(0,1f)]
    4.     public float Sphere1Color = 0f;
    5.     [Range(0, 1f)]
    6.     public float Sphere2Color = 0f;
    7.     [Range(0, 1f)]
    8.     public float Sphere3Color = 0f;
    9.  
    10.     public Transform[] Transforms;
    11.  
    12.     public Mesh Mesh;
    13.     public Material Mat;
    14.  
    15.     void Update()
    16.     {
    17.         var matrices = new Matrix4x4[Transforms.Length];
    18.         var props = new MaterialPropertyBlock();
    19.  
    20.         for (int i = 0; i < Transforms.Length; ++i)
    21.         {
    22.             matrices[i] = Matrix4x4.identity;
    23.             matrices[i].SetTRS(Transforms[i].position, Quaternion.identity, Vector3.one);
    24.         }
    25.         props.SetVectorArray("_PerInstanceColor", new Vector4[]
    26.         {
    27.             new Vector4(Sphere1Color, Sphere1Color, Sphere1Color, Sphere1Color),
    28.             new Vector4(Sphere2Color, Sphere2Color, Sphere2Color, Sphere2Color),
    29.             new Vector4(Sphere3Color, Sphere3Color, Sphere3Color, Sphere3Color),
    30.         });
    31.  
    32.         Graphics.DrawMeshInstanced(Mesh, 0, Mat, matrices, Transforms.Length, props);
    33.     }
    34. }
     
  38. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    So I need to say this amazingly work @eizenhorn :)

    With one big BUT.
    I could not manage to work it on 2019.2
    Throws row of errors, which I am not experienced to solve.
    However, I installed Unity 2020.1a, as I remember you are on latest version and installed Universal RP package.
    That works practically out of the box, with minor adjustment.

    Either way, thx lot.

    That mean however, I better transit to 2020.1a now.
    Not sure if same works on 2019.3. I had some errors on my version. Maybe after reinstalling. But I will try 2020 first.
     
  39. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Yes I’m on latest beta :) 2019.3.0b7 :) and this video from it (you can see in the corner)
     
  40. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    I more remember you post from other thread and deducted by the look of Unity in vid. But true point :)

    Just to note, I didn't have to comment it out, with 2020.1a.
    Or at least I didn't see error. But something to keep in mind.
     
    Last edited: Oct 16, 2019
  41. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Yep, guess redifinition can be fixed in alpha, I not checked it, I just “fixed” your problem on my current version
     
    Antypodish likes this.
  42. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Just my little update on progress with my ring shaped shader and multiple properties, which is as desired at this stage.
    However using Graphics.DrawMeshInstanced and MaterialPropertyBlock in this example, on over 2k instances.



    So as discussed earlier, I used Shader Graph as way to make my shader. Then modified source code after conversion, to be compatible with MaterialPropertyBlock. As result, I can set now 4 properties on each ring shaped shader.

    I probably wont stop on DrawMeshInstanced. But for now is good as it is :)

    Thx for support on that matter.
     
    daniilkorotin and eizenhorn like this.
  43. li2343

    li2343

    Joined:
    Jan 16, 2019
    Posts:
    2
    I am Bosheng Li. For the videos you referenced above, I indeed used custom graphics command like DrawMeshInstancedIndirect for that. I use my own render system instead of the RenderMeshSystemV2. That's also why I tried to implement my own frustum culling and LOD part for my own rendering system. The main reason for not using the RenderMeshSystemV2 is because I believe that it does't support instancing, thus not friendly for circumstances like drawing thousands of stars that only varies in their shader part.
     
    Zyblade likes this.
  44. li2343

    li2343

    Joined:
    Jan 16, 2019
    Posts:
    2