2
0

ParticlesLit.bsl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #define LIGHTING_DATA
  2. #include "$ENGINE$\ParticleVertex.bslinc"
  3. #include "$ENGINE$\ForwardLighting.bslinc"
  4. options
  5. {
  6. transparent = true;
  7. };
  8. shader Surface
  9. {
  10. mixin ParticleVertex;
  11. mixin ForwardLighting;
  12. blend
  13. {
  14. target
  15. {
  16. enabled = true;
  17. color = { srcA, srcIA, add };
  18. };
  19. };
  20. depth
  21. {
  22. write = false;
  23. };
  24. code
  25. {
  26. [alias(gAlbedoTex)]
  27. SamplerState gAlbedoSamp;
  28. [alias(gNormalTex)]
  29. SamplerState gNormalSamp;
  30. [alias(gRoughnessTex)]
  31. SamplerState gRoughnessSamp;
  32. [alias(gMetalnessTex)]
  33. SamplerState gMetalnessSamp;
  34. [alias(gEmissiveMaskTex)]
  35. SamplerState gEmissiveMaskSamp;
  36. Texture2D gAlbedoTex = white;
  37. Texture2D gNormalTex = normal;
  38. Texture2D gRoughnessTex = white;
  39. Texture2D gMetalnessTex = black;
  40. Texture2D gEmissiveMaskTex = black;
  41. cbuffer MaterialParams
  42. {
  43. float gOpacity = 1.0f;
  44. [color][hdr]
  45. float3 gEmissiveColor = { 1.0f, 1.0f, 1.0f };
  46. float2 gUVOffset = { 0.0f, 0.0f };
  47. float2 gUVTile = { 1.0f, 1.0f };
  48. }
  49. float4 fsmain(in VStoFS input) : SV_Target0
  50. {
  51. float2 uv = input.uv0 * gUVTile + gUVOffset;
  52. float3 normal = normalize(gNormalTex.Sample(gNormalSamp, uv).xyz * 2.0f - float3(1, 1, 1));
  53. float3 worldNormal = calcWorldNormal(input, normal);
  54. SurfaceData surfaceData;
  55. surfaceData.albedo = gAlbedoTex.Sample(gAlbedoSamp, uv) * input.color;
  56. surfaceData.worldNormal.xyz = worldNormal;
  57. surfaceData.worldNormal.w = 1.0f;
  58. surfaceData.roughness = gRoughnessTex.Sample(gRoughnessSamp, uv).x;
  59. surfaceData.metalness = gMetalnessTex.Sample(gMetalnessSamp, uv).x;
  60. float3 lighting = calcLighting(input.worldPosition.xyz, input.position, uv, surfaceData);
  61. float3 emissive = gEmissiveColor * gEmissiveMaskTex.Sample(gEmissiveMaskSamp, uv).x;
  62. return float4(emissive + lighting, surfaceData.albedo.a * gOpacity);
  63. }
  64. };
  65. };