Browse Source

no message

Hongtae Kim 5 years ago
parent
commit
d7b6436f82

+ 1
- 13
Samples/Data/shaders/texture.frag View File

4
 
4
 
5
 layout (location = 0) in vec2 inUV;
5
 layout (location = 0) in vec2 inUV;
6
 layout (location = 1) in float inLodBias;
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
 layout (location = 0) out vec4 outFragColor;
8
 layout (location = 0) out vec4 outFragColor;
12
 
9
 
13
 void main() 
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 View File


+ 1
- 13
Samples/Data/shaders/texture.vert View File

14
 
14
 
15
 layout (location = 0) out vec2 outUV;
15
 layout (location = 0) out vec2 outUV;
16
 layout (location = 1) out float outLodBias;
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
 out gl_PerVertex 
18
 out gl_PerVertex 
22
 {
19
 {
28
 	outUV = inUV;
25
 	outUV = inUV;
29
 	outLodBias = ubo.lodBias;
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 View File


+ 30
- 16
Samples/Texture/Texture.cpp View File

65
 		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
65
 		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
66
         DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
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
-        // create sampler
71
-        DKSamplerDescriptor samplerDesc = {};
72
-        DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
73
-
74
         // create shaders
68
         // create shaders
75
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
69
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
76
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
70
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
95
 		};
89
 		};
96
 		DKArray<Vertex> vertexData =
90
 		DKArray<Vertex> vertexData =
97
 		{
91
 		{
98
-            { {  1.0f,  1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
99
-            { { -1.0f,  1.0f, 0.0f }, { 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
100
-            { { -1.0f, -1.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
101
-            { {  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 } }
102
 		};
96
 		};
103
 		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
97
 		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
104
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
98
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
117
 		pipelineDescriptor.fragmentFunction = fragShaderFunction;
111
 		pipelineDescriptor.fragmentFunction = fragShaderFunction;
118
 		pipelineDescriptor.colorAttachments.Resize(1);
112
 		pipelineDescriptor.colorAttachments.Resize(1);
119
 		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
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;
120
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
117
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
121
 		pipelineDescriptor.vertexDescriptor.attributes = {
118
 		pipelineDescriptor.vertexDescriptor.attributes = {
122
 			{ DKVertexFormat::Float3, 0, 0, 0 },
119
 			{ DKVertexFormat::Float3, 0, 0, 0 },
143
         DKShaderBindingSetLayout layout;
140
         DKShaderBindingSetLayout layout;
144
         if (1)
141
         if (1)
145
         {
142
         {
146
-            DKShaderBinding binding = {
147
-                0,
148
-                DKShader::DescriptorTypeUniformBuffer,
149
-                1,
150
-                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
+                },
151
             };
156
             };
152
-            layout.bindings.Add(binding);
157
+            layout.bindings.Add(bindings, 2);
153
         }
158
         }
154
         DKObject<DKShaderBindingSet> bindSet = device->CreateShaderBindingSet(layout);
159
         DKObject<DKShaderBindingSet> bindSet = device->CreateShaderBindingSet(layout);
155
         if (bindSet)
160
         if (bindSet)
172
                 bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
177
                 bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
173
                 uboBuffer->Flush();
178
                 uboBuffer->Flush();
174
             }
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);
175
         }
189
         }
176
 
190
 
177
 		DKTimer timer;
191
 		DKTimer timer;