Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a646e8

Browse files
committed
Fix vertex shader source for textures and ubo chapters having a vec3 for positions
1 parent 9cd756f commit 4a646e8

6 files changed

Lines changed: 46 additions & 8 deletions

File tree

07_Depth_buffering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,5 +553,5 @@ geometry and have it look right. We're going to try this out in the next chapter
553553
by drawing a textured model!
554554

555555
[C++ code](/code/depth_buffering.cpp) /
556-
[Vertex shader](/code/shader_textures.vert) /
557-
[Fragment shader](/code/shader_textures.frag)
556+
[Vertex shader](/code/shader_depth.vert) /
557+
[Fragment shader](/code/shader_depth.frag)

08_Loading_models.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,5 @@ learn how these effects work from tutorials for other APIs, because despite
343343
Vulkan's explicitness, many concepts still work the same.
344344

345345
[C++ code](/code/model_loading.cpp) /
346-
[Vertex shader](/code/shader_textures.vert) /
347-
[Fragment shader](/code/shader_textures.frag)
346+
[Vertex shader](/code/shader_depth.vert) /
347+
[Fragment shader](/code/shader_depth.frag)

code/shader_depth.frag

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
4+
layout(binding = 1) uniform sampler2D texSampler;
5+
6+
layout(location = 0) in vec3 fragColor;
7+
layout(location = 1) in vec2 fragTexCoord;
8+
9+
layout(location = 0) out vec4 outColor;
10+
11+
void main() {
12+
outColor = texture(texSampler, fragTexCoord);
13+
}

code/shader_depth.vert

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
4+
layout(binding = 0) uniform UniformBufferObject {
5+
mat4 model;
6+
mat4 view;
7+
mat4 proj;
8+
} ubo;
9+
10+
layout(location = 0) in vec3 inPosition;
11+
layout(location = 1) in vec3 inColor;
12+
layout(location = 2) in vec2 inTexCoord;
13+
14+
layout(location = 0) out vec3 fragColor;
15+
layout(location = 1) out vec2 fragTexCoord;
16+
17+
out gl_PerVertex {
18+
vec4 gl_Position;
19+
};
20+
21+
void main() {
22+
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
23+
fragColor = inColor;
24+
fragTexCoord = inTexCoord;
25+
}

code/shader_textures.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ layout(binding = 0) uniform UniformBufferObject {
77
mat4 proj;
88
} ubo;
99

10-
layout(location = 0) in vec3 inPosition;
10+
layout(location = 0) in vec2 inPosition;
1111
layout(location = 1) in vec3 inColor;
1212
layout(location = 2) in vec2 inTexCoord;
1313

@@ -19,7 +19,7 @@ out gl_PerVertex {
1919
};
2020

2121
void main() {
22-
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
22+
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
2323
fragColor = inColor;
2424
fragTexCoord = inTexCoord;
2525
}

code/shader_ubo.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ layout(binding = 0) uniform UniformBufferObject {
77
mat4 proj;
88
} ubo;
99

10-
layout(location = 0) in vec3 inPosition;
10+
layout(location = 0) in vec2 inPosition;
1111
layout(location = 1) in vec3 inColor;
1212

1313
layout(location = 0) out vec3 fragColor;
@@ -17,6 +17,6 @@ out gl_PerVertex {
1717
};
1818

1919
void main() {
20-
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
20+
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
2121
fragColor = inColor;
2222
}

0 commit comments

Comments
 (0)