Diffuse.bsl 2.5 KB

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