|
i have this shader that is suposed to make objects transparent if they are to close to the camera and it works perfectly when the object is at 0,0,0 but for example when the object is at 0,0,40 i get full fade at around 0,0,20 (for this example the variables FadeStartDistance = 0 and FadeDistance = 10) i also have a problem that the range of the fade is half, ea if i have FadeDistance = 10 then the actual lenght of the fade is 5 meters. i currectly get around this problem by multiplaying the distance by 0.5 but that doesnt seem like the right way and im guessing that the problems are related EDIT changed to using the correct matrix to get the worldspace and now it works for normal mashes but the problem now is that when i use it for a particle shader (im using the new 3.5 version) it again only works when its at 0,0,0 if i move it to 0,0,20 it doesnt work at all and if its at 0,0,10 i can see some particles no matter where the camera is EDIT2 i have preformed some more testing and it seems like the Object2World matrix always is the identity matrix for particle system is there some other matrix i can/should use instead? Shader "Custom/DistanceFade" { Properties { _MainTex ("Main Tex", 2D) = "white" {} _FadeStartDistance ("Fade Start Distance", Float) = 0 _FadeDistance ("Fade Distance", Float) = 0 _MinFade ("Minimum Fade", Float) = 0 } SubShader { Pass { //Blend SrcAlpha One //Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" }
(comments are locked)
|
|
I'm not an expert but are you certain to use the right matrix conversion? If I'm not mistaking, UNITY_MATRIX_MVP transform the coordinates into screen position, whereas you are checking against world camera position. Can't this work better with UNITY_MATRIX_MV? Of course at the end, you will need to transform it again to screen position, with: See here for a definition of the different matrices. updated the question
Apr 23 '12 at 04:14 PM
imapler
(comments are locked)
|
