Transparent.bsl 1.8 KB

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