ArmorPowerUp.azsl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #pragma once
  2. #include <viewsrg_all.srgi>
  3. #include <Atom/Features/PBR/DefaultObjectSrg.azsli>
  4. #define UNIFIED_FORWARD_OUTPUT
  5. #include <Atom/Features/PBR/ForwardPassOutput.azsli>
  6. #include <Atom/Features/SrgSemantics.azsli>
  7. #include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
  8. #include <Atom/Features/PBR/ForwardPassSrg.azsli>
  9. ShaderResourceGroup MatSRG : SRG_PerMaterial
  10. {
  11. float3 m_Color;
  12. float m_Intensity;
  13. Texture2D m_patternMap;
  14. Texture2D m_noisePerline1;
  15. Texture2D m_HexagonalGradiantMap;
  16. Texture2D m_maskMap;
  17. float m_Slider;
  18. float m_power;
  19. float m_offset;
  20. Sampler m_sampler
  21. {
  22. AddressU = Wrap;
  23. AddressV = Wrap;
  24. MinFilter = Linear;
  25. MagFilter = Linear;
  26. MipFilter = Linear;
  27. MaxAnisotropy = 16;
  28. };
  29. }
  30. struct v2f
  31. {
  32. float4 vertex : SV_POSITION;
  33. float2 uv : TEXCOORD0;
  34. float4 vertexObjPos : TEXCOORD1;
  35. float2 screenPos : TEXCOORD2;
  36. };
  37. struct VertexInput
  38. {
  39. float3 m_position : POSITION;
  40. float3 m_normal : NORMAL;
  41. float2 m_uv : UV0;
  42. };
  43. struct VertexShaderOutput
  44. {
  45. float4 m_position : SV_Position;
  46. float3 m_normal : NORMAL;
  47. float2 m_uv : UV0;
  48. float3 m_worldPosition : UV1;
  49. float3 m_localSpacePosition : UV2;
  50. float4 m_clipPosition : UV4;
  51. //float3 m_positionVS : UV4;
  52. };
  53. VertexShaderOutput MainVS(VertexInput IN)
  54. {
  55. VertexShaderOutput OUT;
  56. OUT.m_worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1)).xyz;
  57. OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPosition, 1.0));
  58. //OUT.m_positionWS = mul(ObjectSrg::GetWorldMatrix(), float4(OUT.m_worldPosition, 1)).xyz;
  59. //OUT.m_positionVS = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPosition, 1.0)).xyz;
  60. OUT.m_normal = normalize(mul(ObjectSrg::GetWorldMatrixInverseTranspose(), IN.m_normal));
  61. OUT.m_uv = IN.m_uv;
  62. OUT.m_localSpacePosition = IN.m_position;
  63. OUT.m_clipPosition = OUT.m_position;
  64. return OUT;
  65. }
  66. struct PixelOutput
  67. {
  68. float4 m_color : SV_Target0;
  69. };
  70. float GetLinearDepth(float depth)
  71. {
  72. const float zFar = ViewSrg::GetFarZ();
  73. const float zRange = ViewSrg::GetFarZMinusNearZ();
  74. const float zFarTimesNear = ViewSrg::GetFarZTimesNearZ();
  75. return (-zFarTimesNear) / (depth * zRange - zFar);
  76. }
  77. ForwardPassOutput MainPS(VertexShaderOutput IN)
  78. {
  79. ForwardPassOutput OUT;
  80. //float fragmentEyeDepth = -IN.m_positionVS.z;
  81. float3 Color = MatSRG::m_Color.rgb;
  82. float Intensity = MatSRG::m_Intensity;
  83. float2 uv = IN.m_uv;
  84. float3 viewPos = ViewSrg::m_worldPosition;
  85. float3 worldPos = IN.m_worldPosition;
  86. float3 locPos = IN.m_localSpacePosition;
  87. float3 viewDir = normalize(worldPos - viewPos);
  88. float3 normal = IN.m_normal;
  89. float fresnel = pow(1 - saturate(abs(dot(normal, viewDir))), MatSRG::m_power)* 0.75;
  90. float4 perlinnoise1 = MatSRG::m_noisePerline1.Sample(MatSRG::m_sampler, uv * float2(3, 2) + (SceneSrg::m_time * float2(-0.025, -0.05)));
  91. float4 hexagonGradiant = MatSRG::m_HexagonalGradiantMap.Sample(MatSRG::m_sampler, uv * float2(3, 2) + (SceneSrg::m_time * float2(-0.025, -0.05)));
  92. float4 maskTexture = step(0.69, MatSRG::m_maskMap.Sample(MatSRG::m_sampler, uv * float2(1, 2)+ (SceneSrg::m_time * float2(0.1, 0.25))));
  93. float4 patternTexture = MatSRG::m_patternMap.Sample(MatSRG::m_sampler, uv * float2(3, 2) + (SceneSrg::m_time * float2(-0.025, -0.05)));
  94. /*
  95. float projectionSign = 1f;
  96. float4 o = m_position * 0.5f;
  97. o.xy = float2(o.x, o.y * projectionSign) + o.w;
  98. o.zw = pos.zw;
  99. float4 ComputeScreenPos = o;
  100. */
  101. float InRemap = MatSRG::m_Slider;
  102. float2 InMinMax = float2(0, 1);
  103. float2 OutMinMax = float2(0.8, -0.7);
  104. float sliderRemap = OutMinMax.x + (InRemap - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x);
  105. float2 gradiantandNoise = hexagonGradiant * clamp(perlinnoise1, 0.15, 1);
  106. float2 uvNoise = lerp(1-uv, gradiantandNoise, 0.25) + float2(0, sliderRemap);
  107. float2 offset2 = float2(uvNoise * float2(1, 0.5) + float2(0, sliderRemap) + MatSRG::m_Slider+ 0.01);
  108. float2 offset3 = float2(uvNoise * float2(1, 2) + float2(0, sliderRemap)) + MatSRG::m_Slider - float2(0, 1.76);
  109. float comparaisonGreater = clamp(offset2.y > 0.99 ? 0 : offset2.y, 0, 1);
  110. float comparaisonGreater2 = clamp(comparaisonGreater > 0.01 ? offset3.y : comparaisonGreater, 0, 1);
  111. float gradient = 0.73 * (saturate(comparaisonGreater2));
  112. float2 OutMinMax2 = float2(0.41, 1.4);
  113. float sliderRemap2 = OutMinMax2.x + (InRemap - InMinMax.x) * (OutMinMax2.y - OutMinMax2.x) / (InMinMax.y - InMinMax.x);
  114. float2 d = abs(uvNoise * float2(1, 1.05) - sliderRemap2) - float2(3, 0.02);
  115. d = 1 - d / fwidth(d);
  116. float rect = saturate(min(d.x, d.y));
  117. float alpha = comparaisonGreater;
  118. float alpha2 = alpha > 0 ? 1 : alpha;
  119. // Get scene and fragment depths:
  120. float3 clipPos = IN.m_clipPosition / IN.m_clipPosition.w;
  121. float2 screenUV = clipPos * 0.5f + 0.5f;
  122. screenUV.y = 1.0f - screenUV.y;
  123. const float fragDepth = GetLinearDepth(clipPos.z);
  124. const float sceneDepth = PassSrg::m_linearDepthTexture.Sample(PassSrg::LinearSampler, screenUV).r;
  125. //float DepthOffset = sceneDepth - fragDepth;
  126. //float DepthOffset = 1-(sceneDepth-(fragDepth - MatSRG::m_offset));
  127. float DepthOffset =clamp(1- smoothstep((sceneDepth - fragDepth), 1, 0), 0., 0.4);
  128. DepthOffset = smoothstep(0.1,0.0,abs(sceneDepth-fragDepth));
  129. float3 lineBorder = rect + ((maskTexture.xyz * patternTexture.xyz + patternTexture.xyz * 0.4) + (clamp(gradient + alpha2 * (fresnel + DepthOffset), 0., 0.4) * Color * Intensity));
  130. //OUT.m_color.rgb = float3(1., 1., 1.) * (DepthOffset);
  131. //OUT.m_color.a = 1.0f;
  132. OUT.m_color.rgb = lineBorder;
  133. OUT.m_color.a = clamp(gradient + alpha2 * (fresnel + DepthOffset), 0., 0.4);
  134. return OUT;
  135. }