- Home /
weird values from UnityWorldSpaceLightDir
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.
 
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.
PS: Feel a bit let down by markdown on this site as I can't for the life of me get a line break.
Your answer
 
 
             Follow this Question
Related Questions
Porting from ShaderToy(GLSL) to shaderlab(HLSL/CG) unity not giving me the desired result. 2 Answers
How can I add Color property To This Shader 1 Answer
How to get red underlines for bad syntax and code suggestions for hlsl code in Unity? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                