Hongtae Kim 5 年 前
コミット
d7b6436f82
共有5 個のファイルを変更した32 個の追加42 個の削除を含む
  1. 1
    13
      Samples/Data/shaders/texture.frag
  2. バイナリ
      Samples/Data/shaders/texture.frag.spv
  3. 1
    13
      Samples/Data/shaders/texture.vert
  4. バイナリ
      Samples/Data/shaders/texture.vert.spv
  5. 30
    16
      Samples/Texture/Texture.cpp

+ 1
- 13
Samples/Data/shaders/texture.frag ファイルの表示

@@ -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
 }

バイナリ
Samples/Data/shaders/texture.frag.spv ファイルの表示


+ 1
- 13
Samples/Data/shaders/texture.vert ファイルの表示

@@ -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
 }

バイナリ
Samples/Data/shaders/texture.vert.spv ファイルの表示


+ 30
- 16
Samples/Texture/Texture.cpp ファイルの表示

@@ -65,12 +65,6 @@ 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
-        // create sampler
71
-        DKSamplerDescriptor samplerDesc = {};
72
-        DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
73
-
74 68
         // create shaders
75 69
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
76 70
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
@@ -95,10 +89,10 @@ public:
95 89
 		};
96 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 97
 		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
104 98
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
@@ -117,6 +111,9 @@ public:
117 111
 		pipelineDescriptor.fragmentFunction = fragShaderFunction;
118 112
 		pipelineDescriptor.colorAttachments.Resize(1);
119 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 117
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
121 118
 		pipelineDescriptor.vertexDescriptor.attributes = {
122 119
 			{ DKVertexFormat::Float3, 0, 0, 0 },
@@ -143,13 +140,21 @@ public:
143 140
         DKShaderBindingSetLayout layout;
144 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 159
         DKObject<DKShaderBindingSet> bindSet = device->CreateShaderBindingSet(layout);
155 160
         if (bindSet)
@@ -172,6 +177,15 @@ public:
172 177
                 bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
173 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 191
 		DKTimer timer;