diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj b/WickedEngine/WickedEngine_SHADERS.vcxproj index 2ad5f4970..f49cdc3fc 100644 --- a/WickedEngine/WickedEngine_SHADERS.vcxproj +++ b/WickedEngine/WickedEngine_SHADERS.vcxproj @@ -168,6 +168,14 @@ Compute 5.0 + + Compute + 5.0 + + + Compute + 5.0 + Compute 5.0 diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters index 9f00e21c6..fb11d897d 100644 --- a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters +++ b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters @@ -828,6 +828,12 @@ CS + + CS + + + CS + diff --git a/WickedEngine/envMapGS.hlsl b/WickedEngine/envMapGS.hlsl index 76380b221..b689dea41 100644 --- a/WickedEngine/envMapGS.hlsl +++ b/WickedEngine/envMapGS.hlsl @@ -14,6 +14,7 @@ void main(triangle VSOut_EnvmapRendering input[3], inout TriangleStream 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_ \ No newline at end of file diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index 220faaba5..8e2377762 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -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 diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index c9c3dfe05..2a0efc115 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -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, diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index de6855b2f..3ce59d3f7 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -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(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_unorm4_BicubicCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_BicubicCS.cso", wiResourceManager::COMPUTESHADER)); computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); computeShaders[CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN] = static_cast(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) diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index c5dbd9924..302bf8fcd 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -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); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 75bf009e0..8a6404696 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -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()