Textured quad with proper view projection
This commit is contained in:
parent
0c7aad9070
commit
05f2deb5df
@ -92,7 +92,7 @@ layout(location = 0) out vec4 FragColor;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 hdr_color = texture(sampler2D(global_textures2d[PushConstants.scene_color_texture], global_samplers[PushConstants.scene_color_sampler]), VertexOut.uv).rgb;
|
vec3 hdr_color = texture(sampler2D(global_textures2d[PushConstants.scene_color_texture], global_samplers[PushConstants.scene_color_sampler]), VertexOut.uv).rgb;
|
||||||
hdr_color = ACESFitted(hdr_color);
|
hdr_color = pow(hdr_color, vec3(1.0f/2.2f)); // ACESFitted(hdr_color);
|
||||||
|
|
||||||
FragColor.rgb = hdr_color;
|
FragColor.rgb = hdr_color;
|
||||||
FragColor.a = 1;
|
FragColor.a = 1;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"vertex": "triangle.glsl",
|
"vertex": "unlit.glsl",
|
||||||
"fragment": "triangle.glsl",
|
"fragment": "unlit.glsl",
|
||||||
"compute": null,
|
"compute": null,
|
||||||
"color_attachment_type": "main",
|
"color_attachment_type": "main",
|
||||||
"depth_stencil_attachment": true
|
"depth_stencil_attachment": true
|
||||||
|
@ -1,30 +1,46 @@
|
|||||||
#extension GL_ARB_bindless_texture : require
|
#extension GL_EXT_buffer_reference : require
|
||||||
|
#extension GL_EXT_scalar_block_layout : require
|
||||||
|
#extension GL_EXT_nonuniform_qualifier : require
|
||||||
|
|
||||||
#include "camera.glsl"
|
#include "global.glsl"
|
||||||
|
|
||||||
// Uniforms
|
|
||||||
layout(location = 1) uniform mat4 model;
|
|
||||||
|
|
||||||
layout(location = 2) uniform vec3 color;
|
|
||||||
|
|
||||||
// Input, output blocks
|
|
||||||
|
|
||||||
#if VERTEX_SHADER
|
#if VERTEX_SHADER
|
||||||
|
|
||||||
layout(location = 0) in vec3 aPos;
|
// QUAD
|
||||||
|
vec2 positions[6] = vec2[](
|
||||||
|
vec2(-1, -1),
|
||||||
|
vec2(-1, 1),
|
||||||
|
vec2(1, 1),
|
||||||
|
|
||||||
|
vec2(1, 1),
|
||||||
|
vec2(1, -1),
|
||||||
|
vec2(-1, -1)
|
||||||
|
);
|
||||||
|
|
||||||
|
layout(location = 0) out vec2 OutUV;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = projection * view * model * vec4(aPos.xyz, 1.0);
|
OutUV = positions[gl_VertexIndex] * 0.5 + 0.5;
|
||||||
|
OutUV.y = 1 - OutUV.y;
|
||||||
|
|
||||||
|
gl_Position = vec4(positions[gl_VertexIndex] + vec2(gl_InstanceIndex, 0), gl_InstanceIndex, 1.0) * Global.view.world_to_clip;
|
||||||
}
|
}
|
||||||
#endif // VERTEX_SHADER
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FRAGMENT_SHADER
|
#if FRAGMENT_SHADER
|
||||||
|
|
||||||
out vec4 FragColor;
|
layout(location = 0) in vec2 InUV;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
|
layout(push_constant, std430) uniform constants {
|
||||||
|
uint color_texture;
|
||||||
|
uint color_sampler;
|
||||||
|
} PushConstants;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FragColor = vec4(color, 1.0f);
|
FragColor = vec4(texture(sampler2D(global_textures2d[PushConstants.color_texture], global_samplers[PushConstants.color_sampler]), InUV).rgb, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif // FRAGMNET_SHADER
|
|
||||||
|
7
assets/shaders/unlit.prog
Normal file
7
assets/shaders/unlit.prog
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"vertex": "unlit.glsl",
|
||||||
|
"fragment": "unlit.glsl",
|
||||||
|
"compute": null,
|
||||||
|
"color_attachment_type": "main",
|
||||||
|
"depth_stencil_attachment": true
|
||||||
|
}
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"shader": "unlit.glsl",
|
|
||||||
"vertex": true,
|
|
||||||
"fragment": true,
|
|
||||||
"compute": false
|
|
||||||
}
|
|
@ -440,7 +440,14 @@ pub fn draw(self: *Render2) !void {
|
|||||||
|
|
||||||
const global_uniform = blk: {
|
const global_uniform = blk: {
|
||||||
const view = self.camera.view_mat;
|
const view = self.camera.view_mat;
|
||||||
const projection = self.camera.projection();
|
const projection = self.camera.projection().mul(Mat4{
|
||||||
|
.data = .{
|
||||||
|
.{ 1, 0, 0, 0 },
|
||||||
|
.{ 0, 1, 0, 0 },
|
||||||
|
.{ 0, 0, 1, 0 },
|
||||||
|
.{ 0, 0, 0, 1 },
|
||||||
|
},
|
||||||
|
});
|
||||||
const view_projection = projection.mul(view);
|
const view_projection = projection.mul(view);
|
||||||
|
|
||||||
break :blk GlobalUniform{
|
break :blk GlobalUniform{
|
||||||
@ -558,11 +565,16 @@ pub fn draw(self: *Render2) !void {
|
|||||||
cmds.setDepthWriteEnable(vk.TRUE);
|
cmds.setDepthWriteEnable(vk.TRUE);
|
||||||
cmds.setDepthCompareOp(.greater);
|
cmds.setDepthCompareOp(.greater);
|
||||||
|
|
||||||
const triangle = self.assetman.resolveShaderProgram(a.ShaderPrograms.shaders.triangle);
|
const unlit = self.assetman.resolveShaderProgram(a.ShaderPrograms.shaders.unlit);
|
||||||
|
|
||||||
cmds.bindPipeline(.graphics, triangle.pipeline);
|
cmds.bindPipeline(.graphics, unlit.pipeline);
|
||||||
cmds.bindDescriptorSets(.graphics, self.descriptorman.pipeline_layout, 0, 1, &.{global_descriptor_set}, 0, null);
|
cmds.bindDescriptorSets(.graphics, self.descriptorman.pipeline_layout, 0, 1, &.{global_descriptor_set}, 0, null);
|
||||||
|
|
||||||
|
self.pushConstants(cmds, .{ .vertex_bit = true, .fragment_bit = true }, UnlitPushConstants{
|
||||||
|
.color_texture = self.assetman.resolveTexture(a.Textures.bunny_tex1).descriptor_handle.index,
|
||||||
|
.color_sampler = self.screen_color_sampler_descriptor_handle.index,
|
||||||
|
});
|
||||||
|
|
||||||
cmds.setViewportWithCount(1, &.{vk.Viewport{
|
cmds.setViewportWithCount(1, &.{vk.Viewport{
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = 0,
|
.y = 0,
|
||||||
@ -576,7 +588,7 @@ pub fn draw(self: *Render2) !void {
|
|||||||
.extent = gc.swapchain_extent,
|
.extent = gc.swapchain_extent,
|
||||||
}});
|
}});
|
||||||
|
|
||||||
cmds.draw(3, 2, 0, 0);
|
cmds.draw(6, 2, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post process and convert from f16 to rgba8_unorm
|
// Post process and convert from f16 to rgba8_unorm
|
||||||
@ -629,7 +641,7 @@ pub fn draw(self: *Render2) !void {
|
|||||||
cmds.bindDescriptorSets(.graphics, self.descriptorman.pipeline_layout, 0, 1, &.{global_descriptor_set}, 0, null);
|
cmds.bindDescriptorSets(.graphics, self.descriptorman.pipeline_layout, 0, 1, &.{global_descriptor_set}, 0, null);
|
||||||
|
|
||||||
self.pushConstants(cmds, .{ .vertex_bit = true, .fragment_bit = true }, PostProcessPushConstants{
|
self.pushConstants(cmds, .{ .vertex_bit = true, .fragment_bit = true }, PostProcessPushConstants{
|
||||||
.scene_color_texture = self.assetman.resolveTexture(a.Textures.bunny_tex1).descriptor_handle.index,
|
.scene_color_texture = main_render_target.color_descriptor.index(),
|
||||||
.scene_color_sampler = self.screen_color_sampler_descriptor_handle.index,
|
.scene_color_sampler = self.screen_color_sampler_descriptor_handle.index,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -787,6 +799,11 @@ const GlobalUniform = extern struct {
|
|||||||
view: View,
|
view: View,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const UnlitPushConstants = extern struct {
|
||||||
|
color_texture: u32,
|
||||||
|
color_sampler: u32,
|
||||||
|
};
|
||||||
|
|
||||||
const PostProcessPushConstants = extern struct {
|
const PostProcessPushConstants = extern struct {
|
||||||
scene_color_texture: u32,
|
scene_color_texture: u32,
|
||||||
scene_color_sampler: u32,
|
scene_color_sampler: u32,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user