- Home /
Find angle face under mouse pointer.
Hello, I state that I am a c# programmer, but bad shaders programmer :)
I have a projector component and I need to find the angle projected texture to exclude the projecting on vertical faces.
My projector is under the mouse pointer and when is over an horizontal faces is ok.
I would like to prevent the projector "work" also on vertical faces to avoid this bad effect.
If possible I would do it in the shader code to avoid the vertical projected image even if the cursor is located on the corners of an horizontal face and a part "goes out" on vertical face.
In c# i find this solution:
if (Physics.Raycast(MouseRay,out hitInfo)){
if(hitInfo.normal.y>0) draw...
else
not draw...
....
But only it works on curved surfaces and not, for example, on the face cubes.
How can I do?
Answer by Rodolphito · May 11, 2015 at 09:19 AM
I would recommend having the cancel texture on a plane mesh, and have a script cast a vertical ray downwards every time the mouse moves and position the mesh there, probably with a small offset to prevent z fighting. The benefit of doing it this way is that the symbol is not cut, it is rendered entirely.
So, use a unity plane primitive with your texture and mouse tracking script, and then have it cast a downwards vertical ray to find the correct altitude to render the mesh.
Thanks for the answer but I would like to have the texture projected even on strong angles. The problem is only in the vertical faces.
I would like to get something like this:
if (angle> 85) not draw
and possibly by pixels :)
How about separating the object into 2 objects, in different layers (or with tags) which is a layer of projectable things and another layer of unprojectable things. This would be useless if you have dynamic objects that you want to be able to project on based on angle though. It is also a kind of time consu$$anonymous$$g method.
Alternatively you can render the sprite in screenspace, sampling the normal of the place under your mouse and using it to align the sprite, but that is not really what you asked for.
Solved, and per-pixel :)
With this simple code:
if(input.norm.y<=0)
textureColor=float4(0.0, 0.0, 0.0, 0.0);
Hi there. I am having the same issue outlined here.
Would you be able to maybe show how you implemented your solution? i.e. maybe the whole shader code or a description.
$$anonymous$$any thanks