Hi!
Experiencing strange behavior when using 1 SG shader for 2 GameObjects seen by the same camera! Possibly easy fix for those who already encountered it!
I assume there is something simple i’m missing, but when i simply:
create a sprite (2D) in scene (sprite component, test rectangular S2D texture, inside GameObject)
change the sprite’s material to one that wraps the new shader (SpriteLitMaster) i just made
rotate the object and change its position
It all works well!
Until… i duplicate the GameObject…
Now when the camera (orthographic or perspective) sees only one of the objects, their rotation and position is showing correctly.
But when i adjust the camera to see both of the objects, then both of the objects reset their rotation to 0 and vertical position to 0.
It might be my shader – or it might be a bug? (i doubt it, its just something too simple to not be noticed over multiple Unity versions) – i’ve tried U2019.3 and U2020.2b, SG versions 7.1.8 and 10.2.2)
Added a screenshot of SG for clarity:
wave-shader hosted at ImgBB — ImgBB
EDIT1: I can confirm this happens because of the shader used. However i still don’t understand, why single object works well and multiple objects don’t. It seems to have something to do with me rewiring the position node, but why is this change not kept local per GameObject? Would that mean each shader would have to be instanced rather than shared? How would you solve this problem (im trying to make a wavy shader with custom transform per GameObject)? Thanks!
EDIT2: It was my mistake… not understanding the shaders well. To individuate the vertical position of each GameObject, i had to - in the shader - connect the Y output of the position node into a new Add node - and the secondary input of the Add node had to be output from all the lower calculations of the graph (UVs, Sine,…) - this way the shader could account for the individual vertical positions of the GameObjects. The output of the new Add node then directly connects to the Y input of the Combine node, that then connects to the Vertex Position Input of the Sprite Unlit Master Node. Im still looking at rotation, but given time and the recent understanding, im sure this could be solved as well.