Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WickedEngine/shaders/cullingShaderHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ void AABBfromMinMax(inout AABB aabb, float3 _min, float3 _max)
aabb.c = (_min + _max) * 0.5f;
aabb.e = abs(_max - aabb.c);
}
void AABBtransform(inout AABB aabb, float4x4 mat)
template<typename T>
void AABBtransform(inout AABB aabb, T mat)
{
float3 _min = aabb.getMin();
float3 _max = aabb.getMax();
Expand Down
4 changes: 2 additions & 2 deletions WickedEngine/shaders/lightCullingCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid :

// frustum AABB in world space transformed into the space of the probe/decal OBB:
AABB b = GroupAABB_WS;
AABBtransform(b, load_entitymatrix(entity.GetMatrixIndex()));
AABBtransform(b, (float3x4)load_entitymatrix(i)); // note: straight entity-matrix mapping ok

if (IntersectAABB(a, b))
{
Expand Down Expand Up @@ -280,7 +280,7 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid :

// frustum AABB in world space transformed into the space of the probe/decal OBB:
AABB b = GroupAABB_WS;
AABBtransform(b, load_entitymatrix(entity.GetMatrixIndex()));
AABBtransform(b, (float3x4)load_entitymatrix(i)); // note: straight entity-matrix mapping ok

if (IntersectAABB(a, b))
{
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/lightingHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ inline half3 EnvironmentReflection_Global(in Surface surface)
// clipSpacePos: world space pixel position transformed into OBB space by probeProjection matrix
// MIP: mip level to sample
// return: color of the environment map (rgb), blend factor of the environment map (a)
inline half4 EnvironmentReflection_Local(in TextureCube<half4> cubemap, in Surface surface, in ShaderEntity probe, in float4x4 probeProjection, in half3 clipSpacePos)
inline half4 EnvironmentReflection_Local(in TextureCube<half4> cubemap, in Surface surface, in ShaderEntity probe, in float3x4 probeProjection, in half3 clipSpacePos)
{
if ((probe.layerMask & surface.layerMask) == 0)
return 0; // early exit: layer mismatch
Expand Down
30 changes: 12 additions & 18 deletions WickedEngine/shaders/shadingHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting)
{
// Retrieve global entity index from local bucket, then remove bit from local bucket:
const uint bucket_bit_index = firstbitlow(bucket_bits);
const uint entity_index = bucket_bit_index;
bucket_bits ^= 1u << bucket_bit_index;

const uint entity_index = probes().first_item() + bucket_bit_index;
ShaderEntity probe = load_entity(probes().first_item() + entity_index);

float4x4 probeProjection = load_entitymatrix(probe.GetMatrixIndex());
const int probeTexture = asint(probeProjection[3][0]);
probeProjection[3] = float4(0, 0, 0, 1);
TextureCube<half4> cubemap = bindless_cubemaps_half4[descriptor_index(probeTexture)];
float3x4 probeProjection = load_entitymatrix(entity_index); // note: straight entity-matrix mapping ok
TextureCube<half4> cubemap = bindless_cubemaps_half4[descriptor_index(probe.GetTextureIndex())];

const half3 clipSpacePos = mul(probeProjection, float4(surface.P, 1)).xyz;
const half3 uvw = box_to_uv(clipSpacePos.xyz);
Expand Down Expand Up @@ -180,22 +178,21 @@ inline void ForwardDecals(inout Surface surface, inout half4 surfaceMap, Sampler
{
// Retrieve global entity index from local bucket, then remove bit from local bucket:
const uint bucket_bit_index = firstbitlow(bucket_bits);
const uint entity_index = bucket_bit_index;
bucket_bits ^= 1u << bucket_bit_index;

ShaderEntity decal = load_entity(decals().first_item() + entity_index);
const uint entity_index = decals().first_item() + bucket_bit_index;
ShaderEntity decal = load_entity(entity_index);

float4x4 decalProjection = load_entitymatrix(decal.GetMatrixIndex());
float4x4 decalProjection = load_entitymatrix(entity_index); // note: straight entity-matrix mapping ok
const int decalTexture = asint(decalProjection[3][0]);
const int decalNormal = asint(decalProjection[3][1]);
const int decalSurfacemap = asint(decalProjection[3][2]);
const int decalDisplacementmap = asint(decalProjection[3][3]);
decalProjection[3] = float4(0, 0, 0, 1);

// under here will be VGPR!
if ((decal.layerMask & surface.layerMask) == 0)
continue;
const float3 clipSpacePos = mul(decalProjection, float4(surface.P, 1)).xyz;
const float3 clipSpacePos = mul((float3x4)decalProjection, float4(surface.P, 1)).xyz;
float3 uvw = box_to_uv(clipSpacePos.xyz);
[branch]
if (is_saturated(uvw))
Expand Down Expand Up @@ -306,10 +303,8 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f

ShaderEntity probe = load_entity(entity_index);

float4x4 probeProjection = load_entitymatrix(probe.GetMatrixIndex());
const int probeTexture = asint(probeProjection[3][0]);
probeProjection[3] = float4(0, 0, 0, 1);
TextureCube<half4> cubemap = bindless_cubemaps_half4[descriptor_index(probeTexture)];
float3x4 probeProjection = load_entitymatrix(entity_index); // note: straight entity-matrix mapping ok
TextureCube<half4> cubemap = bindless_cubemaps_half4[descriptor_index(probe.GetTextureIndex())];

const half3 clipSpacePos = mul(probeProjection, float4(surface.P, 1)).xyz;
const half3 uvw = box_to_uv(clipSpacePos.xyz);
Expand Down Expand Up @@ -644,22 +639,21 @@ inline void TiledDecals(inout Surface surface, uint flatTileIndex, inout half4 s
{
// Retrieve global entity index from local bucket, then remove bit from local bucket:
const uint bucket_bit_index = firstbitlow(bucket_bits);
const uint entity_index = bucket * 32 + bucket_bit_index;
bucket_bits ^= 1u << bucket_bit_index;

const uint entity_index = bucket * 32 + bucket_bit_index;
ShaderEntity decal = load_entity(entity_index);

float4x4 decalProjection = load_entitymatrix(decal.GetMatrixIndex());
float4x4 decalProjection = load_entitymatrix(entity_index); // note: straight entity-matrix mapping ok
const int decalTexture = asint(decalProjection[3][0]);
const int decalNormal = asint(decalProjection[3][1]);
const int decalSurfacemap = asint(decalProjection[3][2]);
const int decalDisplacementmap = asint(decalProjection[3][3]);
decalProjection[3] = float4(0, 0, 0, 1);

// under here will be VGPR!
if ((decal.layerMask & surface.layerMask) == 0)
continue;
const float3 clipSpacePos = mul(decalProjection, float4(surface.P, 1)).xyz;
const float3 clipSpacePos = mul((float3x4)decalProjection, float4(surface.P, 1)).xyz;
float3 uvw = box_to_uv(clipSpacePos.xyz);
[branch]
if (is_saturated(uvw))
Expand Down
7 changes: 3 additions & 4 deletions WickedEngine/shaders/surfaceHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -795,22 +795,21 @@ struct Surface
{
// Retrieve global entity index from local bucket, then remove bit from local bucket:
const uint bucket_bit_index = firstbitlow(bucket_bits);
const uint entity_index = bucket * 32 + bucket_bit_index;
bucket_bits ^= 1u << bucket_bit_index;

const uint entity_index = bucket * 32 + bucket_bit_index;
ShaderEntity decal = load_entity(entity_index);

float4x4 decalProjection = load_entitymatrix(decal.GetMatrixIndex());
float4x4 decalProjection = load_entitymatrix(entity_index); // note: straight entity-matrix mapping ok
const int decalTexture = asint(decalProjection[3][0]);
const int decalNormal = asint(decalProjection[3][1]);
const int decalSurfacemap = asint(decalProjection[3][2]);
const int decalDisplacementmap = asint(decalProjection[3][3]);
decalProjection[3] = float4(0, 0, 0, 1);

// under here will be VGPR!
if ((decal.layerMask & layerMask) == 0)
continue;
const float3 clipSpacePos = mul(decalProjection, float4(P, 1)).xyz;
const float3 clipSpacePos = mul((float3x4)decalProjection, float4(P, 1)).xyz;
float3 uvw = box_to_uv(clipSpacePos.xyz);
[branch]
if (is_saturated(uvw))
Expand Down
38 changes: 13 additions & 25 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4549,7 +4549,6 @@ void UpdatePerFrameData(
const XMMATRIX viewMatrix = vis.camera->GetView();

uint32_t entityCounter = 0;
uint32_t matrixCounter = 0;

// Write decals into entity array:
decalarray_offset = entityCounter;
Expand All @@ -4561,11 +4560,6 @@ void UpdatePerFrameData(
entityCounter--;
break;
}
if (matrixCounter >= MATRIXARRAY_COUNT)
{
matrixCounter--;
break;
}
ShaderEntity shaderentity = {};
XMMATRIX shadermatrix;

Expand Down Expand Up @@ -4596,7 +4590,7 @@ void UpdatePerFrameData(
shaderentity.SetAngleScale(decal.normal_strength);
shaderentity.SetLength(decal.displacement_strength);

shaderentity.SetIndices(matrixCounter, 0);
shaderentity.SetIndices(entityCounter, 0);
shadermatrix = XMMatrixInverse(nullptr, XMLoadFloat4x4(&decal.world));

int texture = -1;
Expand Down Expand Up @@ -4629,8 +4623,7 @@ void UpdatePerFrameData(
XMStoreFloat3(&cullsphere.center, XMVector3Transform(XMLoadFloat3(&shaderentity.position), viewMatrix));
cullsphere.radius = decal.range;

XMStoreFloat4x4(matrixArray + matrixCounter, shadermatrix);
matrixCounter++;
XMStoreFloat4x4(matrixArray + entityCounter, shadermatrix); // note: straight entity-matrix mapping ok

std::memcpy(entityArray + entityCounter, &shaderentity, sizeof(ShaderEntity));
std::memcpy(entityCullingArray + entityCounter, &cullsphere, sizeof(ShaderSphere));
Expand All @@ -4648,11 +4641,6 @@ void UpdatePerFrameData(
entityCounter--;
break;
}
if (matrixCounter >= MATRIXARRAY_COUNT)
{
matrixCounter--;
break;
}
ShaderEntity shaderentity = {};
XMMATRIX shadermatrix;

Expand All @@ -4673,33 +4661,29 @@ void UpdatePerFrameData(
shaderentity.position = probe.position;
shaderentity.SetRange(probe.range);

shaderentity.SetIndices(matrixCounter, 0);
shadermatrix = XMLoadFloat4x4(&probe.inverseMatrix);

int texture = -1;
int texture_index = -1;
if (probe.texture.IsValid())
{
texture = device->GetDescriptorIndex(&probe.texture, SubresourceType::SRV, probe.subresource);
texture_index = device->GetDescriptorIndex(&probe.texture, SubresourceType::SRV, probe.subresource);
}
texture_index = std::max(0, texture_index);

shadermatrix.r[0] = XMVectorSetW(shadermatrix.r[0], *(float*)&texture);
shadermatrix.r[1] = XMVectorSetW(shadermatrix.r[1], 0);
shadermatrix.r[2] = XMVectorSetW(shadermatrix.r[2], 0);
shadermatrix.r[3] = XMVectorSetW(shadermatrix.r[3], 0);
shaderentity.SetIndices(entityCounter, (uint)texture_index);
shadermatrix = XMLoadFloat4x4(&probe.inverseMatrix);

ShaderSphere cullsphere = {};
XMStoreFloat3(&cullsphere.center, XMVector3Transform(XMLoadFloat3(&shaderentity.position), viewMatrix));
cullsphere.radius = probe.range;

XMStoreFloat4x4(matrixArray + matrixCounter, shadermatrix);
matrixCounter++;
XMStoreFloat4x4(matrixArray + entityCounter, shadermatrix); // note: straight entity-matrix mapping ok

std::memcpy(entityArray + entityCounter, &shaderentity, sizeof(ShaderEntity));
std::memcpy(entityCullingArray + entityCounter, &cullsphere, sizeof(ShaderSphere));
entityCounter++;
envprobearray_count++;
}

uint32_t matrixCounter = entityCounter; // so far entities and matrices had 1-1 mapping, this is not true below this part:
const XMFLOAT2 atlas_dim_rcp = XMFLOAT2(1.0f / float(shadowMapAtlas.desc.width), 1.0f / float(shadowMapAtlas.desc.height));

// Write directional lights into entity array:
Expand Down Expand Up @@ -4759,6 +4743,7 @@ void UpdatePerFrameData(
for (size_t cascade = 0; cascade < cascade_count; ++cascade)
{
XMStoreFloat4x4(&matrixArray[matrixCounter++], shcams[cascade].view_projection);
matrixCounter = std::min(matrixCounter, MATRIXARRAY_COUNT - 1);
}
}

Expand Down Expand Up @@ -4851,6 +4836,7 @@ void UpdatePerFrameData(
SHCAM shcam;
CreateSpotLightShadowCam(light, shcam);
XMStoreFloat4x4(&matrixArray[matrixCounter++], shcam.view_projection);
matrixCounter = std::min(matrixCounter, MATRIXARRAY_COUNT - 1);
}

if (light.IsCastingShadow())
Expand Down Expand Up @@ -5015,6 +5001,7 @@ void UpdatePerFrameData(
SHCAM shcam;
CreateSpotLightShadowCam(light, shcam);
XMStoreFloat4x4(&matrixArray[matrixCounter++], shcam.view_projection);
matrixCounter = std::min(matrixCounter, MATRIXARRAY_COUNT - 1);
}

if (light.IsCastingShadow())
Expand Down Expand Up @@ -5093,6 +5080,7 @@ void UpdatePerFrameData(
XMStoreFloat3(&cullsphere.center, XMVector3Transform(XMLoadFloat3(&shaderentity.position), viewMatrix));
cullsphere.radius = FLT_MAX;
matrixArray[matrixCounter++] = collider.plane.projection;
matrixCounter = std::min(matrixCounter, MATRIXARRAY_COUNT - 1);
break;
default:
assert(0);
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 72;
// minor bug fixes, alterations, refactors, updates
const int revision = 89;
const int revision = 90;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down
Loading