Is there any reason for u_sprite_size to be (0,0)? - sprite-kit

I've been working to add a fragment shader to a SKSpriteNode of size (1024,768) on a screen with a size of (1024, 768), but the variables in the shader keep returning strange values. The u_sprite_size is always (0,0) and the v_tex_coord.x seems to be 0.1435 at one end of the sprite and .16075 at the other.
Is there any reason this should be happening?

Related

Any way to get a URP shader to tile at a constant size, regardless of face orientation?

I need a shader which I can apply to a surface, and have it tile a texture at a constant size. Think 'stretchable brick wall' I looked at this world shader hoping I could adapt. https://www.youtube.com/watch?v=vIh_6xtBwsI&ab_channel=JustinFoley
The problem with world UV's is they only project along the major axes. I need it to follow the rotation of the object, just not affected by scale.
This is what I was trying:
But as you can imagine, it is still affected by scale, and appears to align with the y plane:

Unity3d Shader Z testing question, ZTest Greater but keep behind

I'm rather new with shaders in Unity and I'm trying to create something but all my attempts failed.
The scenario is this, I have the following objects: A,B,C.
A is a sprite, B is a Textmesh (not GUI) and C is a depth mask rectangle.
I wanted to take the text and scroll it over the "A" sprite, but since just scrolling the text over the sprite will result in the text going out of the sprite bounds, I wanted to create a depth mask that only while rendered on that mask the text will appear, and place that mask on the sprite.
That worked just fine, I put the sprite (A) then the text (B) and I added ZTest Greater to it's shader, and then (C) the depth mask, which is basically a rect with the following shader:
Tags { "Queue" = "Transparent" }
Lighting Off
ZTest LEqual
ZWrite On
ColorMask 0
Pass {}
This makes it so the text only appears on the rect of the mask and once its scrolled out, it vanishes, which is great.
Now for my problem, I have another object, which can appear on top of everything, and should make everything vanish as well (so I used a depth mask like stated above), but since I've already defined the text to be ZTest Greater, when that object goes over, everything disappears correctly except for the text.
My question is as follows, is there a way to differentiate between the two masks, so that the text will appear on one (passing the Ztest), but disappear from the other(failing the Ztest?).
Attaching a screenshot depicting my problem, as you can see, the red masks are showing only part of the text (which is good) but the blue mask which needs to be the end of the screen is not working on the text because the text is ZTest greater which is needed for the red mask.
So what I actually need is a way for the blue mask to cover the text but the red mask reveal it.
Any ideas if you can assign specific objects so that they will act differently with each other object, with regards to the shaders' tests? (or a similar solution)

How to achieve variable distortion along height on single 2D Sprites

I'm trying to achieve an effect on single 2D sprites that is similar to those used on animes when characters are moving fast.
My start point was using the Tilling and Offset node on URP shader graphs to distort the sprite, i could change the tilling based on variables such as time but that didn't achieve the desired effect, the main problem with that node is that it distorts the whole sprite on the same amount, while the desired effect would be a distortion that varies along the height of the sprite.
Anyone got any insights on this?
Here's my reference point,
base sprite:
distorted (i would like a more detailed - less distorted effect but i hope you get the idea):
Edit 1: My current progress

SpriteKit sprite position inside node tree

Currently working on a simple 2D game, where I have player character that is split into multiple sprites (head, torso, legs, arms,...).
I have absolute coordinates right in Aseprite (if I take individual sprite and position them I get correct coordinates).
When I put everything into swift and use negative y instead of positive everything gets totally weird.
For example in Aseprite I have coordinates as follow: head (30, 17), torso (30, 24) and legs (28, 35). Everything aligns perfectly.
In SpriteKit I extend SKNode class and put every subsprites inside with just negative number for y. So instead of going up, I draw down. It looks like that coordinates give in pixels are not correct - sprites are off by few pixels. Mostly is off y coordinate but in some cases (character rotation) also x.
How to get from those absolute upper-left coordinates to correct SpriteKit coordinates then?
Ok I figured what was wrong (several things):
your parent class can be SKNode, but children has to have set anchor point at (0,1)
when changing texture of child sprite, always make sure that sprite size is set to new size of texture. If not it will use previous texture size and resize new texture to old size. This introduces additional problems with positioning. So you have to call: child.size = child.texture!.size() (I used force unwrap because I set (new) texture one step before so I'm 100% sure it exists.
when setting new texture set anchor point again (it seems it gets reset when changing texture of child sprite).

Unity GameObject Width and Height set to zero but still displaying as normal

I have a GameObject in a scene but not in the Canvas. In this GameObject I am instantiating a couple of other GameObjects without any problems.
What I do not understand is that, it doesn't matter if I set the main GameObject's Width and Height to 0 or 100 or 1000, nothing changes, it will still instantiate and display everything in the same way.
Can someone please explain me why it still displaying everything when I set the main GameObject's width and height to 0?
Thank you.
RectTransforms only matter to Canvas objects
Width and Height are properties only available to RectTransform type Transforms and only matter for Canvas objects. For non-canvas objects you should just use a normal Transform at which point you will have a scale parameter, which setting it to zero, will make the object have zero size.