Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 929 vs 933 for /trunk/Source Code/Rendering/PostFX/CustomOperators/BloomPreRenderOperator.cpp

Diff revisions: vs.
  @@ -78,9 +78,9 @@
78 78 }
79 79
80 80 // Order: luminance calc -> bloom -> tonemap
81 - void BloomPreRenderOperator::execute() {
81 + void BloomPreRenderOperator::execute(GFX::CommandBuffer& bufferInOut) {
82 82 PipelineDescriptor pipelineDescriptor;
83 - pipelineDescriptor._stateHash = _context.getDefaultStateBlock(true);
83 + pipelineDescriptor._stateHash = _context.get2DStateBlock();
84 84
85 85 GenericDrawCommand triangleCmd;
86 86 triangleCmd.primitiveType(PrimitiveType::TRIANGLES);
  @@ -88,44 +88,108 @@
88 88
89 89 RenderTargetHandle screen = _parent.inputRT();
90 90
91 + pipelineDescriptor._shaderProgram = _bloomCalc;
92 + GFX::BindPipelineCommand pipelineCmd;
93 + pipelineCmd._pipeline = _context.newPipeline(pipelineDescriptor);
94 + GFX::BindPipeline(bufferInOut, pipelineCmd);
95 +
91 96 // Step 1: generate bloom
92 - screen._rt->bind(to_U8(ShaderProgram::TextureUsage::UNIT0), RTAttachmentType::Colour, 0); //screen
97 + TextureData data = screen._rt->getAttachment(RTAttachmentType::Colour, 0).texture()->getData(); //screen
98 + data.setBinding(to_U32(ShaderProgram::TextureUsage::UNIT0));
99 +
100 + GFX::BindDescriptorSetsCommand descriptorSetCmd;
101 + descriptorSetCmd._set._textureData.addTexture(data);
102 + GFX::BindDescriptorSets(bufferInOut, descriptorSetCmd);
93 103
94 104 // render all of the "bright spots"
95 - _context.renderTargetPool().drawToTargetBegin(_bloomOutput._targetID);
96 - pipelineDescriptor._shaderProgram = _bloomCalc;
97 - _context.draw(triangleCmd, _context.newPipeline(pipelineDescriptor));
98 - _context.renderTargetPool().drawToTargetEnd();
105 + GFX::BeginRenderPassCommand beginRenderPassCmd;
106 + beginRenderPassCmd._target = _bloomOutput._targetID;
107 + GFX::BeginRenderPass(bufferInOut, beginRenderPassCmd);
108 +
109 + GFX::DrawCommand drawCmd;
110 + drawCmd._drawCommands.push_back(triangleCmd);
111 + GFX::AddDrawCommands(bufferInOut, drawCmd);
112 +
113 + GFX::EndRenderPassCommand endRenderPassCmd;
114 + GFX::EndRenderPass(bufferInOut, endRenderPassCmd);
99 115
100 116 // Step 2: blur bloom
101 - _blur->bind();
102 117 // Blur horizontally
103 - _blur->SetSubroutine(ShaderType::FRAGMENT, _horizBlur);
104 - _bloomOutput._rt->bind(to_U8(ShaderProgram::TextureUsage::UNIT0), RTAttachmentType::Colour, 0);
118 + pipelineDescriptor._shaderProgram = _blur;
119 + pipelineDescriptor._shaderFunctions[to_base(ShaderType::FRAGMENT)].push_back(_horizBlur);
120 + pipelineCmd._pipeline = _context.newPipeline(pipelineDescriptor);
121 + GFX::BindPipeline(bufferInOut, pipelineCmd);
122 +
123 + data = _bloomOutput._rt->getAttachment(RTAttachmentType::Colour, 0).texture()->getData();
124 + data.setBinding(to_U32(ShaderProgram::TextureUsage::UNIT0));
125 + descriptorSetCmd._set._textureData.clear();
126 + descriptorSetCmd._set._textureData.addTexture(data);
127 + GFX::BindDescriptorSets(bufferInOut, descriptorSetCmd);
128 +
129 + beginRenderPassCmd._target = _bloomBlurBuffer[0]._targetID;
130 + GFX::BeginRenderPass(bufferInOut, beginRenderPassCmd);
131 +
132 + GFX::SendPushConstantsCommand pushConstantsCommand;
133 + pushConstantsCommand._constants = _bloomCalcConstants;
134 + GFX::SendPushConstants(bufferInOut, pushConstantsCommand);
135 +
136 + GFX::AddDrawCommands(bufferInOut, drawCmd);
105 137
106 - Pipeline blurPipeline = _context.newPipeline(pipelineDescriptor);
107 - _context.renderTargetPool().drawToTargetBegin(_bloomBlurBuffer[0]._targetID);
108 - pipelineDescriptor._shaderProgram = _blur;
109 - _context.draw(triangleCmd, blurPipeline, _bloomCalcConstants);
110 - _context.renderTargetPool().drawToTargetEnd();
138 + GFX::EndRenderPass(bufferInOut, endRenderPassCmd);
111 139
112 140 // Blur vertically (recycle the render target. We have a copy)
113 - _blur->SetSubroutine(ShaderType::FRAGMENT, _vertBlur);
114 - _bloomBlurBuffer[0]._rt->bind(to_U8(ShaderProgram::TextureUsage::UNIT0), RTAttachmentType::Colour, 0);
115 -
116 - _context.renderTargetPool().drawToTargetBegin(_bloomBlurBuffer[1]._targetID);
117 - _context.draw(triangleCmd, blurPipeline, _bloomCalcConstants);
118 - _context.renderTargetPool().drawToTargetEnd();
141 + pipelineDescriptor._shaderProgram = _blur;
142 + pipelineDescriptor._shaderFunctions[to_base(ShaderType::FRAGMENT)][0] = _vertBlur;
143 + pipelineCmd._pipeline = _context.newPipeline(pipelineDescriptor);
144 + GFX::BindPipeline(bufferInOut, pipelineCmd);
145 +
146 + data = _bloomBlurBuffer[0]._rt->getAttachment(RTAttachmentType::Colour, 0).texture()->getData();
147 + data.setBinding(to_U32(ShaderProgram::TextureUsage::UNIT0));
148 + descriptorSetCmd._set._textureData.clear();
149 + descriptorSetCmd._set._textureData.addTexture(data);
150 + GFX::BindDescriptorSets(bufferInOut, descriptorSetCmd);
151 +
152 + beginRenderPassCmd._target = _bloomBlurBuffer[1]._targetID;
153 + GFX::BeginRenderPass(bufferInOut, beginRenderPassCmd);
154 + GFX::SendPushConstants(bufferInOut, pushConstantsCommand);
155 +
156 + GFX::AddDrawCommands(bufferInOut, drawCmd);
157 +
158 + GFX::EndRenderPass(bufferInOut, endRenderPassCmd);
119 159
120 160 // Step 3: apply bloom
121 - _bloomBlurBuffer[0]._rt->blitFrom(screen._rt);
122 - _bloomBlurBuffer[0]._rt->bind(to_U8(ShaderProgram::TextureUsage::UNIT0), RTAttachmentType::Colour, 0); //Screen
123 - _bloomBlurBuffer[1]._rt->bind(to_U8(ShaderProgram::TextureUsage::UNIT1), RTAttachmentType::Colour, 0); //Bloom
124 -
125 - _context.renderTargetPool().drawToTargetBegin(screen._targetID, _screenOnlyDraw);
126 - pipelineDescriptor._shaderProgram = _bloomApply;
127 - _context.draw(triangleCmd, _context.newPipeline(pipelineDescriptor), _bloomApplyConstants);
128 - _context.renderTargetPool().drawToTargetEnd();
161 + GFX::BlitRenderTargetCommand blitRTCommand;
162 + blitRTCommand._source = screen._targetID;
163 + blitRTCommand._destination = _bloomBlurBuffer[0]._targetID;
164 + GFX::BlitRenderTarget(bufferInOut, blitRTCommand);
165 +
166 + TextureData data0 = _bloomBlurBuffer[0]._rt->getAttachment(RTAttachmentType::Colour, 0).texture()->getData(); //Screen
167 + data0.setBinding(to_U32(ShaderProgram::TextureUsage::UNIT0));
168 + TextureData data1 = _bloomBlurBuffer[1]._rt->getAttachment(RTAttachmentType::Colour, 0).texture()->getData(); //Bloom
169 + data1.setBinding(to_U32(ShaderProgram::TextureUsage::UNIT1));
170 +
171 + data = _bloomBlurBuffer[0]._rt->getAttachment(RTAttachmentType::Colour, 0).texture()->getData();
172 + data.setBinding(to_U32(ShaderProgram::TextureUsage::UNIT0));
173 + descriptorSetCmd._set._textureData.clear();
174 + descriptorSetCmd._set._textureData.addTexture(data0);
175 + descriptorSetCmd._set._textureData.addTexture(data1);
176 + GFX::BindDescriptorSets(bufferInOut, descriptorSetCmd);
177 +
178 + pipelineDescriptor._shaderProgram = _bloomApply;
179 + pipelineDescriptor._shaderFunctions[to_base(ShaderType::FRAGMENT)].clear();
180 + pipelineCmd._pipeline = _context.newPipeline(pipelineDescriptor);
181 + GFX::BindPipeline(bufferInOut, pipelineCmd);
182 +
183 + pushConstantsCommand._constants = _bloomApplyConstants;
184 + GFX::SendPushConstants(bufferInOut, pushConstantsCommand);
185 +
186 + beginRenderPassCmd._target = screen._targetID;
187 + beginRenderPassCmd._descriptor = _screenOnlyDraw;
188 + GFX::BeginRenderPass(bufferInOut, beginRenderPassCmd);
189 +
190 + GFX::AddDrawCommands(bufferInOut, drawCmd);
191 +
192 + GFX::EndRenderPass(bufferInOut, endRenderPassCmd);
129 193 }
130 194
131 195 void BloomPreRenderOperator::debugPreview(U8 slot) const {