MobileForwardPassVertexAndPixel.azsli 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Atom/Features/Pipeline/Forward/ForwardPassOutput.azsli>
  10. #include <Atom/Features/PostProcessing/Tonemap.azsli>
  11. #include <Atom/Features/ColorManagement/TransformColor.azsli>
  12. // --- Vertex Shader ---
  13. VsOutput VertexShader(VsInput IN, uint instanceId : SV_InstanceID)
  14. {
  15. VsSystemValues SV;
  16. SV.m_instanceId = instanceId;
  17. VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
  18. return OUT;
  19. }
  20. // --- Pixel Shader ---
  21. #if FORCE_EARLY_DEPTH_STENCIL
  22. [earlydepthstencil]
  23. #endif
  24. ForwardPassOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
  25. {
  26. float3 views[MAX_SHADING_VIEWS];
  27. views[0] = ViewSrg::m_worldPosition.xyz; // Assume one view for forward pass for now
  28. // ------- Geometry -> Surface -> Lighting -------
  29. PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
  30. Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
  31. LightingData lightingData = EvaluateLighting(surface, IN.position, views);
  32. // ------- Output -------
  33. ForwardPassOutput OUT;
  34. real3 color = lightingData.diffuseLighting.rgb + lightingData.emissiveLighting.rgb;
  35. for(uint i = 0; i < GET_SHADING_VIEW_COUNT; ++i)
  36. {
  37. color += lightingData.specularLighting[i];
  38. }
  39. #if ENABLE_MERGE_FILMIC_TONEMAP
  40. // Apply manual exposure compensation
  41. color = ApplyManualExposure(color, real(ViewSrg::GetExposureValueCompensation()));
  42. //Convert to linearsrg space as we are in acescg space and we will not be applying aces tonemap
  43. color = AcesCg_To_LinearSrgb(color);
  44. // We could add other forms of tonemapping in future via shader options.
  45. color = TonemapFilmic(color);
  46. #endif
  47. OUT.m_color.rgb = color;
  48. OUT.m_color.a = 1.0;
  49. #if OUTPUT_DEPTH
  50. OUT.m_depth = IN.position.z;
  51. #endif
  52. return OUT;
  53. }