Add some shaders
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,14 @@
|
||||
#ifndef __Shaders_h_included
|
||||
#define __Shaders_h_included
|
||||
|
||||
/* Contents of file background.frag.spv */
|
||||
extern const long int background_frag_spv_size;
|
||||
extern const unsigned char background_frag_spv[1044];
|
||||
|
||||
/* Contents of file background.vert.spv */
|
||||
extern const long int background_vert_spv_size;
|
||||
extern const unsigned char background_vert_spv[2844];
|
||||
|
||||
/* Contents of file basic.frag.spv */
|
||||
extern const long int basic_frag_spv_size;
|
||||
extern const unsigned char basic_frag_spv[376];
|
||||
@@ -10,6 +18,18 @@ extern const unsigned char basic_frag_spv[376];
|
||||
extern const long int basic_vert_spv_size;
|
||||
extern const unsigned char basic_vert_spv[2824];
|
||||
|
||||
/* Contents of file grid.frag.spv */
|
||||
extern const long int grid_frag_spv_size;
|
||||
extern const unsigned char grid_frag_spv[6440];
|
||||
|
||||
/* Contents of file grid.vert.spv */
|
||||
extern const long int grid_vert_spv_size;
|
||||
extern const unsigned char grid_vert_spv[3308];
|
||||
|
||||
/* Contents of file pointCloud.vert.spv */
|
||||
extern const long int pointCloud_vert_spv_size;
|
||||
extern const unsigned char pointCloud_vert_spv[2812];
|
||||
|
||||
/* File table comprising original file name, address and size */
|
||||
typedef struct {
|
||||
const char *entryName;
|
||||
|
||||
27
openVulkanoCpp/Shader/background.frag
Normal file
27
openVulkanoCpp/Shader/background.frag
Normal file
@@ -0,0 +1,27 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 0) uniform sampler2D camTexture;
|
||||
#ifdef ENABLE_DEPTH_WRITE
|
||||
layout (binding = 1) uniform sampler2D depthMap;
|
||||
#endif
|
||||
|
||||
layout (location = 0) in vec2 texCoords;
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, push_constant) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
float near;
|
||||
float far;
|
||||
} cam;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(camTexture, texCoords);
|
||||
#ifdef ENABLE_DEPTH_WRITE
|
||||
gl_FragDepth = (texture(depthMap, texCoords).r - cam.near) / (cam.far - cam.near);
|
||||
#endif
|
||||
}
|
||||
39
openVulkanoCpp/Shader/background.vert
Normal file
39
openVulkanoCpp/Shader/background.vert
Normal file
@@ -0,0 +1,39 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(std140, push_constant) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
float nearPlane;
|
||||
float farPlane;
|
||||
float width;
|
||||
float height;
|
||||
float fov;
|
||||
float aspect;
|
||||
} cam;
|
||||
|
||||
// Grid position are in clipped space
|
||||
vec4 gridPlane[4] = vec4[] (
|
||||
vec4(1, 1, 0, 1), vec4(-1, 1, 0, 1), vec4(1, -1, 0, 1), vec4(-1, -1, 0, 1)
|
||||
);
|
||||
|
||||
float realFov = 53;
|
||||
float realAspect = 1.33333333;
|
||||
|
||||
void main() {
|
||||
float virtualAspect = cam.width / cam.height;
|
||||
vec4 position = gridPlane[gl_VertexIndex];
|
||||
|
||||
// Calculate the scaling factors for width and height
|
||||
float scaleX = tan(radians(cam.fov * 0.5)) / tan(radians(realFov * 0.5));
|
||||
float scaleY = virtualAspect / realAspect * scaleX;
|
||||
|
||||
// Scale the quad's position
|
||||
position.xy *= vec2(scaleX, scaleY);
|
||||
|
||||
// Pass the transformed position to the fragment shader
|
||||
gl_Position = position;
|
||||
}
|
||||
46
openVulkanoCpp/Shader/pointCloud.vert
Normal file
46
openVulkanoCpp/Shader/pointCloud.vert
Normal file
@@ -0,0 +1,46 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec4 position;
|
||||
layout(location = 1) in vec4 normal;
|
||||
layout(location = 2) in vec4 color;
|
||||
layout(location = 3) in float weight;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(binding = 0) uniform NodeData
|
||||
{
|
||||
mat4 world;
|
||||
} node;
|
||||
|
||||
layout(std140, push_constant) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
} cam;
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec4 worldPos = node.world * position;
|
||||
vec4 worldPos = node.world[3] + position;
|
||||
worldPos.w = 1;
|
||||
|
||||
//float discardHelper = 0;
|
||||
float discardHelper = normal.a * 3;
|
||||
vec3 camDir = (worldPos - cam.camPos).xyz;
|
||||
// normal culling
|
||||
if (dot(normal.xyz, camDir) > 0)
|
||||
{
|
||||
discardHelper += 3;
|
||||
}
|
||||
|
||||
outColor = color;
|
||||
//outColor = normal / 2 + 0.5f;
|
||||
//outColor = vec4(weight/10, weight / 50, weight / 100, 1);
|
||||
//gl_Position = normalize(cam.viewProjection * worldPos);
|
||||
gl_Position = cam.viewProjection * worldPos;
|
||||
gl_PointSize = max(1, 4 - dot(camDir, camDir) / 2);
|
||||
|
||||
gl_Position.z += discardHelper;
|
||||
}
|
||||
Reference in New Issue
Block a user