Skip to content

Commit 4f9dfb3

Browse files
committed
Added pre-atrous temporal accum
1 parent d70d2e4 commit 4f9dfb3

File tree

12 files changed

+110
-57
lines changed

12 files changed

+110
-57
lines changed

rttEngine/Rendering/Vulkan/VulkanLayer.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ VulkanLayer::VulkanLayer()
4040
atrousShader.Create();
4141
atrousPipeline.Create();
4242

43+
temporalShader = rttvk::Shader("Content/EngineLoad/Shaders/temporal.comp", &logicalDevice, VK_SHADER_STAGE_COMPUTE_BIT);
44+
temporalShader.Create();
45+
temporal.Create();
46+
4347
pipeline.Create();
4448
computeShader.Destroy();
4549

@@ -111,6 +115,16 @@ VulkanLayer::VulkanLayer()
111115
VK_CREATE_VALIDATION(vkAllocateDescriptorSets(logicalDevice.GetDevice(), &allocateInfo, &descSetAtrous));
112116

113117

118+
VK_CREATE_VALIDATION(vkCreateDescriptorPool(logicalDevice.GetDevice(), &poolCreateInfo, nullptr, &descPoolTemporal));
119+
120+
allocateInfo.descriptorPool = descPoolTemporal;
121+
allocateInfo.descriptorSetCount = 1;
122+
layout = temporal.GetDescriptorLayout();
123+
allocateInfo.pSetLayouts = &layout;
124+
125+
VK_CREATE_VALIDATION(vkAllocateDescriptorSets(logicalDevice.GetDevice(), &allocateInfo, &descSetTemporal));
126+
127+
114128

115129
resolutionBuffer = rttvk::Buffer(&logicalDevice, 12, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
116130
resolutionBuffer.Create();
@@ -732,11 +746,22 @@ void VulkanLayer::RecordCommandBuffer(uint32_t imageIndex)
732746
wds5.dstSet = descSetAtrous;
733747
wds6.dstSet = descSetAtrous;
734748

749+
750+
735751

736752

737753
VkWriteDescriptorSet wdssAtrous[] = { wds3,wds4, wds5,wds6, wds7,wds8 };
738754
vkUpdateDescriptorSets(logicalDevice.GetDevice(), 6, wdssAtrous, 0, nullptr);
739755

756+
wds3.dstSet = descSetTemporal;
757+
wds4.dstSet = descSetTemporal;
758+
wds7.dstSet = descSetTemporal;
759+
wds8.dstSet = descSetTemporal;
760+
wds9.dstSet = descSetTemporal;
761+
wds10.dstSet = descSetTemporal;
762+
VkWriteDescriptorSet wdssTemporal[] = { wds3,wds4, wds7,wds8, wds9,wds10 };
763+
vkUpdateDescriptorSets(logicalDevice.GetDevice(), 6, wdssTemporal, 0, nullptr);
764+
740765
VkCommandBufferBeginInfo beginInfo{};
741766
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
742767
vkBeginCommandBuffer(commandBuffer.GetBuffer(), &beginInfo);
@@ -751,9 +776,13 @@ void VulkanLayer::RecordCommandBuffer(uint32_t imageIndex)
751776

752777
vkCmdTraceRaysKHR(commandBuffer.GetBuffer(), &rgenRegion, &rmissRegion, &rchitRegion, &sbt_null, resolution[0], resolution[1], 1);
753778

754-
//vkCmdBindPipeline(commandBuffer.GetBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, atrousPipeline.GetPipeline());
755-
//vkCmdBindDescriptorSets(commandBuffer.GetBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, atrousPipeline.GetPipelineLayout(), 0, 1, &descSetAtrous, 0, nullptr);
756-
/*int atrousSize = 1;
779+
vkCmdBindPipeline(commandBuffer.GetBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, temporal.GetPipeline());
780+
vkCmdBindDescriptorSets(commandBuffer.GetBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, temporal.GetPipelineLayout(), 0, 1, &descSetTemporal, 0, nullptr);
781+
vkCmdDispatch(commandBuffer.GetBuffer(), resolution[0] / 32.0 + 1, resolution[1] / 32.0 + 1, 1);
782+
783+
vkCmdBindPipeline(commandBuffer.GetBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, atrousPipeline.GetPipeline());
784+
vkCmdBindDescriptorSets(commandBuffer.GetBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, atrousPipeline.GetPipelineLayout(), 0, 1, &descSetAtrous, 0, nullptr);
785+
int atrousSize = 1;
757786
vkCmdPushConstants(commandBuffer.GetBuffer(), atrousPipeline.GetPipelineLayout(), VK_SHADER_STAGE_COMPUTE_BIT, 0, 4, &atrousSize);
758787
vkCmdDispatch(commandBuffer.GetBuffer(), resolution[0]/32.0+1, resolution[1] / 32.0 + 1, 1);
759788
atrousSize = 2;
@@ -770,7 +799,7 @@ void VulkanLayer::RecordCommandBuffer(uint32_t imageIndex)
770799
vkCmdDispatch(commandBuffer.GetBuffer(), resolution[0] / 32.0 + 1, resolution[1] / 32.0 + 1, 1);
771800
atrousSize = 6;
772801
vkCmdPushConstants(commandBuffer.GetBuffer(), atrousPipeline.GetPipelineLayout(), VK_SHADER_STAGE_COMPUTE_BIT, 0, 4, &atrousSize);
773-
vkCmdDispatch(commandBuffer.GetBuffer(), resolution[0] / 32.0 + 1, resolution[1] / 32.0 + 1, 1);*/
802+
vkCmdDispatch(commandBuffer.GetBuffer(), resolution[0] / 32.0 + 1, resolution[1] / 32.0 + 1, 1);
774803

775804

776805

rttEngine/Rendering/Vulkan/VulkanLayer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class VulkanLayer : public RenderingLayer {
116116

117117
rttvk::Shader temporalShader = rttvk::Shader();
118118
std::vector<VkDescriptorSetLayoutBinding> setLayoutT = { directInputRT,indirectInputRT,direct2InputRT,indirect2InputRT,directPrevInputRT,indirectPrevInputRT };
119-
rttvk::Pipeline temporal = rttvk::Pipeline(&temporalShader, &logicalDevice, setLayout);
119+
rttvk::Pipeline temporal = rttvk::Pipeline(&temporalShader, &logicalDevice, setLayoutT);
120120
VkDescriptorPool descPoolTemporal;
121121
VkDescriptorSet descSetTemporal;
122122

rttGameTemplate/Content/EngineLoad/Shaders/atrous.comp

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ layout (binding = 15, rgba32f) uniform image2D indirect2ColorBuffer;
1212

1313
vec3 getDirectPixelColor(ivec2 pos) {
1414
if (waveletSize%2==0) {
15-
return imageLoad(direct2ColorBuffer,ivec2(pos+0.5)).xyz;
15+
return imageLoad(direct2ColorBuffer,ivec2(pos)).xyz;
1616
} else {
17-
return imageLoad(directColorBuffer,ivec2(pos+0.5)).xyz;
17+
return imageLoad(directColorBuffer,ivec2(pos)).xyz;
1818
}
1919
};
2020

2121
vec3 getInDirectPixelColor(ivec2 pos) {
2222
if (waveletSize%2==0) {
23-
return imageLoad(indirect2ColorBuffer,ivec2(pos+0.5)).xyz;
23+
return imageLoad(indirect2ColorBuffer,ivec2(pos)).xyz;
2424
} else {
25-
return imageLoad(indirectColorBuffer,ivec2(pos+0.5)).xyz;
25+
return imageLoad(indirectColorBuffer,ivec2(pos)).xyz;
2626
}
2727
};
2828
void main() {

rttGameTemplate/Content/EngineLoad/Shaders/raytracer.rmiss

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ layout(location = 0) rayPayloadInEXT hitPayload prd;
66

77
void main() {
88
prd.didHit = false;
9-
prd.color = vec3(0.7);
9+
prd.color = vec3(0.0, 0.0, 0.0);
1010
}

rttGameTemplate/Content/EngineLoad/Shaders/shader.comp

+42-44
Original file line numberDiff line numberDiff line change
@@ -43,53 +43,53 @@ void main() {
4343
bool shouldDraw = false;
4444
vec3 color = vec3(0.0);
4545
uint currentElement = 0;
46-
for(uint i = 0;i<hierarchySize;i++) {
47-
uint type = hierarchyBuffer.tree[currentElement];
48-
// Every field would have text
49-
uint lenght = hierarchyBuffer.tree[currentElement+1];
50-
uint lenght4b = uint(ceil(hierarchyBuffer.tree[currentElement+1]/4.0));
51-
// Every field would have size
52-
ivec2 minSize = ivec2(hierarchyBuffer.tree[currentElement+2+lenght4b],hierarchyBuffer.tree[currentElement+3+lenght4b]);
53-
ivec2 maxSize = ivec2(hierarchyBuffer.tree[currentElement+4+lenght4b],hierarchyBuffer.tree[currentElement+5+lenght4b]);
46+
// for(uint i = 0;i<hierarchySize;i++) {
47+
// uint type = hierarchyBuffer.tree[currentElement];
48+
// // Every field would have text
49+
// uint lenght = hierarchyBuffer.tree[currentElement+1];
50+
// uint lenght4b = uint(ceil(hierarchyBuffer.tree[currentElement+1]/4.0));
51+
// // Every field would have size
52+
// ivec2 minSize = ivec2(hierarchyBuffer.tree[currentElement+2+lenght4b],hierarchyBuffer.tree[currentElement+3+lenght4b]);
53+
// ivec2 maxSize = ivec2(hierarchyBuffer.tree[currentElement+4+lenght4b],hierarchyBuffer.tree[currentElement+5+lenght4b]);
5454

55-
if (checkIfInAABB(texCoord*resolution,vec4(minSize,maxSize))) {
56-
color = vec3(1.0);
57-
if (type == 1) {
55+
// if (checkIfInAABB(texCoord*resolution,vec4(minSize,maxSize))) {
56+
// color = vec3(1.0);
57+
// if (type == 1) {
5858

59-
//color = vec3(0.1);
60-
}
61-
// this code slows down an entire app
62-
if (type == 2 || type == 3) {
63-
shouldDraw = true;
64-
color = vec3(0.1);
65-
if (type == 2) {
66-
color = vec3(0.5,0.5333,0.7333);
67-
}
68-
for (int h = 0;h<lenght;h++) {
69-
vec2 letterMin = minSize+2+vec2(h*16,0);
70-
vec2 letterMax = minSize+18+vec2(h*16,0);
71-
if(checkIfInAABB(texCoord*resolution,vec4(letterMin,letterMax))) {
72-
uint letterRow = uint(floor(h/4.0));
73-
uint letterColumn = h%4;
74-
uint letterValue = (hierarchyBuffer.tree[currentElement+2+letterRow]>>(3-letterColumn)*8) & (0x000000ff);
75-
uint letterX = (letterValue & 0xf0)>>4;
76-
uint letterY = (letterValue & 0x0f);
77-
vec2 letterTexCoord = (texCoord*resolution-letterMin)/(letterMax-letterMin);
78-
letterTexCoord = (letterTexCoord+vec2(letterY,letterX))/16;
79-
if (texture(fontTexture,letterTexCoord).w>0.5) {
80-
color = vec3(1.0);
81-
}
82-
};
83-
};
84-
}
59+
// //color = vec3(0.1);
60+
// }
61+
// // this code slows down an entire app
62+
// if (type == 2 || type == 3) {
63+
// shouldDraw = true;
64+
// color = vec3(0.1);
65+
// if (type == 2) {
66+
// color = vec3(0.5,0.5333,0.7333);
67+
// }
68+
// for (int h = 0;h<lenght;h++) {
69+
// vec2 letterMin = minSize+2+vec2(h*16,0);
70+
// vec2 letterMax = minSize+18+vec2(h*16,0);
71+
// if(checkIfInAABB(texCoord*resolution,vec4(letterMin,letterMax))) {
72+
// uint letterRow = uint(floor(h/4.0));
73+
// uint letterColumn = h%4;
74+
// uint letterValue = (hierarchyBuffer.tree[currentElement+2+letterRow]>>(3-letterColumn)*8) & (0x000000ff);
75+
// uint letterX = (letterValue & 0xf0)>>4;
76+
// uint letterY = (letterValue & 0x0f);
77+
// vec2 letterTexCoord = (texCoord*resolution-letterMin)/(letterMax-letterMin);
78+
// letterTexCoord = (letterTexCoord+vec2(letterY,letterX))/16;
79+
// if (texture(fontTexture,letterTexCoord).w>0.5) {
80+
// color = vec3(1.0);
81+
// }
82+
// };
83+
// };
84+
// }
8585

8686

87-
}
88-
currentElement+=6+lenght4b;
89-
}
87+
// }
88+
// currentElement+=6+lenght4b;
89+
// }
9090
//vec4 color3 = vec4(imageLoad(albedoColorBuffer,screen_pos).xyz*(imageLoad(directColorBuffer,screen_pos).xyz+imageLoad(indirectColorBuffer,screen_pos).xyz),0.0);
91-
vec4 direct=imageLoad(prevDirectColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.8+imageLoad(directColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.2;
92-
vec4 indirect=imageLoad(prevIndirectColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.8+imageLoad(indirectColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.2;
91+
vec4 direct=imageLoad(directColorBuffer,ivec2(screen_pos+0.5)).xyzw;
92+
vec4 indirect=imageLoad(indirectColorBuffer,ivec2(screen_pos+0.5)).xyzw;
9393
vec4 albedo = imageLoad(albedoColorBuffer,ivec2(screen_pos+0.5));
9494
vec4 worldPosPrev = imageLoad(worldPosColorBuffer,ivec2(screen_pos+0.5));
9595
vec4 color3 = vec4(0.0);
@@ -105,8 +105,6 @@ void main() {
105105
} else {
106106
imageStore(colorBuffer,screen_pos,color3);
107107
}
108-
imageStore(direct2ColorBuffer,screen_pos,vec4(direct));
109-
imageStore(indirect2ColorBuffer,screen_pos,vec4(indirect));
110108
imageStore(albedoColorBuffer,screen_pos,vec4(color3));
111109
imageStore(prevWorldPosColorBuffer,screen_pos,vec4(worldPosPrev));
112110
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#version 460
2+
layout (local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
3+
4+
layout (binding = 10, rgba32f) uniform image2D directColorBuffer;
5+
layout (binding = 11, rgba32f) uniform image2D indirectColorBuffer;
6+
layout (binding = 14, rgba32f) uniform image2D direct2ColorBuffer;
7+
layout (binding = 15, rgba32f) uniform image2D indirect2ColorBuffer;
8+
layout (binding = 16, rgba32f) uniform image2D prevDirectColorBuffer;
9+
layout (binding = 17, rgba32f) uniform image2D prevIndirectColorBuffer;
10+
11+
void main() {
12+
ivec2 screen_pos = ivec2(gl_GlobalInvocationID.xy);
13+
vec4 direct=imageLoad(prevDirectColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.8+imageLoad(directColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.2;
14+
vec4 indirect=imageLoad(prevIndirectColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.8+imageLoad(indirectColorBuffer,ivec2(screen_pos+0.5)).xyzw*0.2;
15+
imageStore(directColorBuffer,screen_pos,vec4(direct));
16+
imageStore(indirectColorBuffer,screen_pos,vec4(indirect));
17+
imageStore(direct2ColorBuffer,screen_pos,vec4(direct));
18+
imageStore(indirect2ColorBuffer,screen_pos,vec4(indirect));
19+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

rttGameTemplate/Main/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void Init() {
2323

2424
Level* level = GetCurrentLevel();
2525
level->InitActor(&cam);
26-
level->InitActor(&sun);
26+
//level->InitActor(&sun);
2727
level->InitActor(&testMesh);
2828
testMesh.position = vec3(1, 1, 1);
2929
RTT_LOG("Inited");

rttGameTemplate/Source/Camera.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,15 @@ void Camera::Tick(float deltaTime)
9191

9292

9393

94-
95-
94+
light.pos[0] = 0;
95+
light.pos[1] = 4.5;
96+
light.pos[2] = 7;
97+
light.size = 1;
98+
99+
light.color[0] = 10;
100+
light.color[1] = 10;
101+
light.color[2] = 10;
102+
light.Render();
96103

97104

98105
}

0 commit comments

Comments
 (0)