Skip to content

Commit 52fe9df

Browse files
committed
Merge branch 'shader_pipeline_irrlichtbaw' into irrlichtbaw-merge
2 parents 6ac3b9a + c6ce1a9 commit 52fe9df

34 files changed

+2187
-535
lines changed

examples_tests/22.RaytracedAO/InstanceDataPerCamera.glsl

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples_tests/22.RaytracedAO/common.glsl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,35 @@
33

44
#define MAX_ACCUMULATED_SAMPLES (1024*1024)
55

6+
#define WORKGROUP_SIZE 256
67

78
#ifdef __cplusplus
8-
#define mat4 nbl::core::matrix4SIMD
9-
#define mat4x3 nbl::core::matrix3x4SIMD
9+
#define uint uint32_t
10+
struct uvec2
11+
{
12+
uint32_t x,y;
13+
};
14+
struct vec2
15+
{
16+
float x,y;
17+
};
18+
struct vec3
19+
{
20+
float x,y,z;
21+
};
22+
#define mat4 irr::core::matrix4SIMD
23+
#define mat4x3 irr::core::matrix3x4SIMD
1024
#endif
1125

1226

27+
struct RaytraceShaderCommonData_t
28+
{
29+
uvec2 imageDimensions;
30+
uint samplesPerPixelPerDispatch;
31+
uint samplesPerRowPerDispatch;
32+
};
33+
34+
1335
struct SLight
1436
{
1537
#ifdef __cplusplus
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#version 430 core
2+
3+
4+
#include "drawCommon.glsl"
5+
layout(local_size_x = WORKGROUP_SIZE) in;
6+
7+
8+
#include <irr/builtin/glsl/utils/indirect_commands.glsl>
9+
layout(set=1, binding=0, std430, row_major) restrict readonly buffer PerInstanceStatic
10+
{
11+
ObjectStaticData_t staticData[];
12+
};
13+
layout(set=1, binding=1, row_major) writeonly restrict buffer PerInstancePerCamera
14+
{
15+
DrawData_t data[];
16+
} instanceDataPerCamera;
17+
layout(set=1, binding=2, std430, row_major) restrict readonly buffer PerInstanceCull
18+
{
19+
CullData_t cullData[];
20+
};
21+
layout(set=1, binding=3, std430) restrict coherent buffer IndirectDraws
22+
{
23+
irr_glsl_DrawElementsIndirectCommand_t draws[];
24+
} commandBuff[2];
25+
26+
27+
28+
layout(push_constant, row_major) uniform PushConstants
29+
{
30+
CullShaderData_t data;
31+
} pc;
32+
33+
34+
35+
#include <irr/builtin/glsl/utils/culling.glsl>
36+
#include <irr/builtin/glsl/utils/transform.glsl>
37+
38+
39+
// base instance remains unchanged
40+
// we just do atomic add on the instance count
41+
void main()
42+
{
43+
uint globalObjectID = gl_GlobalInvocationID.x;
44+
if (globalObjectID>=pc.data.maxObjectCount)
45+
return;
46+
47+
const mat4x3 worldMatrix = cullData[globalObjectID].worldMatrix;
48+
const uint drawID = cullData[globalObjectID].drawID;
49+
50+
// clear drawcount for next buffer
51+
commandBuff[pc.data.currentCommandBufferIx^0x1u].draws[drawID].instanceCount = 0u;
52+
53+
// cull
54+
const mat4 MVP = irr_glsl_pseudoMul4x4with4x3(pc.data.viewProjMatrix,worldMatrix);
55+
bool notCulled = true;
56+
if (false)
57+
{
58+
mat2x3 bbox;
59+
bbox[0] = cullData[globalObjectID].aabbMinEdge;
60+
bbox[1] = cullData[globalObjectID].aabbMaxEdge;
61+
notCulled = irr_glsl_couldBeVisible(MVP,bbox);
62+
}
63+
64+
if (notCulled)
65+
{
66+
const uint instanceID = atomicAdd(commandBuff[pc.data.currentCommandBufferIx].draws[drawID].instanceCount,1u)+cullData[globalObjectID].baseInstance;
67+
68+
instanceDataPerCamera.data[instanceID].MVP = MVP;
69+
instanceDataPerCamera.data[instanceID].detMVP = pc.data.viewProjDeterminant*staticData[globalObjectID].detWorldMatrix;
70+
instanceDataPerCamera.data[instanceID].objectID = globalObjectID;
71+
}
72+
}

0 commit comments

Comments
 (0)