Skip to content

Commit 89fa6d0

Browse files
committed
add grid renderpass to the scene, perform tests
1 parent 4371b0e commit 89fa6d0

File tree

9 files changed

+403
-154
lines changed

9 files changed

+403
-154
lines changed

64_Gizmo/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@ set(NBL_THIS_EXAMPLE_OUTPUT_SPIRV_DIRECTORY "${_THIS_EXAMPLE_SPIRV_BR_BUNDLE_SEA
99

1010
# list of input source shaders
1111
set(NBL_THIS_EXAMPLE_INPUT_SHADERS
12-
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/vertex.hlsl"
13-
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/fragment.hlsl"
12+
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/cube.vertex.hlsl"
13+
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/cube.fragment.hlsl"
14+
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/grid.vertex.hlsl"
15+
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/grid.fragment.hlsl"
1416
)
1517

1618
set(NBL_THIS_EXAMPLE_INPUT_COMMONS
1719
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/common.hlsl"
20+
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/cube.common.hlsl"
21+
"${NBL_THIS_EXAMPLE_INPUT_SHADERS_DIRECTORY}/grid.common.hlsl"
1822
)
1923

2024
include("${NBL_ROOT_PATH}/src/nbl/builtin/utils.cmake")
2125

2226
foreach(NBL_INPUT_SHADER IN LISTS NBL_THIS_EXAMPLE_INPUT_SHADERS)
23-
cmake_path(GET NBL_INPUT_SHADER STEM NBL_SHADER_STEM)
27+
cmake_path(GET NBL_INPUT_SHADER STEM LAST_ONLY NBL_SHADER_STEM)
28+
cmake_path(GET NBL_SHADER_STEM EXTENSION NBL_SHADER_TYPE)
2429
set(NBL_OUTPUT_SPIRV_FILENAME "${NBL_SHADER_STEM}.spv")
2530
set(NBL_OUTPUT_SPIRV_PATH "${NBL_THIS_EXAMPLE_OUTPUT_SPIRV_DIRECTORY}/${NBL_OUTPUT_SPIRV_FILENAME}")
2631

27-
if(NBL_SHADER_STEM STREQUAL vertex)
32+
if(NBL_SHADER_TYPE STREQUAL .vertex)
2833
set(NBL_NSC_COMPILE_OPTIONS -T vs_6_7 -E VSMain)
29-
elseif(NBL_SHADER_STEM STREQUAL fragment)
34+
elseif(NBL_SHADER_TYPE STREQUAL .fragment)
3035
set(NBL_NSC_COMPILE_OPTIONS -T ps_6_7 -E PSMain)
3136
else()
32-
message(FATAL_ERROR "internal error")
37+
message(FATAL_ERROR "Input shader is supposed to be <name>.<shader type>.hlsl!")
3338
endif()
3439

3540
set(NBL_NSC_COMPILE_COMMAND

64_Gizmo/main.cpp

Lines changed: 253 additions & 115 deletions
Large diffs are not rendered by default.

64_Gizmo/shaders/common.hlsl

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
1-
#ifdef __HLSL_VERSION
2-
struct VSInput
3-
{
4-
[[vk::location(0)]] float4 position : POSITION;
5-
[[vk::location(1)]] float4 color : COLOR0;
6-
};
7-
8-
struct PSInput
9-
{
10-
float4 position : SV_Position;
11-
float4 color : COLOR0;
12-
};
13-
14-
struct SBasicViewParameters //! matches CPU version size & alignment (160, 4)
15-
{
16-
float4x4 MVP;
17-
float3x4 MV;
18-
float3x3 normalMat;
19-
};
20-
#else
21-
#include "nbl/nblpack.h"
22-
struct VSInput
23-
{
24-
float position[4];
25-
float color[4];
26-
} PACK_STRUCT;
27-
#include "nbl/nblunpack.h"
28-
29-
static_assert(sizeof(VSInput) == sizeof(float) * 4 * 2);
30-
#endif // __HLSL_VERSION
1+
#ifndef _THIS_EXAMPLE_COMMON_HLSL_
2+
#define _THIS_EXAMPLE_COMMON_HLSL_
313

324
struct PushConstants
335
{
346
bool withGizmo;
357

368
bool padding[3]; //! size of PushConstants must be multiple of 4
37-
};
9+
};
10+
11+
#ifdef __HLSL_VERSION
12+
struct SBasicViewParameters //! matches CPU version size & alignment (160, 4)
13+
{
14+
float4x4 MVP;
15+
float3x4 MV;
16+
float3x3 normalMat;
17+
};
18+
#endif // __HLSL_VERSION
19+
20+
#endif
21+
22+
/*
23+
do not remove this text, WAVE is so bad that you can get errors if no proper ending xD
24+
*/

64_Gizmo/shaders/cube.common.hlsl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef _THIS_EXAMPLE_CUBE_COMMON_HLSL_
2+
#define _THIS_EXAMPLE_CUBE_COMMON_HLSL_
3+
4+
#ifdef __HLSL_VERSION
5+
struct VSInput
6+
{
7+
[[vk::location(0)]] float4 position : POSITION;
8+
[[vk::location(1)]] float4 color : COLOR0;
9+
};
10+
11+
struct PSInput
12+
{
13+
float4 position : SV_Position;
14+
float4 color : COLOR0;
15+
};
16+
#else
17+
namespace cube
18+
{
19+
#include "nbl/nblpack.h"
20+
struct VSInput
21+
{
22+
float position[4];
23+
float color[4];
24+
} PACK_STRUCT;
25+
#include "nbl/nblunpack.h"
26+
}
27+
28+
static_assert(sizeof(cube::VSInput) == sizeof(float) * 4 * 2);
29+
#endif // __HLSL_VERSION
30+
31+
#include "common.hlsl"
32+
33+
#endif // _THIS_EXAMPLE_CUBE_COMMON_HLSL_
34+
35+
/*
36+
do not remove this text, WAVE is so bad that you can get errors if no proper ending xD
37+
*/

64_Gizmo/shaders/fragment.hlsl renamed to 64_Gizmo/shaders/cube.fragment.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "common.hlsl"
1+
#include "cube.common.hlsl"
22

33
float4 PSMain(PSInput input) : SV_Target0
44
{

64_Gizmo/shaders/vertex.hlsl renamed to 64_Gizmo/shaders/cube.vertex.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "common.hlsl"
1+
#include "cube.common.hlsl"
22

33
[[vk::push_constant]] struct PushConstants pc;
44

64_Gizmo/shaders/grid.common.hlsl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef _THIS_EXAMPLE_GRID_COMMON_HLSL_
2+
#define _THIS_EXAMPLE_GRID_COMMON_HLSL_
3+
4+
#ifdef __HLSL_VERSION
5+
struct VSInput
6+
{
7+
[[vk::location(0)]] float3 position : POSITION;
8+
[[vk::location(1)]] float2 uv : TEXCOORD0;
9+
};
10+
11+
struct PSInput
12+
{
13+
float4 position : SV_Position;
14+
float2 uv : TEXCOORD0;
15+
};
16+
17+
float gridTextureGradBox(float2 p, float2 ddx, float2 ddy)
18+
{
19+
float N = 30.0; // grid ratio
20+
float2 w = max(abs(ddx), abs(ddy)) + 0.01; // filter kernel
21+
22+
// analytic (box) filtering
23+
float2 a = p + 0.5 * w;
24+
float2 b = p - 0.5 * w;
25+
float2 i = (floor(a) + min(frac(a) * N, 1.0) - floor(b) - min(frac(b) * N, 1.0)) / (N * w);
26+
27+
// pattern
28+
return (1.0 - i.x) * (1.0 - i.y);
29+
}
30+
#else
31+
namespace grid
32+
{
33+
#include "nbl/nblpack.h"
34+
struct VSInput
35+
{
36+
float position[3];
37+
float uv[2];
38+
} PACK_STRUCT;
39+
#include "nbl/nblunpack.h"
40+
}
41+
42+
static_assert(sizeof(grid::VSInput) == sizeof(float) * (3 + 2));
43+
#endif // __HLSL_VERSION
44+
45+
#include "common.hlsl"
46+
47+
#endif // _THIS_EXAMPLE_GRID_COMMON_HLSL_
48+
49+
/*
50+
do not remove this text, WAVE is so bad that you can get errors if no proper ending xD
51+
*/

64_Gizmo/shaders/grid.fragment.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "grid.common.hlsl"
2+
3+
float4 PSMain(PSInput input) : SV_Target0
4+
{
5+
float2 uv = (input.uv - float2(0.5, 0.5)) + 0.5 / 30.0;
6+
float grid = gridTextureGradBox(uv, ddx(input.uv), ddy(input.uv));
7+
float4 fragColor = float4(1.0 - grid, 1.0 - grid, 1.0 - grid, 1.0);
8+
fragColor *= 0.25;
9+
fragColor *= 0.3 + 0.6 * smoothstep(0.0, 0.1, 1.0 - length(input.uv) / 5.5);
10+
11+
return fragColor;
12+
}

64_Gizmo/shaders/grid.vertex.hlsl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "grid.common.hlsl"
2+
3+
[[vk::push_constant]] struct PushConstants pc;
4+
5+
// set 1, binding 0
6+
[[vk::binding(0, 1)]]
7+
cbuffer CameraData
8+
{
9+
SBasicViewParameters params;
10+
};
11+
12+
PSInput VSMain(VSInput input)
13+
{
14+
PSInput output;
15+
output.position = mul(params.MVP, float4(input.position, 1.0));
16+
output.uv = (input.uv - float2(0.5, 0.5)) * abs(input.position.xy);
17+
18+
return output;
19+
}

0 commit comments

Comments
 (0)