Browse Source

Now It's Grey

Heedong Arkiny Lee 5 years ago
parent
commit
e94ace574f

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

@@ -46,7 +46,7 @@ public:
46 46
         // setup vertex buffer and attributes
47 47
         vertexDesc.attributes = {
48 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 51
         vertexDesc.layouts = {
52 52
             { DKVertexStepRate::Vertex, sizeof(UVQuad::Vertex), 0 },
@@ -85,7 +85,7 @@ public:
85 85
             texDesc.mipmapLevels = 1;
86 86
             texDesc.sampleCount = 1;
87 87
             texDesc.arrayLength = 1;
88
-            texDesc.usage = DKTexture::UsageShaderRead | DKTexture::UsageShaderWrite;
88
+            texDesc.usage = DKTexture::UsageShaderRead | DKTexture::UsageShaderWrite | DKTexture::UsageSampled;
89 89
             textureTarget = device->CreateTexture(texDesc);
90 90
         }
91 91
 
@@ -125,7 +125,6 @@ public:
125 125
     {
126 126
         DKMatrix4 projectionMatrix;
127 127
         DKMatrix4 modelMatrix;
128
-        DKMatrix4 viewMatrix;
129 128
     };
130 129
 private:
131 130
     DKShaderBindingSetLayout descriptorSetLayout;
@@ -173,7 +172,6 @@ public:
173 172
                 ubo = reinterpret_cast<UBO*>(uniformBuffer->Contents());
174 173
                 ubo->projectionMatrix = DKMatrix4::identity;
175 174
                 ubo->modelMatrix = DKMatrix4::identity;
176
-                ubo->viewMatrix = DKMatrix4::identity;
177 175
                 uniformBuffer->Flush();
178 176
 
179 177
                 descriptorSetPreCompute->SetBuffer(0, uniformBuffer, 0, sizeof(UBO));
@@ -272,6 +270,9 @@ public:
272 270
         DKObject<DKCommandQueue> graphicsQueue = device->CreateCommandQueue(DKCommandQueue::Graphics);
273 271
         DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
274 272
 
273
+        // Geometry Initialzie
274
+        Quad->InitializeGpuResource(graphicsQueue);
275
+
275 276
         // create shaders
276 277
 		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
277 278
 		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.frag.spv");
@@ -300,8 +301,7 @@ public:
300 301
         auto CS_EDF = CS_ED->Function();
301 302
         auto CS_SHF = CS_SH->Function();
302 303
 
303
-        // Geometry Initialzie
304
-        Quad->InitializeGpuResource(graphicsQueue);
304
+
305 305
 
306 306
         // Texture Resource Initialize
307 307
         
@@ -412,16 +412,9 @@ public:
412 412
         embossComputePipelineDescriptor.computeFunction = CS_EF;
413 413
         auto Emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
414 414
         
415
-        
416 415
         DKObject<DKTexture> depthBuffer = nullptr;
417 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 418
         DKTimer timer;
426 419
 		timer.Reset();
427 420
 
@@ -486,18 +479,7 @@ public:
486 479
 			{
487 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 482
                     graphicShaderBindingSet->PostcomputeDescSet()->SetBuffer(0, uboBuffer, 0, sizeof(GraphicShaderBindingSet::UBO));
500
-
501 483
                     graphicShaderBindingSet->PostcomputeDescSet()->SetTexture(1, targettex);
502 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,6 +39,5 @@ void main()
39 39
 	kernel[6] = 0.0; kernel[7] =  0.0; kernel[8] = 2.0;
40 40
 									
41 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