Browse Source

Now It's Grey

Heedong Arkiny Lee 5 years ago
parent
commit
e94ace574f

+ 6
- 24
Samples/ComputeShader/ComputeShader.cpp View File

46
         // setup vertex buffer and attributes
46
         // setup vertex buffer and attributes
47
         vertexDesc.attributes = {
47
         vertexDesc.attributes = {
48
             { DKVertexFormat::Float3, offsetof(UVQuad::Vertex, Pos), 0, 0 },
48
             { DKVertexFormat::Float3, offsetof(UVQuad::Vertex, Pos), 0, 0 },
49
-            { DKVertexFormat::Float2, offsetof(UVQuad::Vertex, UV), 0, 2 },
49
+            { DKVertexFormat::Float2, offsetof(UVQuad::Vertex, UV), 0, 1 },
50
         };
50
         };
51
         vertexDesc.layouts = {
51
         vertexDesc.layouts = {
52
             { DKVertexStepRate::Vertex, sizeof(UVQuad::Vertex), 0 },
52
             { DKVertexStepRate::Vertex, sizeof(UVQuad::Vertex), 0 },
85
             texDesc.mipmapLevels = 1;
85
             texDesc.mipmapLevels = 1;
86
             texDesc.sampleCount = 1;
86
             texDesc.sampleCount = 1;
87
             texDesc.arrayLength = 1;
87
             texDesc.arrayLength = 1;
88
-            texDesc.usage = DKTexture::UsageShaderRead | DKTexture::UsageShaderWrite;
88
+            texDesc.usage = DKTexture::UsageShaderRead | DKTexture::UsageShaderWrite | DKTexture::UsageSampled;
89
             textureTarget = device->CreateTexture(texDesc);
89
             textureTarget = device->CreateTexture(texDesc);
90
         }
90
         }
91
 
91
 
125
     {
125
     {
126
         DKMatrix4 projectionMatrix;
126
         DKMatrix4 projectionMatrix;
127
         DKMatrix4 modelMatrix;
127
         DKMatrix4 modelMatrix;
128
-        DKMatrix4 viewMatrix;
129
     };
128
     };
130
 private:
129
 private:
131
     DKShaderBindingSetLayout descriptorSetLayout;
130
     DKShaderBindingSetLayout descriptorSetLayout;
173
                 ubo = reinterpret_cast<UBO*>(uniformBuffer->Contents());
172
                 ubo = reinterpret_cast<UBO*>(uniformBuffer->Contents());
174
                 ubo->projectionMatrix = DKMatrix4::identity;
173
                 ubo->projectionMatrix = DKMatrix4::identity;
175
                 ubo->modelMatrix = DKMatrix4::identity;
174
                 ubo->modelMatrix = DKMatrix4::identity;
176
-                ubo->viewMatrix = DKMatrix4::identity;
177
                 uniformBuffer->Flush();
175
                 uniformBuffer->Flush();
178
 
176
 
179
                 descriptorSetPreCompute->SetBuffer(0, uniformBuffer, 0, sizeof(UBO));
177
                 descriptorSetPreCompute->SetBuffer(0, uniformBuffer, 0, sizeof(UBO));
272
         DKObject<DKCommandQueue> graphicsQueue = device->CreateCommandQueue(DKCommandQueue::Graphics);
270
         DKObject<DKCommandQueue> graphicsQueue = device->CreateCommandQueue(DKCommandQueue::Graphics);
273
         DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
271
         DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
274
 
272
 
273
+        // Geometry Initialzie
274
+        Quad->InitializeGpuResource(graphicsQueue);
275
+
275
         // create shaders
276
         // create shaders
276
 		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
277
 		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
277
 		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.frag.spv");
278
 		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.frag.spv");
300
         auto CS_EDF = CS_ED->Function();
301
         auto CS_EDF = CS_ED->Function();
301
         auto CS_SHF = CS_SH->Function();
302
         auto CS_SHF = CS_SH->Function();
302
 
303
 
303
-        // Geometry Initialzie
304
-        Quad->InitializeGpuResource(graphicsQueue);
304
+
305
 
305
 
306
         // Texture Resource Initialize
306
         // Texture Resource Initialize
307
         
307
         
412
         embossComputePipelineDescriptor.computeFunction = CS_EF;
412
         embossComputePipelineDescriptor.computeFunction = CS_EF;
413
         auto Emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
413
         auto Emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
414
         
414
         
415
-        
416
         DKObject<DKTexture> depthBuffer = nullptr;
415
         DKObject<DKTexture> depthBuffer = nullptr;
417
         DKObject<DKTexture> targettex = nullptr;
416
         DKObject<DKTexture> targettex = nullptr;
418
 
417
 
419
-        DKCamera camera;
420
-        DKVector3 cameraPosition = { 0, 5, 10 };
421
-        DKVector3 cameraTartget = { 0, 0, 0 };
422
-		
423
-        DKAffineTransform3 tm(DKLinearTransform3().Scale(5).Rotate(DKVector3(-1,0,0), DKGL_PI * 0.5));
424
-
425
         DKTimer timer;
418
         DKTimer timer;
426
 		timer.Reset();
419
 		timer.Reset();
427
 
420
 
486
 			{
479
 			{
487
                 if (graphicShaderBindingSet->PostcomputeDescSet() && ubo)
480
                 if (graphicShaderBindingSet->PostcomputeDescSet() && ubo)
488
                 {
481
                 {
489
-                    camera.SetView(cameraPosition, cameraTartget - cameraPosition, DKVector3(0, 1, 0));
490
-                    camera.SetPerspective(DKGL_DEGREE_TO_RADIAN(90), float(width)/float(height), 1, 1000);
491
-
492
-                    ubo->projectionMatrix = camera.ProjectionMatrix();
493
-                    ubo->viewMatrix = camera.ViewMatrix();
494
-
495
-                    DKQuaternion quat(DKVector3(0, 1, 0), t);
496
-                    DKAffineTransform3 trans = tm * DKAffineTransform3(quat);
497
-                    ubo->modelMatrix = trans.Matrix4();
498
-                    uboBuffer->Flush();
499
                     graphicShaderBindingSet->PostcomputeDescSet()->SetBuffer(0, uboBuffer, 0, sizeof(GraphicShaderBindingSet::UBO));
482
                     graphicShaderBindingSet->PostcomputeDescSet()->SetBuffer(0, uboBuffer, 0, sizeof(GraphicShaderBindingSet::UBO));
500
-
501
                     graphicShaderBindingSet->PostcomputeDescSet()->SetTexture(1, targettex);
483
                     graphicShaderBindingSet->PostcomputeDescSet()->SetTexture(1, targettex);
502
                     graphicShaderBindingSet->PostcomputeDescSet()->SetSamplerState(1, sampler);
484
                     graphicShaderBindingSet->PostcomputeDescSet()->SetSamplerState(1, sampler);
503
                 }
485
                 }

BIN
Samples/Data/shaders/ComputeShader/edgedetect.comp.spv View File


+ 1
- 2
Samples/Data/shaders/ComputeShader/emboss.comp View File

39
 	kernel[6] = 0.0; kernel[7] =  0.0; kernel[8] = 2.0;
39
 	kernel[6] = 0.0; kernel[7] =  0.0; kernel[8] = 2.0;
40
 									
40
 									
41
 	vec4 res = vec4(vec3(conv(kernel, imageData.avg, 1.0, 0.50)), 1.0);
41
 	vec4 res = vec4(vec3(conv(kernel, imageData.avg, 1.0, 0.50)), 1.0);
42
-
43
-	imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), res);
42
+    imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), res);
44
 }
43
 }

BIN
Samples/Data/shaders/ComputeShader/emboss.comp.spv View File


BIN
Samples/Data/shaders/ComputeShader/sharpen.comp.spv View File


BIN
Samples/Data/shaders/ComputeShader/texture.frag.spv View File


BIN
Samples/Data/shaders/ComputeShader/texture.vert.spv View File