Spine-SkeletonLit-ForwardPass-LW.hlsl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef SKELETONLIT_FORWARD_PASS_LW_INCLUDED
  2. #define SKELETONLIT_FORWARD_PASS_LW_INCLUDED
  3. struct appdata {
  4. float3 pos : POSITION;
  5. float3 normal : NORMAL;
  6. half4 color : COLOR;
  7. float2 uv0 : TEXCOORD0;
  8. UNITY_VERTEX_INPUT_INSTANCE_ID
  9. };
  10. struct VertexOutput {
  11. half4 color : COLOR0;
  12. float2 uv0 : TEXCOORD0;
  13. float4 pos : SV_POSITION;
  14. UNITY_VERTEX_OUTPUT_STEREO
  15. };
  16. half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS) {
  17. Light mainLight = GetMainLight();
  18. half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
  19. half3 diffuseLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
  20. // Note: we don't add any lighting in the fragment shader, thus we include both variants below
  21. #if defined(_ADDITIONAL_LIGHTS) || defined(_ADDITIONAL_LIGHTS_VERTEX)
  22. for (int i = 0; i < GetAdditionalLightsCount(); ++i)
  23. {
  24. Light light = GetAdditionalLight(i, positionWS);
  25. half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
  26. diffuseLightColor += LightingLambert(attenuatedLightColor, light.direction, normalWS);
  27. }
  28. #endif
  29. return diffuseLightColor;
  30. }
  31. VertexOutput vert(appdata v) {
  32. VertexOutput o;
  33. UNITY_SETUP_INSTANCE_ID(v);
  34. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  35. half4 color = v.color;
  36. float3 positionWS = TransformObjectToWorld(v.pos);
  37. half3 fixedNormal = half3(0, 0, -1);
  38. half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
  39. color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
  40. // Note: ambient light is also handled via SH.
  41. half3 vertexSH;
  42. OUTPUT_SH(normalWS.xyz, vertexSH);
  43. color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS);
  44. o.color = color;
  45. o.uv0 = v.uv0;
  46. o.pos = TransformWorldToHClip(positionWS);
  47. return o;
  48. }
  49. sampler2D _MainTex;
  50. half4 frag(VertexOutput i) : SV_Target{
  51. half4 tex = tex2D(_MainTex, i.uv0);
  52. half4 col;
  53. #if defined(_STRAIGHT_ALPHA_INPUT)
  54. col.rgb = tex.rgb * i.color.rgb * tex.a;
  55. #else
  56. col.rgb = tex.rgb * i.color.rgb;
  57. #endif
  58. col.a = tex.a * i.color.a;
  59. return col;
  60. }
  61. #endif