@@ -4,34 +4,47 @@ using namespace nbl::hlsl;
44using namespace nbl::hlsl::examples::geometry_creator_scene;
55
66// for dat sweet programmable pulling
7- [[vk::binding (0 )]] Buffer <float32_t4> utbs[/* SPushConstants::DescriptorCount*/ 255 ];
7+ [[vk::binding (0 )]] Buffer <float32_t4> utbs[SPushConstants::DescriptorCount];
88
99//
1010[[vk::push_constant]] SPushConstants pc;
1111
1212//
1313struct SInterpolants
1414{
15- float32_t4 position : SV_Position ;
16- float32_t3 meta : COLOR0 ;
15+ float32_t4 ndc : SV_Position ;
16+ float32_t3 meta : COLOR1 ;
1717};
1818#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl"
1919
20+ float32_t3 reconstructGeometricNormal (float32_t3 pos)
21+ {
22+ const float32_t2x3 dPos_dScreen = float32_t2x3 (
23+ ddx (pos),
24+ ddy (pos)
25+ );
26+ return cross (dPos_dScreen[0 ],dPos_dScreen[1 ]);
27+ }
28+
2029//
2130[shader ("vertex" )]
2231SInterpolants BasicVS (uint32_t VertexIndex : SV_VertexID )
2332{
2433 const float32_t3 position = utbs[pc.positionView][VertexIndex].xyz;
2534
2635 SInterpolants output;
27- output.position = math::linalg::promoted_mul (pc.matrices.worldViewProj,position);
28- output.meta = mul (pc.matrices.normal,utbs[pc.normalView][VertexIndex].xyz);
36+ output.ndc = math::linalg::promoted_mul (pc.matrices.worldViewProj,position);
37+ if (pc.normalView<SPushConstants::DescriptorCount)
38+ output.meta = mul (pc.matrices.normal,utbs[pc.normalView][VertexIndex].xyz);
39+ else
40+ output.meta = mul (inverse (transpose (pc.matrices.normal)),position);
2941 return output;
3042}
3143[shader ("pixel" )]
3244float32_t4 BasicFS (SInterpolants input) : SV_Target0
3345{
34- return float32_t4 (normalize (input.meta)*0.5f +promote<float32_t3>(0.5f ),1.f );
46+ const float32_t3 normal = pc.normalView<SPushConstants::DescriptorCount ? input.meta:reconstructGeometricNormal (input.meta);
47+ return float32_t4 (normalize (normal)*0.5f +promote<float32_t3>(0.5f ),1.f );
3548}
3649
3750// TODO: do smooth normals on the cone
@@ -41,17 +54,13 @@ SInterpolants ConeVS(uint32_t VertexIndex : SV_VertexID)
4154 const float32_t3 position = utbs[pc.positionView][VertexIndex].xyz;
4255
4356 SInterpolants output;
44- output.position = math::linalg::promoted_mul (pc.matrices.worldViewProj,position);
57+ output.ndc = math::linalg::promoted_mul (pc.matrices.worldViewProj,position);
4558 output.meta = mul (inverse (transpose (pc.matrices.normal)),position);
4659 return output;
4760}
4861[shader ("pixel" )]
4962float32_t4 ConeFS (SInterpolants input) : SV_Target0
5063{
51- const float32_t2x3 dViewPos_dScreen = float32_t2x3 (
52- ddx (input.meta),
53- ddy (input.meta)
54- );
55- const float32_t3 normal = cross (dViewPos_dScreen[0 ],dViewPos_dScreen[1 ]);
64+ const float32_t3 normal = reconstructGeometricNormal (input.meta);
5665 return float32_t4 (normalize (normal)*0.5f +promote<float32_t3>(0.5f ),1.f );
5766}
0 commit comments