Skip to content

Commit e29e083

Browse files
new concepts for the vbuffer shader
1 parent e55ed1c commit e29e083

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

examples_tests/41.VisibilityBuffer/common.glsl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _COMMON_GLSL_INCLUDED_
22
#define _COMMON_GLSL_INCLUDED_
33

4+
#extension GL_EXT_shader_16bit_storage: require
5+
46
#include "common.h"
57

68
// defines for buffer fill pipeline
@@ -13,7 +15,7 @@
1315
struct BatchInstanceData
1416
{
1517
vec3 Ka;
16-
uint baseVertex;
18+
uint baseTriangle;
1719
vec3 Kd;
1820
nbl_glsl_VG_VirtualAttributePacked_t vAttrPos;
1921
vec3 Ks;
@@ -36,13 +38,6 @@ layout(set = 1, binding = 0, std430) readonly buffer BatchInstanceBuffer
3638
{
3739
BatchInstanceData batchInstanceData[];
3840
};
39-
#if 0
40-
// VG
41-
layout(set = 1, binding = 1, std430) readonly buffer IndexBuffer // TODO: VG descriptor include
42-
{
43-
uint indexBuffer[];
44-
};
45-
#endif
4641

4742
// non-global descriptors
4843
#include <nbl/builtin/glsl/utils/common.glsl>

examples_tests/41.VisibilityBuffer/fillVBuffer.frag

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
#version 430 core
22

3-
layout(location = 0) flat in uint drawID;
4-
53
#include "common.glsl"
64

5+
layout(location = 0) flat in uint drawGUID;
6+
77
// TODO: investigate using snorm16 for the derivatives
88
layout(location = 0) out uvec4 triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2; // 32bit triangleID, 2x16bit barycentrics, 4x16bit barycentric derivatives
99
#include <nbl/builtin/glsl/barycentric/frag.glsl>
1010

11-
uint nbl_glsl_barycentric_frag_getDrawID() {return drawID;}
12-
vec3 nbl_glsl_barycentric_frag_getVertexPos(in uint drawID, in uint primID, in uint primsVx) {return vec3(0.0/0.0);} // TODO
11+
uint nbl_glsl_barycentric_frag_getDrawID() {return drawGUID;}
12+
vec3 nbl_glsl_barycentric_frag_getVertexPos(in uint drawID, in uint primID, in uint primsVx)
13+
{
14+
const uvec3 tri = nbl_glsl_VG_fetchTriangle(primID+batchInstanceData[drawID].baseTriangle); // can optimize, preload only the y,z component
15+
return nbl_glsl_fetchVtxPos(tri[primsVx],drawID);
16+
}
1317

1418
void main()
1519
{
1620
vec2 bary = nbl_glsl_barycentric_frag_get();
1721

18-
triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2[0] = bitfieldInsert(gl_PrimitiveID,drawID,MAX_TRIANGLES_IN_BATCH,32-MAX_TRIANGLES_IN_BATCH);
22+
triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2[0] = bitfieldInsert(gl_PrimitiveID,drawGUID,MAX_TRIANGLES_IN_BATCH,32-MAX_TRIANGLES_IN_BATCH);
1923
triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2[1] = packUnorm2x16(bary);
2024
triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2[2] = packHalf2x16(dFdx(bary));
2125
triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2[3] = packHalf2x16(dFdy(bary));

examples_tests/41.VisibilityBuffer/shadeVBuffer.comp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ mat2 nbl_glsl_perturbNormal_dUVdSomething()
8585
#include <nbl/builtin/glsl/colorspace/OETF.glsl>
8686
void main()
8787
{
88-
// TODO: out of bounds check and return
8988
const ivec2 fragCoord = ivec2(gl_GlobalInvocationID);
9089
if (any(greaterThanEqual(fragCoord,textureSize(vBuffer,0))))
9190
return;
@@ -101,8 +100,7 @@ void main()
101100
);
102101

103102
gBatchInstance = batchInstanceData[drawID];
104-
const uint indexOffset = triangleID*3u+batchInstanceData.baseVertex;
105-
const uint vertexIDs[3] = {indexBuffer[indexOffset+0u],indexBuffer[indexOffset+1u],indexBuffer[indexOffset+2u]};
103+
const uvec3 vertexIDs = nbl_glsl_VG_fetchTriangle(triangleID+gBatchInstance.baseTriangle);
106104

107105
vec3 pos,normal;
108106
vec2 uv;

0 commit comments

Comments
 (0)