From f64a77f68923393635f391a36129279ad1f71120 Mon Sep 17 00:00:00 2001 From: Ilya Perapechka Date: Sun, 19 Mar 2023 13:49:08 +0200 Subject: [PATCH] ISMap, ISNoise, ISSAOMinify, ISWorldMap shaders. --- IngameEditor/Core/ShaderCache.cpp | 274 ++++++++++++------------------ Shaders/ISMap.hlsl | 57 +++++++ Shaders/ISNoise.hlsl | 105 ++++++++++++ Shaders/ISSAOMinify.hlsl | 67 ++++++++ Shaders/ISWorldMap.hlsl | 63 +++++++ 5 files changed, 398 insertions(+), 168 deletions(-) create mode 100644 Shaders/ISMap.hlsl create mode 100644 Shaders/ISNoise.hlsl create mode 100644 Shaders/ISSAOMinify.hlsl create mode 100644 Shaders/ISWorldMap.hlsl diff --git a/IngameEditor/Core/ShaderCache.cpp b/IngameEditor/Core/ShaderCache.cpp index 2660bd9..dfc0c79 100644 --- a/IngameEditor/Core/ShaderCache.cpp +++ b/IngameEditor/Core/ShaderCache.cpp @@ -811,6 +811,26 @@ namespace SIE defines[0] = { "WADING_HEIGHTMAP", nullptr }; ++defines; } + else if (descEnum == ISWorldMapNoSkyBlur) + { + defines[0] = { "NO_SKY_BLUR", nullptr }; + ++defines; + } + else if (descEnum == ISMinifyContrast) + { + defines[0] = { "CONTRAST", nullptr }; + ++defines; + } + else if (descEnum == ISNoiseNormalmap) + { + defines[0] = { "NORMALMAP", nullptr }; + ++defines; + } + else if (descEnum == ISNoiseScrollAndBlend) + { + defines[0] = { "SCROLL_AND_BLEND", nullptr }; + ++defines; + } defines[0] = { nullptr, nullptr }; } @@ -1591,202 +1611,120 @@ namespace SIE static uint32_t GetImagespaceShaderDescriptor(const RE::BSImagespaceShader& imagespaceShader) { + using enum RE::ImageSpaceEffectManager::EffectType; + static const std::unordered_map descriptors{ - { "BSImagespaceShaderISBlur", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur) }, - { "BSImagespaceShaderBlur3", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur3) }, - { "BSImagespaceShaderBlur5", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur5) }, - { "BSImagespaceShaderBlur7", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur7) }, - { "BSImagespaceShaderBlur9", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur9) }, - { "BSImagespaceShaderBlur11", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur11) }, - { "BSImagespaceShaderBlur13", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur13) }, - { "BSImagespaceShaderBlur15", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBlur15) }, - { "BSImagespaceShaderBrightPassBlur3", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur3) }, - { "BSImagespaceShaderBrightPassBlur5", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur5) }, - { "BSImagespaceShaderBrightPassBlur7", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur7) }, - { "BSImagespaceShaderBrightPassBlur9", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur9) }, - { "BSImagespaceShaderBrightPassBlur11", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur11) }, - { "BSImagespaceShaderBrightPassBlur13", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur13) }, - { "BSImagespaceShaderBrightPassBlur15", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISBrightPassBlur15) }, - { "BSImagespaceShaderNonHDRBlur3", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur3) }, - { "BSImagespaceShaderNonHDRBlur5", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur5) }, - { "BSImagespaceShaderNonHDRBlur7", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur7) }, - { "BSImagespaceShaderNonHDRBlur9", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur9) }, - { "BSImagespaceShaderNonHDRBlur11", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur11) }, - { "BSImagespaceShaderNonHDRBlur13", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur13) }, - { "BSImagespaceShaderNonHDRBlur15", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISNonHDRBlur15) }, - { "BSImagespaceShaderISBasicCopy", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISBasicCopy) }, - { "BSImagespaceShaderISSimpleColor", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISSimpleColor) }, - { "BSImagespaceShaderApplyReflections", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISApplyReflections) }, - { "BSImagespaceShaderISExp", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISExp) }, - { "BSImagespaceShaderISDisplayDepth", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDisplayDepth) }, - { "BSImagespaceShaderAlphaBlend", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISAlphaBlend) }, - { "BSImagespaceShaderWaterFlow", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterFlow) }, - { "BSImagespaceShaderISWaterBlend", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterBlend) }, - { "BSImagespaceShaderGreyScale", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCopyGrayScale) }, - { "BSImagespaceShaderCopy", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISCopy) }, - { "BSImagespaceShaderCopyScaleBias", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCopyScaleBias) }, + { "BSImagespaceShaderISBlur", static_cast(ISBlur) }, + { "BSImagespaceShaderBlur3", static_cast(ISBlur3) }, + { "BSImagespaceShaderBlur5", static_cast(ISBlur5) }, + { "BSImagespaceShaderBlur7", static_cast(ISBlur7) }, + { "BSImagespaceShaderBlur9", static_cast(ISBlur9) }, + { "BSImagespaceShaderBlur11", static_cast(ISBlur11) }, + { "BSImagespaceShaderBlur13", static_cast(ISBlur13) }, + { "BSImagespaceShaderBlur15", static_cast(ISBlur15) }, + { "BSImagespaceShaderBrightPassBlur3", static_cast(ISBrightPassBlur3) }, + { "BSImagespaceShaderBrightPassBlur5", static_cast(ISBrightPassBlur5) }, + { "BSImagespaceShaderBrightPassBlur7", static_cast(ISBrightPassBlur7) }, + { "BSImagespaceShaderBrightPassBlur9", static_cast(ISBrightPassBlur9) }, + { "BSImagespaceShaderBrightPassBlur11", static_cast(ISBrightPassBlur11) }, + { "BSImagespaceShaderBrightPassBlur13", static_cast(ISBrightPassBlur13) }, + { "BSImagespaceShaderBrightPassBlur15", static_cast(ISBrightPassBlur15) }, + { "BSImagespaceShaderNonHDRBlur3", static_cast(ISNonHDRBlur3) }, + { "BSImagespaceShaderNonHDRBlur5", static_cast(ISNonHDRBlur5) }, + { "BSImagespaceShaderNonHDRBlur7", static_cast(ISNonHDRBlur7) }, + { "BSImagespaceShaderNonHDRBlur9", static_cast(ISNonHDRBlur9) }, + { "BSImagespaceShaderNonHDRBlur11", static_cast(ISNonHDRBlur11) }, + { "BSImagespaceShaderNonHDRBlur13", static_cast(ISNonHDRBlur13) }, + { "BSImagespaceShaderNonHDRBlur15", static_cast(ISNonHDRBlur15) }, + { "BSImagespaceShaderISBasicCopy", static_cast(ISBasicCopy) }, + { "BSImagespaceShaderISSimpleColor", static_cast(ISSimpleColor) }, + { "BSImagespaceShaderApplyReflections", static_cast(ISApplyReflections) }, + { "BSImagespaceShaderISExp", static_cast(ISExp) }, + { "BSImagespaceShaderISDisplayDepth", static_cast(ISDisplayDepth) }, + { "BSImagespaceShaderAlphaBlend", static_cast(ISAlphaBlend) }, + { "BSImagespaceShaderWaterFlow", static_cast(ISWaterFlow) }, + { "BSImagespaceShaderISWaterBlend", static_cast(ISWaterBlend) }, + { "BSImagespaceShaderGreyScale", static_cast(ISCopyGrayScale) }, + { "BSImagespaceShaderCopy", static_cast(ISCopy) }, + { "BSImagespaceShaderCopyScaleBias", static_cast(ISCopyScaleBias) }, { "BSImagespaceShaderCopyCustomViewport", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCopyCustomViewport) }, - { "BSImagespaceShaderCopyTextureMask", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCopyTextureMask) }, + static_cast(ISCopyCustomViewport) }, + { "BSImagespaceShaderCopyTextureMask", static_cast(ISCopyTextureMask) }, { "BSImagespaceShaderCopyDynamicFetchDisabled", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCopyDynamicFetchDisabled) }, + static_cast(ISCopyDynamicFetchDisabled) }, { "BSImagespaceShaderISCompositeVolumetricLighting", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCompositeVolumetricLighting) }, + static_cast(ISCompositeVolumetricLighting) }, { "BSImagespaceShaderISCompositeLensFlare", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISCompositeLensFlare) }, + static_cast(ISCompositeLensFlare) }, { "BSImagespaceShaderISCompositeLensFlareVolumetricLighting", - static_cast(RE::ImageSpaceEffectManager::EffectType:: - ISCompositeLensFlareVolumetricLighting) }, - { "BSImagespaceShaderISDebugSnow", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISDebugSnow) }, - { "BSImagespaceShaderDepthOfField", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDepthOfField) }, + static_cast(ISCompositeLensFlareVolumetricLighting) }, + { "BSImagespaceShaderISDebugSnow", static_cast(ISDebugSnow) }, + { "BSImagespaceShaderDepthOfField", static_cast(ISDepthOfField) }, { "BSImagespaceShaderDepthOfFieldFogged", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDepthOfFieldFogged) }, + static_cast(ISDepthOfFieldFogged) }, { "BSImagespaceShaderDepthOfFieldMaskedFogged", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDepthOfFieldMaskedFogged) }, - { "BSImagespaceShaderDistantBlur", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISDistantBlur) }, + static_cast(ISDepthOfFieldMaskedFogged) }, + { "BSImagespaceShaderDistantBlur", static_cast(ISDistantBlur) }, { "BSImagespaceShaderDistantBlurFogged", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDistantBlurFogged) }, + static_cast(ISDistantBlurFogged) }, { "BSImagespaceShaderDistantBlurMaskedFogged", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDistantBlurMaskedFogged) }, - { "BSImagespaceShaderDoubleVision", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDoubleVision) }, - { "BSImagespaceShaderISDownsample", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDownsample) }, + static_cast(ISDistantBlurMaskedFogged) }, + { "BSImagespaceShaderDoubleVision", static_cast(ISDoubleVision) }, + { "BSImagespaceShaderISDownsample", static_cast(ISDownsample) }, { "BSImagespaceShaderISDownsampleIgnoreBrightest", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISDownsampleIgnoreBrightest) }, + static_cast(ISDownsampleIgnoreBrightest) }, { "BSImagespaceShaderISUpsampleDynamicResolution", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISUpsampleDynamicResolution) }, + static_cast(ISUpsampleDynamicResolution) }, { "BSImageSpaceShaderVolumetricLighting", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISVolumetricLighting) }, - { "BSImagespaceShaderHDRDownSample4", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample4) }, + static_cast(ISVolumetricLighting) }, + { "BSImagespaceShaderHDRDownSample4", static_cast(ISHDRDownSample4) }, { "BSImagespaceShaderHDRDownSample4LightAdapt", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample4LightAdapt) }, + static_cast(ISHDRDownSample4LightAdapt) }, { "BSImagespaceShaderHDRDownSample4LumClamp", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample4LumClamp) }, + static_cast(ISHDRDownSample4LumClamp) }, { "BSImagespaceShaderHDRDownSample4RGB2Lum", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample4RGB2Lum) }, - { "BSImagespaceShaderHDRDownSample16", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample16) }, + static_cast(ISHDRDownSample4RGB2Lum) }, + { "BSImagespaceShaderHDRDownSample16", static_cast(ISHDRDownSample16) }, { "BSImagespaceShaderHDRDownSample16LightAdapt", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample16LightAdapt) }, + static_cast(ISHDRDownSample16LightAdapt) }, { "BSImagespaceShaderHDRDownSample16Lum", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample16Lum) }, + static_cast(ISHDRDownSample16Lum) }, { "BSImagespaceShaderHDRDownSample16LumClamp", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRDownSample16LumClamp) }, + static_cast(ISHDRDownSample16LumClamp) }, { "BSImagespaceShaderHDRTonemapBlendCinematic", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRTonemapBlendCinematic) }, + static_cast(ISHDRTonemapBlendCinematic) }, { "BSImagespaceShaderHDRTonemapBlendCinematicFade", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISHDRTonemapBlendCinematicFade) }, - { "BSImagespaceShaderISIBLensFlares", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISIBLensFlares) }, + static_cast(ISHDRTonemapBlendCinematicFade) }, + { "BSImagespaceShaderISIBLensFlares", static_cast(ISIBLensFlares) }, { "BSImagespaceShaderISLightingComposite", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISLightingComposite) }, + static_cast(ISLightingComposite) }, { "BSImagespaceShaderISLightingCompositeMenu", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISLightingCompositeMenu) }, + static_cast(ISLightingCompositeMenu) }, { "BSImagespaceShaderISLightingCompositeNoDirectionalLight", - static_cast(RE::ImageSpaceEffectManager::EffectType:: - ISLightingCompositeNoDirectionalLight) }, - { "BSImagespaceShaderLocalMap", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISLocalMap) }, - { "BSISWaterBlendHeightmaps", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterBlendHeightmaps) }, + static_cast(ISLightingCompositeNoDirectionalLight) }, + { "BSImagespaceShaderLocalMap", static_cast(ISLocalMap) }, + { "BSISWaterBlendHeightmaps", static_cast(ISWaterBlendHeightmaps) }, { "BSISWaterDisplacementClearSimulation", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterDisplacementClearSimulation) }, + static_cast(ISWaterDisplacementClearSimulation) }, { "BSISWaterDisplacementNormals", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterDisplacementNormals) }, + static_cast(ISWaterDisplacementNormals) }, { "BSISWaterDisplacementRainRipple", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterDisplacementRainRipple) }, + static_cast(ISWaterDisplacementRainRipple) }, { "BSISWaterDisplacementTexOffset", - static_cast( - RE::ImageSpaceEffectManager::EffectType::ISWaterDisplacementTexOffset) }, - { "BSISWaterWadingHeightmap", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterWadingHeightmap) }, - { "BSISWaterRainHeightmap", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterRainHeightmap) }, - { "BSISWaterSmoothHeightmap", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterSmoothHeightmap) }, - { "BSISWaterWadingHeightmap", - static_cast(RE::ImageSpaceEffectManager::EffectType::ISWaterWadingHeightmap) }, + static_cast(ISWaterDisplacementTexOffset) }, + { "BSISWaterWadingHeightmap", static_cast(ISWaterWadingHeightmap) }, + { "BSISWaterRainHeightmap", static_cast(ISWaterRainHeightmap) }, + { "BSISWaterSmoothHeightmap", static_cast(ISWaterSmoothHeightmap) }, + { "BSISWaterWadingHeightmap", static_cast(ISWaterWadingHeightmap) }, + { "BSImagespaceShaderMap", static_cast(ISMap) }, + { "BSImagespaceShaderMap", static_cast(ISMap) }, + { "BSImagespaceShaderWorldMap", static_cast(ISWorldMap) }, + { "BSImagespaceShaderWorldMapNoSkyBlur", + static_cast(ISWorldMapNoSkyBlur) }, + { "BSImagespaceShaderISMinify", static_cast(ISMinify) }, + { "BSImagespaceShaderISMinifyContrast", static_cast(ISMinifyContrast) }, + { "BSImagespaceShaderNoiseNormalmap", static_cast(ISNoiseNormalmap) }, + { "BSImagespaceShaderNoiseScrollAndBlend", static_cast(ISNoiseScrollAndBlend) }, }; auto it = descriptors.find(imagespaceShader.name.c_str()); diff --git a/Shaders/ISMap.hlsl b/Shaders/ISMap.hlsl new file mode 100644 index 0000000..42ed56a --- /dev/null +++ b/Shaders/ISMap.hlsl @@ -0,0 +1,57 @@ +#include "Common/DummyVSTexCoord.hlsl" + +typedef VS_OUTPUT PS_INPUT; + +struct PS_OUTPUT +{ + float4 Color : SV_Target0; +}; + +#if defined(PSHADER) +SamplerState Src0Sampler : register(s0); + +Texture2D Src0Tex : register(t0); + +cbuffer PerGeometry : register(b2) +{ + float4 CameraPos : packoffset(c0); +}; + +PS_OUTPUT main(PS_INPUT input) +{ + PS_OUTPUT psout; + + float4 colorLR = 0; + float4 colorBT = 0; + [unroll] for(int j = -1; j <= 1; ++j) + { + [unroll] for(int i = -1; i <= 1; ++i) + { + if (i == 0 && j == 0) + { + continue; + } + + float4 currentColor = + Src0Tex + .Sample(Src0Sampler, input.TexCoord + float2(i * CameraPos.x, j * CameraPos.y)); + + float centerMul = 1; + if (i == 0 || j == 0) + { + centerMul = 2; + } + + colorLR += -i * centerMul * currentColor; + colorBT += -j * centerMul * currentColor; + } + } + float4 convolved = pow(colorLR, 2) + pow(colorBT, 2); + + float3 mapColor = min(0.275, dot(float3(0.2, 0.2, 0.15), convolved.xyz) + min(0.1, 10 * convolved.w).xxx); + psout.Color.xyz = mapColor; + psout.Color.w = 2 * dot(1, mapColor.zzz); + + return psout; +} +#endif diff --git a/Shaders/ISNoise.hlsl b/Shaders/ISNoise.hlsl new file mode 100644 index 0000000..bfd4543 --- /dev/null +++ b/Shaders/ISNoise.hlsl @@ -0,0 +1,105 @@ +struct VS_INPUT +{ + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD0; +}; + +#ifdef VSHADER +cbuffer PerGeometry : register(b2) +{ + float4 GeometryOffset : packoffset(c0); +}; + +VS_OUTPUT main(VS_INPUT input) +{ + VS_OUTPUT vsout; + + vsout.Position.xy = input.Position.xy - GeometryOffset.xy * float2(2, -2); + vsout.Position.zw = input.Position.zw; + vsout.TexCoord = input.TexCoord.xy; + + return vsout; +} +#endif + +typedef VS_OUTPUT PS_INPUT; + +struct PS_OUTPUT +{ + float4 Color : SV_Target0; +}; + +#if defined(PSHADER) +SamplerState NoiseMapSampler : register(s0); + +Texture2D NoiseMapTex : register(t0); + +cbuffer PerGeometry : register(b2) +{ + float2 fTexScroll0 : packoffset(c0.x); + float2 fTexScroll1 : packoffset(c0.z); + float2 fTexScroll2 : packoffset(c1.x); + float2 fNoiseScale : packoffset(c1.z); + float3 fTexScale : packoffset(c2); + float3 fAmplitude : packoffset(c3); +}; + +PS_OUTPUT main(PS_INPUT input) +{ + PS_OUTPUT psout; + +#if defined (NORMALMAP) + + float offset = 0.00390625; + float valueRL = 0; + float valueTB = 0; + [unroll] for (int i = -1; i <= 1; ++i) + { + [unroll] for (int j = -1; j <= 1; ++j) + { + if (i == 0 && j == 0) + { + continue; + } + + float currentValue = abs( + NoiseMapTex.Sample(NoiseMapSampler, input.TexCoord + float2(i * offset, j * offset)) + .x); + + float centerMul = 1; + if (i == 0 || j == 0) + { + centerMul = 2; + } + + valueRL += i * (fNoiseScale.x * centerMul) * currentValue; + valueTB += j * (fNoiseScale.x * centerMul) * currentValue; + } + } + + psout.Color.xyz = normalize(float3(-valueRL, valueTB, 1)) * 0.5 + 0.5; + psout.Color.w = abs(NoiseMapTex.Sample(NoiseMapSampler, input.TexCoord).y); + +#elif defined(SCROLL_AND_BLEND) + float noise1 = + fAmplitude.x * + (NoiseMapTex.Sample(NoiseMapSampler, input.TexCoord * fTexScale.x + fTexScroll0).z * 2 - 1); + float noise2 = + fAmplitude.y * + (NoiseMapTex.Sample(NoiseMapSampler, input.TexCoord * fTexScale.y + fTexScroll1).y * 2 - 1); + float noise3 = + fAmplitude.z * + (NoiseMapTex.Sample(NoiseMapSampler, input.TexCoord * fTexScale.z + fTexScroll2).x * 2 - 1); + + psout.Color = float4(saturate((noise1 + noise2 + noise3) * 0.5 + 0.5) , 0, 0, 1); +#endif + + return psout; +} +#endif diff --git a/Shaders/ISSAOMinify.hlsl b/Shaders/ISSAOMinify.hlsl new file mode 100644 index 0000000..8e68d8b --- /dev/null +++ b/Shaders/ISSAOMinify.hlsl @@ -0,0 +1,67 @@ +#include "Common/DummyVSTexCoord.hlsl" +#include "Common/FrameBuffer.hlsl" + +typedef VS_OUTPUT PS_INPUT; + +struct PS_OUTPUT +{ + float4 Color : SV_Target0; +}; + +#if defined(PSHADER) +SamplerState sourceSampler : register(s0); + +Texture2D sourceTex : register(t0); + +cbuffer PerGeometry : register(b2) +{ + float4 g_RenderTargetResolution : packoffset(c0); + float4 g_ContrastParams : packoffset(c1); + float g_UseDynamicSampling : packoffset(c2); +}; + +float2 GetMinifiedTexCoord(float2 texCoord) +{ + return ((float2)(((int2)(g_RenderTargetResolution.yx * texCoord.yx) & 1) ^ 1) * 2 - 1) * + g_RenderTargetResolution.zw + + texCoord; +} + +static const float4 ContrastValues[] = { { 0.300000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, + { 0.500000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, { 0.300000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, + { 2.000000, 0, 0, 0 }, { 2.500000, 0, 0, 0 }, { 2.000000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, + { 0.500000, 0, 0, 0 }, { 2.500000, 0, 0, 0 }, { 3.500000, 0, 0, 0 }, { 2.500000, 0, 0, 0 }, + { 0.500000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, { 2.000000, 0, 0, 0 }, { 2.500000, 0, 0, 0 }, + { 2.000000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, { 0.300000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, + { 0.500000, 0, 0, 0 }, { 0.400000, 0, 0, 0 }, { 0.300000, 0, 0, 0 } }; + +PS_OUTPUT main(PS_INPUT input) +{ + PS_OUTPUT psout; + + float2 finalTexCoord; + if (asuint(g_UseDynamicSampling) > 0) + { + float2 drAdjustedTexCoord = DynamicResolutionParams1.xy * input.TexCoord; + float2 minifiedTexCoord = GetMinifiedTexCoord(drAdjustedTexCoord); + finalTexCoord = clamp(minifiedTexCoord, 0, + DynamicResolutionParams1.xy - float2(CameraPreviousPosAdjust.w, 0)); + } + else + { + finalTexCoord = GetMinifiedTexCoord(input.TexCoord); + } + + float4 color = sourceTex.Sample(sourceSampler, finalTexCoord); + +#if defined(CONTRAST) + int contrastIndex = (int)(5 * input.TexCoord.x) + (int)(5 * input.TexCoord.y) * 5; + float contrastFactor = ContrastValues[contrastIndex].x * g_ContrastParams.x; + color *= contrastFactor; +#endif + + psout.Color = color; + + return psout; +} +#endif diff --git a/Shaders/ISWorldMap.hlsl b/Shaders/ISWorldMap.hlsl new file mode 100644 index 0000000..d34f1fc --- /dev/null +++ b/Shaders/ISWorldMap.hlsl @@ -0,0 +1,63 @@ +#include "Common/DummyVSTexCoord.hlsl" +#include "Common/FrameBuffer.hlsl" + +typedef VS_OUTPUT PS_INPUT; + +struct PS_OUTPUT +{ + float4 Color : SV_Target0; +}; + +#if defined(PSHADER) +SamplerState ImageSampler : register(s0); +SamplerState DepthSampler : register(s1); + +Texture2D ImageTex : register(t0); +Texture2D DepthTex : register(t1); + +cbuffer PerGeometry : register(b2) +{ + float4 CameraParams : packoffset(c0); + float4 DepthParams : packoffset(c1); + float4 TexelSize : packoffset(c2); +}; + +PS_OUTPUT main(PS_INPUT input) +{ + PS_OUTPUT psout; + + float2 adjustedTexCoord = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord); + + float depth = DepthTex.Sample(DepthSampler, adjustedTexCoord).x; + + float depthFactor = DepthParams.w / ((1 - depth) * DepthParams.z + DepthParams.y); + float offsetDelta = min(TexelSize.y, TexelSize.z * abs(depthFactor - TexelSize.x)); +#if defined(NO_SKY_BLUR) + if (1 - depth <= 1e-4) + { + offsetDelta = 0; + } +#endif + if (depthFactor < TexelSize.x) + { + offsetDelta *= TexelSize.w; + } + float2 startOffset = input.TexCoord - 3 * (CameraParams.xy * offsetDelta); + + float4 color = 0; + for(int i = 0; i < 7; ++i) + { + for(int j = 0; j < 7; ++j) + { + float2 currentTexCoord = GetDynamicResolutionAdjustedScreenPosition( + startOffset + CameraParams.xy * offsetDelta * float2(i, j)); + float4 currentColor = ImageTex.Sample(ImageSampler, currentTexCoord); + color += currentColor; + } + } + + psout.Color = 0.0204081628 * color; + + return psout; +} +#endif