added bicubic lightmap filter, bicubic mipgen, enabled lightmaps for env probe captures
This commit is contained in:
@@ -168,6 +168,14 @@
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="generateMIPChain2D_float4_BicubicCS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="generateMIPChain2D_unorm4_BicubicCS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="generateMIPChain2D_unorm4_GaussianCS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
|
||||
@@ -828,6 +828,12 @@
|
||||
<FxCompile Include="copytexture2D_float4_borderexpandCS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="generateMIPChain2D_float4_BicubicCS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="generateMIPChain2D_unorm4_BicubicCS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="PS">
|
||||
|
||||
@@ -14,6 +14,7 @@ void main(triangle VSOut_EnvmapRendering input[3], inout TriangleStream<PSIn_Env
|
||||
output.pos = mul(input[v].pos, xCubeShadowVP[f]);
|
||||
output.pos3D = input[v].pos.xyz;
|
||||
output.tex = input[v].tex;
|
||||
output.atl = input[v].atl;
|
||||
output.nor = input[v].nor;
|
||||
output.instanceColor = input[v].instanceColor;
|
||||
output.ao = input[v].ao;
|
||||
|
||||
@@ -8,6 +8,7 @@ struct VSOut_EnvmapRendering
|
||||
float4 pos : SV_Position;
|
||||
float3 nor : NORMAL;
|
||||
float2 tex : TEXCOORD0;
|
||||
float2 atl : ATLAS;
|
||||
nointerpolation float3 instanceColor : INSTANCECOLOR;
|
||||
float ao : AMBIENT_OCCLUSION;
|
||||
};
|
||||
@@ -18,6 +19,7 @@ struct PSIn_EnvmapRendering
|
||||
float3 pos3D : WORLDPOSITION;
|
||||
float3 nor : NORMAL;
|
||||
float2 tex : TEXCOORD0;
|
||||
float2 atl : ATLAS;
|
||||
float ao : AMBIENT_OCCLUSION;
|
||||
nointerpolation float3 instanceColor : INSTANCECOLOR;
|
||||
uint RTIndex : SV_RenderTargetArrayIndex;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "envMapHF.hlsli"
|
||||
|
||||
|
||||
VSOut_EnvmapRendering main(Input_Object_POS_TEX input)
|
||||
VSOut_EnvmapRendering main(Input_Object_ALL input)
|
||||
{
|
||||
VSOut_EnvmapRendering Out;
|
||||
|
||||
@@ -12,6 +12,7 @@ VSOut_EnvmapRendering main(Input_Object_POS_TEX input)
|
||||
Out.pos = mul(surface.position, WORLD);
|
||||
Out.nor = normalize(mul(surface.normal, (float3x3)WORLD));
|
||||
Out.tex = surface.uv;
|
||||
Out.atl = surface.atlas;
|
||||
Out.instanceColor = input.instance.color_dither.rgb;
|
||||
Out.ao = 1;
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "globals.hlsli"
|
||||
#include "ShaderInterop_Utility.h"
|
||||
|
||||
#ifndef MIP_OUTPUT_FORMAT
|
||||
#define MIP_OUTPUT_FORMAT float4
|
||||
#endif
|
||||
|
||||
TEXTURE2D(input, float4, TEXSLOT_UNIQUE0);
|
||||
RWTEXTURE2D(output, MIP_OUTPUT_FORMAT, 0);
|
||||
|
||||
[numthreads(GENERATEMIPCHAIN_2D_BLOCK_SIZE, GENERATEMIPCHAIN_2D_BLOCK_SIZE, 1)]
|
||||
void main(uint3 DTid : SV_DispatchThreadID)
|
||||
{
|
||||
if (DTid.x < outputResolution.x && DTid.y < outputResolution.y)
|
||||
{
|
||||
output[DTid.xy] = SampleTextureCatmullRom(input, ((float2)DTid.xy + 0.5f) / (float2)outputResolution.xy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#define MIP_OUTPUT_FORMAT unorm float4
|
||||
|
||||
#include "generateMIPChain2D_float4_BicubicCS.hlsl"
|
||||
@@ -185,4 +185,59 @@ inline float3 UV_to_CubeMap(in float2 uv, in uint faceIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16. ( https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1#file-tex2dcatmullrom-hlsl )
|
||||
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
|
||||
float4 SampleTextureCatmullRom(in Texture2D<float4> tex, in float2 uv)
|
||||
{
|
||||
float2 texSize;
|
||||
tex.GetDimensions(texSize.x, texSize.y);
|
||||
|
||||
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
|
||||
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
|
||||
// location [1, 1] in the grid, where [0, 0] is the top left corner.
|
||||
float2 samplePos = uv * texSize;
|
||||
float2 texPos1 = floor(samplePos - 0.5f) + 0.5f;
|
||||
|
||||
// Compute the fractional offset from our starting texel to our original sample location, which we'll
|
||||
// feed into the Catmull-Rom spline function to get our filter weights.
|
||||
float2 f = samplePos - texPos1;
|
||||
|
||||
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
|
||||
// These equations are pre-expanded based on our knowledge of where the texels will be located,
|
||||
// which lets us avoid having to evaluate a piece-wise function.
|
||||
float2 w0 = f * (-0.5f + f * (1.0f - 0.5f * f));
|
||||
float2 w1 = 1.0f + f * f * (-2.5f + 1.5f * f);
|
||||
float2 w2 = f * (0.5f + f * (2.0f - 1.5f * f));
|
||||
float2 w3 = f * f * (-0.5f + 0.5f * f);
|
||||
|
||||
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
|
||||
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
|
||||
float2 w12 = w1 + w2;
|
||||
float2 offset12 = w2 / (w1 + w2);
|
||||
|
||||
// Compute the final UV coordinates we'll use for sampling the texture
|
||||
float2 texPos0 = texPos1 - 1;
|
||||
float2 texPos3 = texPos1 + 2;
|
||||
float2 texPos12 = texPos1 + offset12;
|
||||
|
||||
texPos0 /= texSize;
|
||||
texPos3 /= texSize;
|
||||
texPos12 /= texSize;
|
||||
|
||||
float4 result = 0.0f;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos0.x, texPos0.y), 0.0f) * w0.x * w0.y;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos12.x, texPos0.y), 0.0f) * w12.x * w0.y;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos3.x, texPos0.y), 0.0f) * w3.x * w0.y;
|
||||
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos0.x, texPos12.y), 0.0f) * w0.x * w12.y;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos12.x, texPos12.y), 0.0f) * w12.x * w12.y;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos3.x, texPos12.y), 0.0f) * w3.x * w12.y;
|
||||
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos0.x, texPos3.y), 0.0f) * w0.x * w3.y;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos12.x, texPos3.y), 0.0f) * w12.x * w3.y;
|
||||
result += tex.SampleLevel(sampler_linear_clamp, float2(texPos3.x, texPos3.y), 0.0f) * w3.x * w3.y;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // _SHADER_GLOBALS_
|
||||
@@ -15,6 +15,8 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define LIGHTMAP_QUALITY_BICUBIC
|
||||
|
||||
|
||||
#include "globals.hlsli"
|
||||
#include "objectInputLayoutHF.hlsli"
|
||||
@@ -599,11 +601,13 @@ GBUFFEROutputType_Thin main(PIXELINPUT input)
|
||||
|
||||
|
||||
#ifndef SIMPLE_INPUT
|
||||
#ifndef ENVMAPRENDERING
|
||||
#ifdef LIGHTMAP_QUALITY_BICUBIC
|
||||
float4 lightmap = SampleTextureCatmullRom(texture_globallightmap, input.atl);
|
||||
#else
|
||||
float4 lightmap = texture_globallightmap.SampleLevel(sampler_linear_clamp, input.atl, 0);
|
||||
#endif // LIGHTMAP_QUALITY_BICUBIC
|
||||
diffuse += lightmap.rgb;
|
||||
ao *= saturate(1 - lightmap.a);
|
||||
#endif // ENVMAPRENDERING
|
||||
#endif // SIMPLE_INPUT
|
||||
|
||||
|
||||
|
||||
@@ -272,6 +272,8 @@ enum CSTYPES
|
||||
CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER,
|
||||
CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN,
|
||||
CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN,
|
||||
CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC,
|
||||
CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC,
|
||||
CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER,
|
||||
CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER,
|
||||
CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN,
|
||||
|
||||
@@ -666,10 +666,8 @@ VLTYPES GetVLTYPE(SHADERTYPE shaderType, bool tessellation, bool alphatest, bool
|
||||
case SHADERTYPE_DEFERRED:
|
||||
case SHADERTYPE_FORWARD:
|
||||
case SHADERTYPE_TILEDFORWARD:
|
||||
realVL = VLTYPE_OBJECT_ALL;
|
||||
break;
|
||||
case SHADERTYPE_ENVMAPCAPTURE:
|
||||
realVL = VLTYPE_OBJECT_POS_TEX;
|
||||
realVL = VLTYPE_OBJECT_ALL;
|
||||
break;
|
||||
case SHADERTYPE_DEPTHONLY:
|
||||
if (tessellation)
|
||||
@@ -1328,10 +1326,12 @@ void RenderMeshes(const RenderQueue& renderQueue, SHADERTYPE shaderType, UINT re
|
||||
};
|
||||
|
||||
const bool advancedVBRequest =
|
||||
!IsWireRender() &&
|
||||
(shaderType == SHADERTYPE_FORWARD ||
|
||||
!IsWireRender() && (
|
||||
shaderType == SHADERTYPE_FORWARD ||
|
||||
shaderType == SHADERTYPE_DEFERRED ||
|
||||
shaderType == SHADERTYPE_TILEDFORWARD);
|
||||
shaderType == SHADERTYPE_TILEDFORWARD ||
|
||||
shaderType == SHADERTYPE_ENVMAPCAPTURE
|
||||
);
|
||||
|
||||
const bool easyTextureBind =
|
||||
shaderType == SHADERTYPE_TEXTURE ||
|
||||
@@ -1978,6 +1978,8 @@ void LoadShaders()
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_GaussianCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_unorm4_BicubicCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_BicubicCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
@@ -6629,7 +6631,7 @@ void GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD th
|
||||
GetDevice()->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
assert(0); // not implemented
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6682,6 +6684,10 @@ void GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD th
|
||||
GetDevice()->EventBegin("GenerateMipChain 2D - GaussianFilter", threadID);
|
||||
GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN], threadID);
|
||||
break;
|
||||
case MIPGENFILTER_BICUBIC:
|
||||
GetDevice()->EventBegin("GenerateMipChain 2D - BicubicFilter", threadID);
|
||||
GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC], threadID);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
@@ -6760,6 +6766,9 @@ void GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHREAD th
|
||||
GetDevice()->EventBegin("GenerateMipChain 3D - GaussianFilter", threadID);
|
||||
GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN], threadID);
|
||||
break;
|
||||
default:
|
||||
assert(0); // not implemented
|
||||
break;
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < desc.MipLevels - 1; ++i)
|
||||
|
||||
@@ -151,6 +151,7 @@ namespace wiRenderer
|
||||
MIPGENFILTER_LINEAR,
|
||||
MIPGENFILTER_LINEAR_MAXIMUM,
|
||||
MIPGENFILTER_GAUSSIAN,
|
||||
MIPGENFILTER_BICUBIC,
|
||||
};
|
||||
void GenerateMipChain(wiGraphicsTypes::Texture1D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1);
|
||||
void GenerateMipChain(wiGraphicsTypes::Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates
|
||||
const int minor = 24;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 8;
|
||||
const int revision = 9;
|
||||
|
||||
|
||||
long GetVersion()
|
||||
|
||||
Reference in New Issue
Block a user