Skip to content

Commit de80cc5

Browse files
committed
Started support for multiple set of UV (2)
1 parent ff7fcf0 commit de80cc5

30 files changed

Lines changed: 155 additions & 129 deletions

VesperEngine/Assets/Shaders/pbr_shader.frag

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
layout(location = 0) in vec3 fragColor;
88
layout(location = 1) in vec3 fragPositionWorld;
99
layout(location = 2) in vec3 fragNormalWorld;
10-
layout(location = 3) in vec2 fragUV;
10+
layout(location = 3) in vec2 fragUV1;
11+
layout(location = 4) in vec2 fragUV2;
1112

1213
layout(location = 0) out vec4 outColor;
1314

@@ -164,10 +165,10 @@ vec3 getNormal(bool hasNormal)
164165
vec3 N = normalize(fragNormalWorld);
165166
#if BINDLESS == 1
166167
if (hasNormal)
167-
N = normalize(texture(textures[nonuniformEXT(materials[materialIndexUBO.materialIndex].TextureIndices[4])], fragUV).xyz * 2.0 - 1.0);
168+
N = normalize(texture(textures[nonuniformEXT(materials[materialIndexUBO.materialIndex].TextureIndices[4])], fragUV1).xyz * 2.0 - 1.0);
168169
#else
169170
if (hasNormal)
170-
N = normalize(texture(normalTexture, fragUV).xyz * 2.0 - 1.0);
171+
N = normalize(texture(normalTexture, fragUV1).xyz * 2.0 - 1.0);
171172
#endif
172173
return N;
173174
}
@@ -224,30 +225,30 @@ vec4 baseColor;
224225

225226
#if BINDLESS == 1
226227
vec4 texColor = hasBaseColor
227-
? texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[5])], fragUV)
228+
? texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[5])], fragUV1)
228229
: vec4(1.0); // fallback if no texture
229230

230231
// Combine fragment color only with RGB — preserve texture alpha
231232
baseColor.rgb = fragColor * texColor.rgb;
232233
baseColor.a = texColor.a * materials[matIdx].BaseColorAlpha;
233234

234235
float ao = hasAO
235-
? texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[6])], fragUV).r
236+
? texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[6])], fragUV1).r
236237
: 1.0;
237238

238239
if (baseColor.a < materials[matIdx].AlphaCutoff)
239240
discard;
240241

241242
#else
242243
vec4 texColor = hasBaseColor
243-
? texture(baseColorTexture, fragUV)
244+
? texture(baseColorTexture, fragUV1)
244245
: vec4(1.0);
245246

246247
baseColor.rgb = fragColor * texColor.rgb;
247248
baseColor.a = texColor.a * material.BaseColorAlpha;
248249

249250
float ao = hasAO
250-
? texture(aoTexture, fragUV).r
251+
? texture(aoTexture, fragUV1).r
251252
: 1.0;
252253

253254
if (baseColor.a < material.AlphaCutoff)
@@ -256,11 +257,11 @@ vec4 baseColor;
256257

257258

258259
#if BINDLESS == 1
259-
if(hasRoughness) roughness *= texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[0])], fragUV).g;
260-
if(hasMetallic) metallic *= texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[1])], fragUV).b;
260+
if(hasRoughness) roughness *= texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[0])], fragUV1).g;
261+
if(hasMetallic) metallic *= texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[1])], fragUV1).b;
261262
#else
262-
if(hasRoughness) roughness *= texture(roughnessTexture, fragUV).g;
263-
if(hasMetallic) metallic *= texture(metallicTexture, fragUV).b;
263+
if(hasRoughness) roughness *= texture(roughnessTexture, fragUV1).g;
264+
if(hasMetallic) metallic *= texture(metallicTexture, fragUV1).b;
264265
#endif
265266

266267
roughness = clamp(roughness, c_MinRoughness, 1.0);
@@ -429,10 +430,10 @@ vec4 baseColor;
429430

430431
#if BINDLESS == 1
431432
if(hasEmissive)
432-
color += texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[3])], fragUV).rgb;
433+
color += texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[3])], fragUV1).rgb;
433434
#else
434435
if(hasEmissive)
435-
color += texture(emissiveTexture, fragUV).rgb;
436+
color += texture(emissiveTexture, fragUV1).rgb;
436437
#endif
437438

438439
//outColor = vec4(vec3(pbrInputs.NdotL), 1.0);

VesperEngine/Assets/Shaders/pbr_shader.vert

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,30 @@
77
layout(location = 0) in vec3 inPosition;
88
layout(location = 1) in vec3 inColor;
99
layout(location = 2) in vec3 inNormal;
10-
layout(location = 3) in vec2 inUV;
11-
layout(location = 4) in vec3 inMorphPos0;
12-
layout(location = 5) in vec3 inMorphNorm0;
13-
layout(location = 6) in vec3 inMorphPos1;
14-
layout(location = 7) in vec3 inMorphNorm1;
15-
layout(location = 8) in vec3 inMorphPos2;
16-
layout(location = 9) in vec3 inMorphNorm2;
17-
layout(location = 10) in vec3 inMorphPos3;
18-
layout(location = 11) in vec3 inMorphNorm3;
19-
layout(location = 12) in vec3 inMorphPos4;
20-
layout(location = 13) in vec3 inMorphNorm4;
21-
layout(location = 14) in vec3 inMorphPos5;
22-
layout(location = 15) in vec3 inMorphNorm5;
23-
layout(location = 16) in vec3 inMorphPos6;
24-
layout(location = 17) in vec3 inMorphNorm6;
25-
layout(location = 18) in vec3 inMorphPos7;
26-
layout(location = 19) in vec3 inMorphNorm7;
10+
layout(location = 3) in vec2 inUV1;
11+
layout(location = 4) in vec2 inUV2;
12+
layout(location = 5) in vec3 inMorphPos0;
13+
layout(location = 6) in vec3 inMorphNorm0;
14+
layout(location = 7) in vec3 inMorphPos1;
15+
layout(location = 8) in vec3 inMorphNorm1;
16+
layout(location = 9) in vec3 inMorphPos2;
17+
layout(location = 10) in vec3 inMorphNorm2;
18+
layout(location = 11) in vec3 inMorphPos3;
19+
layout(location = 12) in vec3 inMorphNorm3;
20+
layout(location = 13) in vec3 inMorphPos4;
21+
layout(location = 14) in vec3 inMorphNorm4;
22+
layout(location = 15) in vec3 inMorphPos5;
23+
layout(location = 16) in vec3 inMorphNorm5;
24+
layout(location = 17) in vec3 inMorphPos6;
25+
layout(location = 18) in vec3 inMorphNorm6;
26+
layout(location = 19) in vec3 inMorphPos7;
27+
layout(location = 20) in vec3 inMorphNorm7;
2728

2829
layout(location = 0) out vec3 fragColor;
2930
layout(location = 1) out vec3 fragPositionWorld;
3031
layout(location = 2) out vec3 fragNormalWorld;
31-
layout(location = 3) out vec2 fragUV;
32+
layout(location = 3) out vec2 fragUV1;
33+
layout(location = 4) out vec2 fragUV2;
3234

3335
layout(std140, set = 0, binding = 0) uniform SceneUBO
3436
{
@@ -83,5 +85,6 @@ void main()
8385
fragColor = inColor;
8486
fragPositionWorld = positionWorld.xyz;
8587
fragNormalWorld = normalize(mat3(transpose(inverse(entityUBO.ModelMatrix))) * finalNorm);
86-
fragUV = inUV;
88+
fragUV1 = inUV1;
89+
fragUV2 = inUV2;
8790
}
52 Bytes
Binary file not shown.
132 Bytes
Binary file not shown.
52 Bytes
Binary file not shown.
132 Bytes
Binary file not shown.

VesperEngine/Assets/Shaders/phong_shader.frag

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
layout(location = 0) in vec3 fragColor;
99
layout(location = 1) in vec3 fragPositionWorld;
1010
layout(location = 2) in vec3 fragNormalWorld;
11-
layout(location = 3) in vec2 fragUV;
11+
layout(location = 3) in vec2 fragUV1;
12+
layout(location = 4) in vec2 fragUV2;
1213

1314
layout(location = 0) out vec4 outColor;
1415

@@ -87,7 +88,7 @@ layout(constant_id = 0) const float kBrightnessFactor = 1.0;
8788
void main()
8889
{
8990
// DEBUG UV COLOR
90-
//outColor = vec4(fragUV, 0.0, 1.0); // Visualize UVs as colors
91+
//outColor = vec4(fragUV1, 0.0, 1.0); // Visualize UVs as colors
9192

9293
#if BINDLESS == 1
9394
// Access material data using the index
@@ -119,22 +120,22 @@ void main()
119120
#if BINDLESS == 1
120121
if (bHasAlphaTexture)
121122
{
122-
alpha *= texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[4])], fragUV).r;
123+
alpha *= texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[4])], fragUV1).r;
123124
}
124125
#else
125126
if (bHasAlphaTexture)
126127
{
127-
alpha *= texture(alphaTexture, fragUV).r;
128+
alpha *= texture(alphaTexture, fragUV1).r;
128129
}
129130
#endif
130131

131132
vec3 normal = normalize(fragNormalWorld);
132133
if (bHasNormalTexture)
133134
{
134135
#if BINDLESS == 1
135-
vec3 normalMap = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[3])], fragUV).rgb * 2.0 - 1.0;
136+
vec3 normalMap = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[3])], fragUV1).rgb * 2.0 - 1.0;
136137
#else
137-
vec3 normalMap = texture(normalTexture, fragUV).rgb * 2.0 - 1.0;
138+
vec3 normalMap = texture(normalTexture, fragUV1).rgb * 2.0 - 1.0;
138139
#endif
139140

140141
normal = normalize(normalMap);
@@ -149,9 +150,9 @@ void main()
149150
if (bHasAmbientTexture)
150151
{
151152
#if BINDLESS == 1
152-
vec4 ambientTextureColor = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[0])], fragUV);
153+
vec4 ambientTextureColor = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[0])], fragUV1);
153154
#else
154-
vec4 ambientTextureColor = texture(ambientTexture, fragUV);
155+
vec4 ambientTextureColor = texture(ambientTexture, fragUV1);
155156
#endif
156157

157158
vec4 finalAmbientColor = ambientTextureColor * ambientColor;
@@ -162,9 +163,9 @@ void main()
162163
if (bHasDiffuseTexture)
163164
{
164165
#if BINDLESS == 1
165-
vec4 diffuseTextureColor = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[1])], fragUV);
166+
vec4 diffuseTextureColor = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[1])], fragUV1);
166167
#else
167-
vec4 diffuseTextureColor = texture(diffuseTexture, fragUV);
168+
vec4 diffuseTextureColor = texture(diffuseTexture, fragUV1);
168169
#endif
169170

170171
vec4 finalDiffuseColor = diffuseTextureColor * diffuseColor;
@@ -207,9 +208,9 @@ void main()
207208
if (bHasSpecularTexture)
208209
{
209210
#if BINDLESS == 1
210-
vec4 specularTextureColor = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[2])], fragUV);
211+
vec4 specularTextureColor = texture(textures[nonuniformEXT(materials[matIdx].TextureIndices[2])], fragUV1);
211212
#else
212-
vec4 specularTextureColor = texture(specularTexture, fragUV);
213+
vec4 specularTextureColor = texture(specularTexture, fragUV1);
213214
#endif
214215

215216
vec4 finalSpecularColor = specularTextureColor * specularColor;

VesperEngine/Assets/Shaders/phong_shader.vert

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,30 @@
77
layout(location = 0) in vec3 inPosition;
88
layout(location = 1) in vec3 inColor;
99
layout(location = 2) in vec3 inNormal;
10-
layout(location = 3) in vec2 inUV;
11-
layout(location = 4) in vec3 inMorphPos0;
12-
layout(location = 5) in vec3 inMorphNorm0;
13-
layout(location = 6) in vec3 inMorphPos1;
14-
layout(location = 7) in vec3 inMorphNorm1;
15-
layout(location = 8) in vec3 inMorphPos2;
16-
layout(location = 9) in vec3 inMorphNorm2;
17-
layout(location = 10) in vec3 inMorphPos3;
18-
layout(location = 11) in vec3 inMorphNorm3;
19-
layout(location = 12) in vec3 inMorphPos4;
20-
layout(location = 13) in vec3 inMorphNorm4;
21-
layout(location = 14) in vec3 inMorphPos5;
22-
layout(location = 15) in vec3 inMorphNorm5;
23-
layout(location = 16) in vec3 inMorphPos6;
24-
layout(location = 17) in vec3 inMorphNorm6;
25-
layout(location = 18) in vec3 inMorphPos7;
26-
layout(location = 19) in vec3 inMorphNorm7;
10+
layout(location = 3) in vec2 inUV1;
11+
layout(location = 4) in vec2 inUV2;
12+
layout(location = 5) in vec3 inMorphPos0;
13+
layout(location = 6) in vec3 inMorphNorm0;
14+
layout(location = 7) in vec3 inMorphPos1;
15+
layout(location = 8) in vec3 inMorphNorm1;
16+
layout(location = 9) in vec3 inMorphPos2;
17+
layout(location = 10) in vec3 inMorphNorm2;
18+
layout(location = 11) in vec3 inMorphPos3;
19+
layout(location = 12) in vec3 inMorphNorm3;
20+
layout(location = 13) in vec3 inMorphPos4;
21+
layout(location = 14) in vec3 inMorphNorm4;
22+
layout(location = 15) in vec3 inMorphPos5;
23+
layout(location = 16) in vec3 inMorphNorm5;
24+
layout(location = 17) in vec3 inMorphPos6;
25+
layout(location = 18) in vec3 inMorphNorm6;
26+
layout(location = 19) in vec3 inMorphPos7;
27+
layout(location = 20) in vec3 inMorphNorm7;
2728

2829
layout(location = 0) out vec3 fragColor;
2930
layout(location = 1) out vec3 fragPositionWorld;
3031
layout(location = 2) out vec3 fragNormalWorld;
31-
layout(location = 3) out vec2 fragUV;
32+
layout(location = 3) out vec2 fragUV1;
33+
layout(location = 4) out vec2 fragUV2;
3234

3335
layout(std140, set = 0, binding = 0) uniform SceneUBO
3436
{
@@ -85,5 +87,6 @@ void main()
8587
fragColor = inColor;
8688
fragPositionWorld = positionWorld.xyz;
8789
fragNormalWorld = normalize(mat3(transpose(inverse(entityUBO.ModelMatrix))) * finalNorm);
88-
fragUV = inUV;
90+
fragUV1 = inUV1;
91+
fragUV2 = inUV2;
8992
}
52 Bytes
Binary file not shown.
132 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)