mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Make shadows work with one cascade
This commit is contained in:
parent
0cb8b4dfa1
commit
c1856a5e36
7 changed files with 34 additions and 13 deletions
|
@ -182,7 +182,7 @@ void GL41Texture::syncSampler() const {
|
|||
glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||
|
||||
if (sampler.doComparison()) {
|
||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE_ARB);
|
||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
||||
} else {
|
||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
|
@ -197,7 +197,7 @@ void GL41Texture::syncSampler() const {
|
|||
glTexParameterf(_target, GL_TEXTURE_MIN_LOD, (float)sampler.getMinMip());
|
||||
glTexParameterf(_target, GL_TEXTURE_MAX_LOD, (sampler.getMaxMip() == Sampler::MAX_MIP_LEVEL ? 1000.f : sampler.getMaxMip()));
|
||||
|
||||
glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, sampler.getMaxAnisotropy());
|
||||
glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY, sampler.getMaxAnisotropy());
|
||||
}
|
||||
|
||||
using GL41FixedAllocationTexture = GL41Backend::GL41FixedAllocationTexture;
|
||||
|
|
|
@ -152,7 +152,7 @@ public:
|
|||
glSamplerParameteri(result, GL_TEXTURE_MIN_FILTER, fm.minFilter);
|
||||
glSamplerParameteri(result, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||
if (sampler.doComparison()) {
|
||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE_ARB);
|
||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
||||
} else {
|
||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
|
@ -341,7 +341,7 @@ void GL45Texture::syncSampler() const {
|
|||
glTextureParameteri(_id, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||
|
||||
if (sampler.doComparison()) {
|
||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE_ARB);
|
||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
||||
} else {
|
||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
|
|
|
@ -61,7 +61,7 @@ Framebuffer* Framebuffer::createShadowmap(uint16 width) {
|
|||
samplerDesc._borderColor = glm::vec4(1.0f);
|
||||
samplerDesc._wrapModeU = Sampler::WRAP_BORDER;
|
||||
samplerDesc._wrapModeV = Sampler::WRAP_BORDER;
|
||||
samplerDesc._filter = Sampler::FILTER_MIN_MAG_LINEAR;
|
||||
samplerDesc._filter = Sampler::FILTER_MIN_MAG_POINT;
|
||||
samplerDesc._comparisonFunc = LESS;
|
||||
|
||||
depthTexture->setSampler(Sampler(samplerDesc));
|
||||
|
|
|
@ -227,7 +227,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
|||
}
|
||||
|
||||
const auto setupOutput = task.addJob<RenderShadowSetup>("ShadowSetup");
|
||||
const auto queryResolution = setupOutput.getN<RenderShadowSetup::Outputs>(2);
|
||||
const auto queryResolution = setupOutput.getN<RenderShadowSetup::Outputs>(1);
|
||||
// Fetch and cull the items from the scene
|
||||
|
||||
static const auto shadowCasterReceiverFilter = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(tagBits, tagMask);
|
||||
|
@ -248,10 +248,12 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
|||
const auto sortedShapes = task.addJob<DepthSortShapes>("DepthSortShadow", sortedPipelines, true);
|
||||
|
||||
render::Varying cascadeFrustums[SHADOW_CASCADE_MAX_COUNT] = {
|
||||
ViewFrustumPointer(),
|
||||
ViewFrustumPointer(),
|
||||
ViewFrustumPointer()
|
||||
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||
,ViewFrustumPointer(),
|
||||
ViewFrustumPointer(),
|
||||
ViewFrustumPointer()
|
||||
#endif
|
||||
};
|
||||
|
||||
for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) {
|
||||
|
@ -293,13 +295,15 @@ RenderShadowSetup::RenderShadowSetup() :
|
|||
|
||||
void RenderShadowSetup::configure(const Config& configuration) {
|
||||
setConstantBias(0, configuration.constantBias0);
|
||||
setConstantBias(1, configuration.constantBias1);
|
||||
setConstantBias(2, configuration.constantBias2);
|
||||
setConstantBias(3, configuration.constantBias3);
|
||||
setSlopeBias(0, configuration.slopeBias0);
|
||||
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||
setConstantBias(1, configuration.constantBias1);
|
||||
setSlopeBias(1, configuration.slopeBias1);
|
||||
setConstantBias(2, configuration.constantBias2);
|
||||
setSlopeBias(2, configuration.slopeBias2);
|
||||
setConstantBias(3, configuration.constantBias3);
|
||||
setSlopeBias(3, configuration.slopeBias3);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RenderShadowSetup::setConstantBias(int cascadeIndex, float value) {
|
||||
|
|
|
@ -17,11 +17,19 @@
|
|||
#define SHADOW_SCREEN_SPACE_DITHER 1
|
||||
|
||||
// the shadow texture
|
||||
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||
uniform sampler2DShadow shadowMaps[SHADOW_CASCADE_MAX_COUNT];
|
||||
#else
|
||||
uniform sampler2DShadow shadowMaps;
|
||||
#endif
|
||||
|
||||
// Sample the shadowMap with PCF (built-in)
|
||||
float fetchShadow(int cascadeIndex, vec3 shadowTexcoord) {
|
||||
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||
return texture(shadowMaps[cascadeIndex], shadowTexcoord);
|
||||
#else
|
||||
return texture(shadowMaps, shadowTexcoord);
|
||||
#endif
|
||||
}
|
||||
|
||||
vec2 PCFkernel[4] = vec2[4](
|
||||
|
@ -89,6 +97,7 @@ float evalShadowCascadeAttenuation(int cascadeIndex, ShadowSampleOffsets offsets
|
|||
|
||||
float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDepth, vec3 worldNormal) {
|
||||
ShadowSampleOffsets offsets = evalShadowFilterOffsets(worldPosition);
|
||||
#if 0
|
||||
vec4 cascadeShadowCoords[2];
|
||||
cascadeShadowCoords[0] = vec4(0);
|
||||
cascadeShadowCoords[1] = vec4(0);
|
||||
|
@ -105,6 +114,11 @@ float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDe
|
|||
float attenuation = mix(cascadeAttenuations.x, cascadeAttenuations.y, cascadeMix);
|
||||
// Falloff to max distance
|
||||
return mix(1.0, attenuation, evalShadowFalloff(viewDepth));
|
||||
#else
|
||||
vec4 shadowTexcoord = evalShadowTexcoord(0, worldPosition);
|
||||
float attenuation = fetchShadow(0, shadowTexcoord.xyz);
|
||||
return attenuation;
|
||||
#endif
|
||||
}
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# define MAT4 mat4
|
||||
#endif
|
||||
|
||||
#define SHADOW_CASCADE_MAX_COUNT 4
|
||||
#define SHADOW_CASCADE_MAX_COUNT 1
|
||||
|
||||
struct ShadowTransform {
|
||||
MAT4 reprojection;
|
||||
|
|
|
@ -370,10 +370,13 @@ void CullShapeBounds::run(const RenderContextPointer& renderContext, const Input
|
|||
const auto& inShapes = inputs.get0();
|
||||
const auto& cullFilter = inputs.get1();
|
||||
const auto& boundsFilter = inputs.get2();
|
||||
const auto& antiFrustum = inputs.get3();
|
||||
ViewFrustumPointer antiFrustum;
|
||||
auto& outShapes = outputs.edit0();
|
||||
auto& outBounds = outputs.edit1();
|
||||
|
||||
if (!inputs[3].isNull()) {
|
||||
antiFrustum = inputs.get3();
|
||||
}
|
||||
outShapes.clear();
|
||||
outBounds = AABox();
|
||||
|
||||
|
|
Loading…
Reference in a new issue