GBufferOutput.bslinc 923 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "$ENGINE$\SurfaceData.bslinc"
  2. #ifndef WRITE_VELOCITY
  3. #define WRITE_VELOCITY 0
  4. #endif
  5. mixin GBufferOutput
  6. {
  7. mixin SurfaceData;
  8. code
  9. {
  10. struct GBufferData
  11. {
  12. float4 albedo : SV_Target1;
  13. float4 normal : SV_Target2;
  14. float2 metalRoughness : SV_Target3;
  15. #if WRITE_VELOCITY
  16. float2 velocity : SV_Target4;
  17. float id : SV_Target5;
  18. #else
  19. float id : SV_Target4;
  20. #endif
  21. };
  22. GBufferData encodeGBuffer(SurfaceData input)
  23. {
  24. GBufferData output;
  25. output.albedo = input.albedo;
  26. output.normal.xyz = float3(input.worldNormal.xyz * 0.5f + 0.5f);
  27. output.normal.w = 1.0f; // Marks that some deferred data was written
  28. output.metalRoughness.x = input.roughness;
  29. output.metalRoughness.y = input.metalness;
  30. #if WRITE_VELOCITY
  31. output.velocity = encodeVelocity16SNORM(input.velocity);
  32. #endif
  33. output.id = input.mask / 256.0f;
  34. return output;
  35. }
  36. };
  37. };