2 Commits

Auteur SHA1 Bericht Datum
  Hongtae Kim d7b6436f82 no message 6 jaren geleden
  Hongtae Kim 61dc36f5d6 no message 6 jaren geleden

+ 1
- 13
Samples/Data/shaders/texture.frag Bestand weergeven

@@ -4,22 +4,10 @@ layout (binding = 1) uniform sampler2D samplerColor;
4 4
 
5 5
 layout (location = 0) in vec2 inUV;
6 6
 layout (location = 1) in float inLodBias;
7
-layout (location = 2) in vec3 inNormal;
8
-layout (location = 3) in vec3 inViewVec;
9
-layout (location = 4) in vec3 inLightVec;
10 7
 
11 8
 layout (location = 0) out vec4 outFragColor;
12 9
 
13 10
 void main() 
14 11
 {
15
-	vec4 color = texture(samplerColor, inUV, inLodBias);
16
-
17
-	vec3 N = normalize(inNormal);
18
-	vec3 L = normalize(inLightVec);
19
-	vec3 V = normalize(inViewVec);
20
-	vec3 R = reflect(-L, N);
21
-	vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
22
-	float specular = pow(max(dot(R, V), 0.0), 16.0) * color.a;
23
-
24
-	outFragColor = vec4(diffuse * color.rgb + specular, 1.0);	
12
+	outFragColor = texture(samplerColor, inUV, inLodBias);
25 13
 }

BIN
Samples/Data/shaders/texture.frag.spv Bestand weergeven


+ 1
- 13
Samples/Data/shaders/texture.vert Bestand weergeven

@@ -14,9 +14,6 @@ layout (binding = 0) uniform UBO
14 14
 
15 15
 layout (location = 0) out vec2 outUV;
16 16
 layout (location = 1) out float outLodBias;
17
-layout (location = 2) out vec3 outNormal;
18
-layout (location = 3) out vec3 outViewVec;
19
-layout (location = 4) out vec3 outLightVec;
20 17
 
21 18
 out gl_PerVertex 
22 19
 {
@@ -28,14 +25,5 @@ void main()
28 25
 	outUV = inUV;
29 26
 	outLodBias = ubo.lodBias;
30 27
 
31
-	vec3 worldPos = vec3(ubo.model * vec4(inPos, 1.0));
32
-
33
-	gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
34
-
35
-    vec4 pos = ubo.model * vec4(inPos, 1.0);
36
-	outNormal = mat3(inverse(transpose(ubo.model))) * inNormal;
37
-	vec3 lightPos = vec3(0.0);
38
-	vec3 lPos = mat3(ubo.model) * lightPos.xyz;
39
-    outLightVec = lPos - pos.xyz;
40
-    outViewVec = ubo.viewPos.xyz - pos.xyz;		
28
+	gl_Position = vec4(inPos.xyz, 1.0);
41 29
 }

BIN
Samples/Data/shaders/texture.vert.spv Bestand weergeven


+ 31
- 13
Samples/Texture/Texture.cpp Bestand weergeven

@@ -65,9 +65,7 @@ public:
65 65
 		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
66 66
         DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
67 67
 
68
-        // create texture
69
-        DKObject<DKTexture> texture = LoadTexture2D(queue, resourcePool.LoadResourceData("textures/deathstar3.png"));
70
-
68
+        // create shaders
71 69
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
72 70
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
73 71
 
@@ -91,10 +89,10 @@ public:
91 89
 		};
92 90
 		DKArray<Vertex> vertexData =
93 91
 		{
94
-            { {  1.0f,  1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
95
-            { { -1.0f,  1.0f, 0.0f }, { 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
96
-            { { -1.0f, -1.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
97
-            { {  1.0f, -1.0f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }
92
+            { {  0.5f,  0.5f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
93
+            { { -0.5f,  0.5f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
94
+            { { -0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
95
+            { {  0.5f, -0.5f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } }
98 96
 		};
99 97
 		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
100 98
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
@@ -113,6 +111,9 @@ public:
113 111
 		pipelineDescriptor.fragmentFunction = fragShaderFunction;
114 112
 		pipelineDescriptor.colorAttachments.Resize(1);
115 113
 		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
114
+        pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = true;
115
+        pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
116
+        pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
116 117
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
117 118
 		pipelineDescriptor.vertexDescriptor.attributes = {
118 119
 			{ DKVertexFormat::Float3, 0, 0, 0 },
@@ -139,13 +140,21 @@ public:
139 140
         DKShaderBindingSetLayout layout;
140 141
         if (1)
141 142
         {
142
-            DKShaderBinding binding = {
143
-                0,
144
-                DKShader::DescriptorTypeUniformBuffer,
145
-                1,
146
-                nullptr
143
+            DKShaderBinding bindings[2] = {
144
+                {
145
+                    0,
146
+                    DKShader::DescriptorTypeUniformBuffer,
147
+                    1,
148
+                    nullptr
149
+                },
150
+                {
151
+                    1,
152
+                    DKShader::DescriptorTypeTextureSampler,
153
+                    1,
154
+                    nullptr
155
+                },
147 156
             };
148
-            layout.bindings.Add(binding);
157
+            layout.bindings.Add(bindings, 2);
149 158
         }
150 159
         DKObject<DKShaderBindingSet> bindSet = device->CreateShaderBindingSet(layout);
151 160
         if (bindSet)
@@ -168,6 +177,15 @@ public:
168 177
                 bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
169 178
                 uboBuffer->Flush();
170 179
             }
180
+
181
+            // create texture
182
+            DKObject<DKTexture> texture = LoadTexture2D(queue, resourcePool.LoadResourceData("textures/deathstar3.png"));
183
+            // create sampler
184
+            DKSamplerDescriptor samplerDesc = {};
185
+            DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
186
+
187
+            bindSet->SetTexture(1, texture);
188
+            bindSet->SetSamplerState(1, sampler);
171 189
         }
172 190
 
173 191
 		DKTimer timer;