Rotation shader for a sprite

Hello!

I try to make a 2d isometric game with Unity, that uses all 3 dimensions in gameplay (as well as physics). To approach that, i set all my flat sprites in 3d world and my camera to 45 degrees to the floor. Of course, all sprites became … “shorter”, because of camera rotation. To fix it, as I see it, i need to rotate all my sprites to 45 degrees, so they will allways facing at the camera - so it will be some kind of billboarding. For some physics and mechanics reasons, i cant do it in scripts, so i guessed about shader.

Normal billboard approach uses only position of billboards, but i need whole World matrix for my sprites (they are affected by physics, etc). The problem is, i can modify World matrix manually by myself in vertex shader (at least, i think, its possible), but i can’t do anything with it later in code: you need to multiply input vertex by World * View * Projection matrix to propper matrix transformations, but as i changed World matrix with a new one, i need ViewProjection or View and Projection matrices to create my own brand new MVP matrix. But Unity has no View or ViewProjection matrices, so i can’t :frowning:

Maybe there is a way to rotate object in shader or maybe my approach is whole wrong?.. Thanks!

(P.S. sorry for my english)

First scren is thats how its looks in the editor. Second - the game itself. Yes, i know it looks like Diablo, its kinda small funny parody :slight_smile:


First ,MVP can be produced manual in scripts by access special gameobject trnasform property
and second,you can rotate vertex by a certain rotation matrix before u transform it by MVP,in the Model Space
last ,i think there is a view projection there, on the camera

Lulucifer, thanks for responding, but as i said: “For some physics and mechanics reasons, i cant do it in scripts, so i guessed about shader.” If i understand you right. Or you maybe you talking about some property, that is affected MVP matrix, but not transform itself?.. So rotation will appear only for visual part of the object and not object itself?..

of course,you cant modify the mesh collider by shader operation,shader will only affect what you see on the screen,but the physics engine dont give a look at gpu’s frame buffer ,the mesh collider is a independent compoenent,it does not share any data with render,it has its own collection of geo data

Yes, i understand that :slight_smile: Oh, i reread your first post and now i totally get it!

Your second approach about modifying local vertex by multiplying it by precalculated Rotation matrix looks like the exact thing, that i need, thanks! It’s kinda obvious, so shame on me, that i didnt get it by myself :slight_smile: Thanks again!