- Home /
How to resize a quad to fit the dimensions of a sprite/.png ?
I'm building a 3D fps game, basically like the first doom. The thing is I want my "sprites" to cast shadow. So I have to put them in quads (I believe there's no other way to have the sprites cast shadows).
My first question is: Is it optimized to glue two quad together to have my sprites visible on each face ?
My second question is: If I put a .png in the game's assets, and I set the texture type to "Sprite (2D and UI), I can put this sprite in the game and the x and y sizes from the original .png are kept identical in the game. But I have to put the .pngs in quads and transform these .pngs to materials: But then I can't get the size and scale to be exactly the same as in the .png. Is there a non-manual way to set the size and scale of the quad to be the same as the original .png ?
Thank you for reading
Answer by selewi · Apr 16, 2018 at 11:11 AM
First of all, I think that if you want to use a quad with a sprite, you need to know about the billboarding technique, which makes a 2D sprite rotate towards the camera position, so you cannot see the "dark side of the sprite" huh :P.
You can set the scale and the size of a sprite by scripting using the quad bounds or the sprite bounds deppending on what you want to resize. Sorry I cannot help you with code right now, if you still need help with that I'll try to cover the code for you later, but I hope this is enough help. Cheers!
That is true. I indeed figured that I need to "billboard" some sprites and I figured how to do it.
I get your idea: If I'm correct, I shall, in a script, get the size of a sprite bound to a specific quad (in which I put the script) so it transforms that quad according to the sprite's size? Unfortunately, I can't figure out how to code that. I'm still not good enough to write that in C# ><. Could you help me ? Thank you anyway for the time you spent answering.
Answer by BCook99 · Nov 23, 2020 at 08:30 PM
I recently ran into the same issue. In my project I imported the sprites png files as texture type Sprite 2D and set the pixel ratio to 1:1.
I then created a material using the sprite for the albedo and put it on a quad using a sprite shader. By setting the quad scale equal to the dimensions of the PNG file, it matched a 2D sprite display size perfectly.
In my example, the PNG file was 600x600 pixels and the quad scale was 600,600,1