Quantcast
Channel: Questions in topic: "hlsl"
Viewing all articles
Browse latest Browse all 206

weird values from UnityWorldSpaceLightDir

$
0
0
Hey, ran into what I guess to be an issue with UnityWorldSpaceLightDir. When I pass the vector into a fragment color I get this unexpected popping. https://imgur.com/vG3t3I3 ![alt text][1] Seeing the color should represent the direction of the light source in world space. I would assume it to remain one color as long I don't change the rotation of the light (directional light in this case). Shader used: Shader "Debug/LightDirection" { Properties { [KeywordEnum(World, Object)] _Space("Space", Float) = 0 [Toggle] _Abs("Abs()", Float) = 0 } SubShader { Tags{ "RenderType" = "Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; float4 color : COLOR; }; int _Space; bool _Abs; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); float3 rgb; switch (_Space) { case 0: { rgb = UnityWorldSpaceLightDir(v.vertex); } break; case 1: { rgb = ObjSpaceLightDir(v.vertex); } break; default: {} break; } if (_Abs) { rgb = abs(rgb); } o.color = float4(rgb, 1.0f); return o; } fixed4 frag(v2f i) : SV_Target { return fixed4(i.color); } ENDCG } } } Ultimately what I'm trying to achieve is this; https://realtimevfx.com/t/smoke-lighting-and-texture-re-usability-in-skull-bones/5339 But struggling in finding a solid way to get the lights direction relative to the normal of the particles. In the article it is said Light direction should be in tangent space to work. [1]: https://imgur.com/vG3t3I3 PS: Feel a bit let down by markdown on this site as I can't for the life of me get a line break.

Viewing all articles
Browse latest Browse all 206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>