diff --git a/Source/Engine/Renderer/EyeAdaptationPass.cpp b/Source/Engine/Renderer/EyeAdaptationPass.cpp index b539cb212..739316556 100644 --- a/Source/Engine/Renderer/EyeAdaptationPass.cpp +++ b/Source/Engine/Renderer/EyeAdaptationPass.cpp @@ -263,6 +263,7 @@ bool EyeAdaptationPass::setupResources() // Create pipeline stages GPUPipelineState::Description psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle; + psDesc.BlendMode.RenderTargetWriteMask = BlendingMode::ColorWrite::Red; if (!_psLuminanceMap->IsValid()) { psDesc.PS = shader->GetPS("PS_LuminanceMap"); diff --git a/Source/Shaders/ColorGrading.shader b/Source/Shaders/ColorGrading.shader index 7c945e2ef..3d80b3e33 100644 --- a/Source/Shaders/ColorGrading.shader +++ b/Source/Shaders/ColorGrading.shader @@ -353,7 +353,7 @@ float4 PS_Lut2D(Quad_VS2PS input) : SV_Target return CombineLUTs(input.TexCoord, 0); } -META_PS(true, FEATURE_LEVEL_ES2) +META_PS(true, FEATURE_LEVEL_SM4) META_PERMUTATION_1(TONE_MAPPING_MODE_NONE=1) META_PERMUTATION_1(TONE_MAPPING_MODE_NEUTRAL=1) META_PERMUTATION_1(TONE_MAPPING_MODE_ACES=1) diff --git a/Source/Shaders/Common.hlsl b/Source/Shaders/Common.hlsl index 5249e38fb..c15efcd79 100644 --- a/Source/Shaders/Common.hlsl +++ b/Source/Shaders/Common.hlsl @@ -54,7 +54,7 @@ #define SHADING_MODEL_FOLIAGE 3 // Detect feature level support -#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5 +#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5 || defined(WGSL) #define CAN_USE_GATHER 1 #else #define CAN_USE_GATHER 0 @@ -74,6 +74,13 @@ #else #define CAN_USE_TESSELLATION 0 #endif +#if defined(WGSL) +// Wrap not supported read-only Buffer binded as shader resource into StructuredBuffer to be used as storage on WebGPU +#define CAN_USE_TYPED_BUFFER_LOADS 0 +#define Buffer StructuredBuffer +#else +#define CAN_USE_TYPED_BUFFER_LOADS 1 +#endif // Compiler attributes diff --git a/Source/Shaders/EyeAdaptation.shader b/Source/Shaders/EyeAdaptation.shader index 20bf1f102..1989af840 100644 --- a/Source/Shaders/EyeAdaptation.shader +++ b/Source/Shaders/EyeAdaptation.shader @@ -21,9 +21,9 @@ float Dummy1; META_CB_END -float AdaptLuminance(float currentLum, Texture2D previousLuminance) +float AdaptLuminance(float currentLum, Texture2D previousLuminance) { - float previousLum = previousLuminance.Load(int3(0, 0, 0)).x; + float previousLum = previousLuminance.Load(int3(0, 0, 0)); // Adapt the luminance using Pattanaik's technique float delta = currentLum - previousLum; @@ -40,7 +40,7 @@ float AdaptLuminance(float currentLum, Texture2D previousLuminance) META_PS(true, FEATURE_LEVEL_ES2) float4 PS_Manual(Quad_VS2PS input) : SV_Target { - return PreExposure.xxxx; + return PreExposure.xxxx; } #endif @@ -51,7 +51,7 @@ Texture2D SceneColor : register(t0); // Creates the luminance map for the scene META_PS(true, FEATURE_LEVEL_ES2) -float4 PS_LuminanceMap(Quad_VS2PS input) : SV_Target +float PS_LuminanceMap(Quad_VS2PS input) : SV_Target { // Sample the input float3 color = SceneColor.Sample(SamplerLinearClamp, input.TexCoord).rgb; @@ -60,35 +60,35 @@ float4 PS_LuminanceMap(Quad_VS2PS input) : SV_Target float luminance = Luminance(color); // Clamp to avoid artifacts from exceeding fp16 - return clamp(luminance, 1e-4, 60000.0f).xxxx; + return clamp(luminance, 1e-4, 60000.0f); } #endif #ifdef _PS_BlendLuminance -Texture2D CurrentLuminance : register(t0); -Texture2D PreviousLuminance : register(t1); +Texture2D CurrentLuminance : register(t0); +Texture2D PreviousLuminance : register(t1); // Slowly adjusts the scene luminance based on the previous scene luminance META_PS(true, FEATURE_LEVEL_ES2) -float4 PS_BlendLuminance(Quad_VS2PS input) : SV_Target +float PS_BlendLuminance(Quad_VS2PS input) : SV_Target { - float currentLum = CurrentLuminance.Load(int3(0, 0, 0)).x; - return AdaptLuminance(currentLum, PreviousLuminance).xxxx; + float currentLum = CurrentLuminance.Load(int3(0, 0, 0)); + return AdaptLuminance(currentLum, PreviousLuminance); } #endif #ifdef _PS_ApplyLuminance -Texture2D AverageLuminance : register(t0); +Texture2D AverageLuminance : register(t0); // Applies the luminance to the scene color (using multiply blending mode) META_PS(true, FEATURE_LEVEL_ES2) float4 PS_ApplyLuminance(Quad_VS2PS input) : SV_Target { - float averageLuminance = AverageLuminance.Load(int3(0, 0, 0)).x; + float averageLuminance = AverageLuminance.Load(int3(0, 0, 0)); float exposure = 1.0f / averageLuminance; return float4((PreExposure * exposure).xxx, 1); } @@ -101,7 +101,7 @@ float4 PS_ApplyLuminance(Quad_VS2PS input) : SV_Target #define HISTOGRAM_SIZE 64 StructuredBuffer HistogramBuffer : register(t0); -Texture2D PreviousLuminance : register(t1); +Texture2D PreviousLuminance : register(t1); float ComputeLuminanceFromHistogramPosition(float histogramPosition) { @@ -148,10 +148,10 @@ float GetAverageLuminance() // Samples evaluates the scene color luminance based on the histogram META_PS(true, FEATURE_LEVEL_ES2) -float4 PS_Histogram(Quad_VS2PS input) : SV_Target +float PS_Histogram(Quad_VS2PS input) : SV_Target { float currentLum = GetAverageLuminance(); - return AdaptLuminance(currentLum, PreviousLuminance).xxxx; + return AdaptLuminance(currentLum, PreviousLuminance); } #endif diff --git a/Source/Shaders/Fog.shader b/Source/Shaders/Fog.shader index 1eae65d72..b5bd7c66d 100644 --- a/Source/Shaders/Fog.shader +++ b/Source/Shaders/Fog.shader @@ -10,6 +10,7 @@ // Disable Volumetric Fog if is not supported #if VOLUMETRIC_FOG && !CAN_USE_COMPUTE_SHADER +#undef VOLUMETRIC_FOG #define VOLUMETRIC_FOG 0 #endif diff --git a/Source/Shaders/MaterialCommon.hlsl b/Source/Shaders/MaterialCommon.hlsl index 2f9b2dde5..f3f705f52 100644 --- a/Source/Shaders/MaterialCommon.hlsl +++ b/Source/Shaders/MaterialCommon.hlsl @@ -97,14 +97,14 @@ ObjectData LoadObject(Buffer objectsBuffer, uint objectIndex) // This must match ShaderObjectData::Store objectIndex *= 8; ObjectData object = (ObjectData)0; - float4 vector0 = objectsBuffer.Load(objectIndex + 0); - float4 vector1 = objectsBuffer.Load(objectIndex + 1); - float4 vector2 = objectsBuffer.Load(objectIndex + 2); - float4 vector3 = objectsBuffer.Load(objectIndex + 3); - float4 vector4 = objectsBuffer.Load(objectIndex + 4); - float4 vector5 = objectsBuffer.Load(objectIndex + 5); - float4 vector6 = objectsBuffer.Load(objectIndex + 6); - float4 vector7 = objectsBuffer.Load(objectIndex + 7); + float4 vector0 = objectsBuffer[objectIndex + 0]; + float4 vector1 = objectsBuffer[objectIndex + 1]; + float4 vector2 = objectsBuffer[objectIndex + 2]; + float4 vector3 = objectsBuffer[objectIndex + 3]; + float4 vector4 = objectsBuffer[objectIndex + 4]; + float4 vector5 = objectsBuffer[objectIndex + 5]; + float4 vector6 = objectsBuffer[objectIndex + 6]; + float4 vector7 = objectsBuffer[objectIndex + 7]; object.WorldMatrix[0] = float4(vector0.xyz, 0.0f); object.WorldMatrix[1] = float4(vector1.xyz, 0.0f); object.WorldMatrix[2] = float4(vector2.xyz, 0.0f);