wren
Vulkan-based game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
editor_scene.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <string_view>
4
5
namespace
wren::shaders
{
6
7
const
std::string_view
kEditorVertShader
= R
"(
8
#version 450
9
10
layout(set = 0, binding = 0) uniform GLOBALS {
11
mat4 view;
12
mat4 proj;
13
} globals;
14
15
layout(location = 1) out vec3 near_point;
16
layout(location = 2) out vec3 far_point;
17
18
vec3 grid_plane[6] = vec3[](
19
vec3(1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0),
20
vec3(-1, -1, 0), vec3(1, 1, 0), vec3(1, -1, 0)
21
);
22
23
vec3 UnprojectPoint(float x, float y, float z, mat4 view, mat4 projection) {
24
mat4 view_inv = inverse(view);
25
mat4 proj_inv = inverse(projection);
26
27
vec4 unprojected_point = view_inv * proj_inv * vec4(x, y, z, 1.0);
28
29
return unprojected_point.xyz / unprojected_point.w;
30
}
31
32
void main() {
33
vec3 p = grid_plane[gl_VertexIndex].xyz;
34
near_point = UnprojectPoint(p.x, p.y, 0.0, globals.view, globals.proj).xyz;
35
far_point = UnprojectPoint(p.x, p.y, 1.0, globals.view, globals.proj).xyz;
36
37
gl_Position = vec4(p, 1.0);
38
}
39
)";
40
41
const
std::string_view
kEditorFragShader
= R
"(
42
#version 450
43
44
layout(location = 0) out vec4 out_colour;
45
46
layout(location = 1) in vec3 near_point;
47
layout(location = 2) in vec3 far_point;
48
49
void main() {
50
float t = -near_point.y / (far_point.y - near_point.y);
51
// out_colour = vec4(1.0, 0.0, 0.0, 1.0 * float(t > 0));
52
out_colour = vec4(1.0, 0.0, 0.0, t);
53
}
54
55
)";
56
57
}
// namespace wren::shaders
wren::shaders
Definition
editor_scene.hpp:5
wren::shaders::kEditorFragShader
const std::string_view kEditorFragShader
Definition
editor_scene.hpp:41
wren::shaders::kEditorVertShader
const std::string_view kEditorVertShader
Definition
editor_scene.hpp:7
editor
src
shaders
editor_scene.hpp
Generated by
1.17.0