Diffuse.bsl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "$ENGINE$\BasePass.bslinc"
  2. #include "$ENGINE$\Surface.bslinc"
  3. Parameters =
  4. {
  5. Sampler2D gAlbedoSamp : alias("gAlbedoTex");
  6. Sampler2D gNormalSamp : alias("gNormalTex");
  7. Sampler2D gRoughnessSamp : alias("gRoughnessTex");
  8. Sampler2D gMetalnessSamp : alias("gMetalnessTex");
  9. Texture2D gAlbedoTex;
  10. Texture2D gNormalTex = "normal";
  11. Texture2D gRoughnessTex = "white";
  12. Texture2D gMetalnessTex = "black";
  13. };
  14. Technique : base("Surface") =
  15. {
  16. Language = "HLSL11";
  17. Pass =
  18. {
  19. Fragment =
  20. {
  21. SamplerState gAlbedoSamp : register(s0);
  22. SamplerState gNormalSamp : register(s1);
  23. SamplerState gRoughnessSamp : register(s2);
  24. SamplerState gMetalnessSamp : register(s3);
  25. Texture2D gAlbedoTex : register(t0);
  26. Texture2D gNormalTex : register(t1);
  27. Texture2D gRoughnessTex : register(t2);
  28. Texture2D gMetalnessTex : register(t3);
  29. void main(
  30. in VStoFS input,
  31. out float4 OutGBufferA : SV_Target0,
  32. out float4 OutGBufferB : SV_Target1,
  33. out float2 OutGBufferC : SV_Target2)
  34. {
  35. float3 normal = normalize(gNormalTex.Sample(gNormalSamp, input.uv0) * 2.0f - float3(1, 1, 1));
  36. float3 worldNormal = calcWorldNormal(input, normal);
  37. SurfaceData surfaceData;
  38. surfaceData.albedo = gAlbedoTex.Sample(gAlbedoSamp, input.uv0);
  39. surfaceData.worldNormal.xyz = worldNormal;
  40. surfaceData.roughness = gRoughnessTex.Sample(gRoughnessSamp, input.uv0).x;
  41. surfaceData.metalness = gMetalnessTex.Sample(gMetalnessSamp, input.uv0).x;
  42. encodeGBuffer(surfaceData, OutGBufferA, OutGBufferB, OutGBufferC);
  43. }
  44. };
  45. };
  46. };
  47. Technique : base("Surface") =
  48. {
  49. Language = "GLSL";
  50. Pass =
  51. {
  52. Fragment =
  53. {
  54. layout(location = 0) in vec2 uv0;
  55. layout(location = 2) in vec3 tangentToWorldZ;
  56. layout(location = 3) in vec4 tangentToWorldX;
  57. layout(binding = 4) uniform sampler2D gAlbedoTex;
  58. layout(binding = 5) uniform sampler2D gNormalTex;
  59. layout(binding = 6) uniform sampler2D gRoughnessTex;
  60. layout(binding = 7) uniform sampler2D gMetalnessTex;
  61. layout(location = 0) out vec4 fragColor[3];
  62. void main()
  63. {
  64. vec3 normal = normalize(texture(gNormalTex, uv0).xyz * 2.0f - vec3(1, 1, 1));
  65. vec3 worldNormal = calcWorldNormal(tangentToWorldZ, tangentToWorldX, normal);
  66. SurfaceData surfaceData;
  67. surfaceData.albedo = texture(gAlbedoTex, uv0);
  68. surfaceData.worldNormal.xyz = worldNormal;
  69. surfaceData.roughness = texture(gRoughnessTex, uv0).x;
  70. surfaceData.metalness = texture(gMetalnessTex, uv0).x;
  71. encodeGBuffer(surfaceData, fragColor[0], fragColor[1], fragColor[2]);
  72. }
  73. };
  74. };
  75. };