Skip to content

Commit 76db498

Browse files
committed
Added groups
1 parent a4efc82 commit 76db498

File tree

10 files changed

+110
-76
lines changed

10 files changed

+110
-76
lines changed

Engine/Shaders/DeferredForwardPipeline/fragment.glsl

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,26 @@ void main()
2424
{
2525
currentMaterial = materialData[drawId];
2626

27-
vec4 diffuseTexture = texture(currentMaterial.diffuse, TexCoords)+currentMaterial.materialColor;
28-
29-
vec3 albedo = diffuseTexture.rgb;
30-
if (diffuseTexture.a < 0.1) {
31-
discard;
27+
if(statusCopy[drawId].plainColor>1){
28+
FragColor=currentMaterial.materialColor;
29+
}else{
30+
31+
vec4 diffuseTexture = texture(currentMaterial.diffuse, TexCoords)+currentMaterial.materialColor;
32+
33+
vec3 albedo = diffuseTexture.rgb;
34+
if (diffuseTexture.a < 0.1) {
35+
discard;
36+
}
37+
vec4 roughnessMetalnessTexture = texture(currentMaterial.roughness_metalness, TexCoords);
38+
float metallic = roughnessMetalnessTexture.b;
39+
float roughness = roughnessMetalnessTexture.g;
40+
float specularMap = texture(currentMaterial.specularMap, TexCoords).r;
41+
float ao = texture(currentMaterial.ambient_occlusion, TexCoords).r;
42+
43+
vec4 aoSpecular = vec4(specularMap, ao, 0, 0);
44+
45+
vec3 N = getNormalFromMap();
46+
vec3 pbrColor = pbrCalculation(FragPos, N, albedo, aoSpecular, roughness, metallic);
47+
FragColor = vec4(pbrColor, diffuseTexture.a);
3248
}
33-
vec4 roughnessMetalnessTexture = texture(currentMaterial.roughness_metalness, TexCoords);
34-
float metallic = roughnessMetalnessTexture.b;
35-
float roughness = roughnessMetalnessTexture.g;
36-
float specularMap = texture(currentMaterial.specularMap, TexCoords).r;
37-
float ao = texture(currentMaterial.ambient_occlusion, TexCoords).r;
38-
39-
vec4 aoSpecular = vec4(specularMap, ao, 0, 0);
40-
41-
vec3 N = getNormalFromMap();
42-
43-
vec3 pbrColor = pbrCalculation(FragPos, N, albedo, aoSpecular, roughness, metallic);
44-
45-
FragColor = vec4(pbrColor, diffuseTexture.a);
4649
}

Engine/Shaders/DeferredPipeline/fragment.glsl

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ vec3 getNormalFromMap()
5353
return normalize(TBN * tangentNormal);
5454
}
5555

56+
struct StatusData{
57+
uint status;
58+
int plainColor;
59+
vec2 padding;
60+
};
61+
62+
layout(std430, binding = 25) buffer StatusCopy {
63+
StatusData statusCopy[];
64+
};
65+
66+
5667
void main()
5768
{
5869
#if defined(ANIMATE)
@@ -67,22 +78,26 @@ void main()
6778
if (albedoTexture.a < 0.1) {
6879
discard;
6980
}
70-
71-
// and the diffuse per-fragment color
72-
gAlbedoSpec.rgb = albedoTexture.rgb;
73-
74-
// store the fragment position vector in the first gbuffer texture
75-
gPosition.rgb = FragPos;
76-
// also store the per-fragment normals into the gbuffer
77-
gNormal.rgb = getNormalFromMap();
78-
79-
vec4 roughnessMetalnessTexture = texture(currentMaterial.roughness_metalness, TexCoords);
80-
81-
gAlbedoSpec.a= roughnessMetalnessTexture.b;
82-
gNormal.a = roughnessMetalnessTexture.g;
83-
gPosition.a=gl_FragCoord.z;
84-
85-
gAmbient.r = texture(currentMaterial.specularMap, TexCoords).r;
86-
gAmbient.g = texture(currentMaterial.ambient_occlusion, TexCoords).r;
87-
81+
if(statusCopy[drawId].plainColor>1){
82+
gAmbient.b= float(statusCopy[drawId].plainColor);
83+
gAlbedoSpec.rgb = vec3(currentMaterial.materialColor);
84+
}else{
85+
// and the diffuse per-fragment color
86+
gAlbedoSpec.rgb = albedoTexture.rgb;
87+
88+
// store the fragment position vector in the first gbuffer texture
89+
gPosition.rgb = FragPos;
90+
// also store the per-fragment normals into the gbuffer
91+
gNormal.rgb = getNormalFromMap();
92+
93+
vec4 roughnessMetalnessTexture = texture(currentMaterial.roughness_metalness, TexCoords);
94+
95+
gAlbedoSpec.a= roughnessMetalnessTexture.b;
96+
gNormal.a = roughnessMetalnessTexture.g;
97+
gPosition.a=gl_FragCoord.z;
98+
99+
gAmbient.r = texture(currentMaterial.specularMap, TexCoords).r;
100+
gAmbient.g = texture(currentMaterial.ambient_occlusion, TexCoords).r;
101+
gAmbient.b = 0;
102+
}
88103
}

Engine/Shaders/DeferredPipeline/fragment_d.glsl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ layout(std140, binding = 1) uniform MeshData
2525
void main()
2626
{
2727
// retrieve data from gbuffer
28-
vec3 FragPos = texture(gPosition, TexCoords).rgb;
29-
vec3 N = texture(gNormal, TexCoords).rgb;
30-
vec3 albedo = texture(gAlbedo, TexCoords).rgb;
3128
vec4 aoSpecular = texture(gAmbient, TexCoords);
32-
float roughness = texture(gNormal, TexCoords).a;
33-
float metallic = texture(gAlbedo, TexCoords).a;
34-
35-
vec3 pbrColor = pbrCalculation(FragPos, N, albedo, aoSpecular,roughness,metallic);
36-
37-
FragColor = vec4(pbrColor, 1.0);
29+
vec3 albedo = texture(gAlbedo, TexCoords).rgb;
30+
if(int(aoSpecular.b)>0){
31+
FragColor = vec4(albedo, 1.0);
32+
}else{
33+
vec3 FragPos = texture(gPosition, TexCoords).rgb;
34+
vec3 N = texture(gNormal, TexCoords).rgb;
35+
float roughness = texture(gNormal, TexCoords).a;
36+
float metallic = texture(gAlbedo, TexCoords).a;
37+
vec3 pbrColor = pbrCalculation(FragPos, N, albedo, aoSpecular,roughness,metallic);
38+
FragColor = vec4(pbrColor, 1.0);
39+
}
3840
}

Engine/Shaders/ForwardPipeline/fragment.glsl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,28 @@ void main()
2525
#else
2626
currentMaterial = materialData[drawId];
2727
#endif
28-
29-
vec4 diffuseTexture = texture(currentMaterial.diffuse, TexCoords)+currentMaterial.materialColor;
30-
31-
vec3 albedo = diffuseTexture.rgb;
32-
if (diffuseTexture.a < 0.1) {
33-
discard;
28+
if(statusCopy[drawId].plainColor>1){
29+
FragColor=currentMaterial.materialColor;
30+
}else{
31+
32+
vec4 diffuseTexture = texture(currentMaterial.diffuse, TexCoords)+currentMaterial.materialColor;
33+
34+
vec3 albedo = diffuseTexture.rgb;
35+
if (diffuseTexture.a < 0.1) {
36+
discard;
37+
}
38+
vec4 roughnessMetalnessTexture = texture(currentMaterial.roughness_metalness, TexCoords);
39+
float metallic = roughnessMetalnessTexture.b;
40+
float roughness = roughnessMetalnessTexture.g;
41+
float specularMap = texture(currentMaterial.specularMap, TexCoords).r;
42+
float ao = texture(currentMaterial.ambient_occlusion, TexCoords).r;
43+
44+
vec4 aoSpecular=vec4(specularMap, ao, 0, 0);
45+
46+
vec3 N = getNormalFromMap();
47+
48+
vec3 pbrColor = pbrCalculation(FragPos, N, albedo, aoSpecular,roughness,metallic);
49+
FragColor = vec4(pbrColor, diffuseTexture.a);
3450
}
35-
vec4 roughnessMetalnessTexture = texture(currentMaterial.roughness_metalness, TexCoords);
36-
float metallic = roughnessMetalnessTexture.b;
37-
float roughness = roughnessMetalnessTexture.g;
38-
float specularMap = texture(currentMaterial.specularMap, TexCoords).r;
39-
float ao = texture(currentMaterial.ambient_occlusion, TexCoords).r;
40-
41-
vec4 aoSpecular=vec4(specularMap, ao, 0, 0);
42-
43-
vec3 N = getNormalFromMap();
44-
45-
vec3 pbrColor = pbrCalculation(FragPos, N, albedo, aoSpecular,roughness,metallic);
4651

47-
FragColor = vec4(pbrColor, diffuseTexture.a);
4852
}

Engine/Shaders/PbrHeaderPipeline/pbr_func.glsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ layout(std140, binding = 3) uniform FragmentData
2323
sampler2D textureM;
2424
};
2525

26+
struct StatusData{
27+
uint status;
28+
int plainColor;
29+
vec2 padding;
30+
};
31+
32+
layout(std430, binding = 25) buffer StatusCopy {
33+
StatusData statusCopy[];
34+
};
35+
2636

2737
const float LUT_SIZE = 64.0; // ltc_texture size
2838
const float LUT_SCALE = (LUT_SIZE - 1.0)/LUT_SIZE;

Engine/Shaders/StatusPipeline/compute.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ layout(std430, binding = 22) buffer DrawElementsIndirectMeshCopy
1616

1717
struct StatusData{
1818
uint status;
19-
bool plainColor;
19+
int plainColor;
2020
vec2 padding;
2121
};
2222

Engine/Shaders/TransparentPipeline/computeCopy.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ layout(std430, binding = 0) buffer Material {
6060

6161
struct StatusData{
6262
uint status;
63-
bool plainColor;
63+
int plainColor;
6464
vec2 padding;
6565
};
6666

Engine/Shaders/TransparentPipeline/computeHideShow.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ layout(std430, binding = 0) buffer Material
3838

3939
struct StatusData{
4040
uint status;
41-
bool plainColor;
41+
int plainColor;
4242
vec2 padding;
4343
};
4444

Engine/include/SceneData/MeshIndirect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace Prisma
118118

119119
struct StatusData {
120120
unsigned int status;
121-
bool plainMaterial;
121+
int plainMaterial;
122122
glm::vec2 padding;
123123
};
124124

Engine/src/SceneData/MeshIndirect.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ void Prisma::MeshIndirect::updateSize()
239239

240240
m_ssboIndices->resize(sizeof(glm::ivec4) * meshes.size());
241241

242-
std::vector<unsigned int> status;
242+
std::vector<StatusData> status;
243243
for (const auto& mesh : meshes)
244244
{
245-
status.push_back(mesh->visible());
245+
status.push_back({ mesh->visible(),mesh->material()->plain(),glm::vec2(0) });
246246
}
247-
m_ssboStatusCopy->resize(sizeof(unsigned int) * status.size());
248-
m_ssboStatusCopy->modifyData(0, sizeof(unsigned int) * status.size(), status.data());
249-
m_ssboStatus->resize(sizeof(unsigned int) * status.size());
247+
m_ssboStatusCopy->resize(sizeof(StatusData) * status.size());
248+
m_ssboStatusCopy->modifyData(0, sizeof(StatusData) * status.size(), status.data());
249+
m_ssboStatus->resize(sizeof(StatusData) * status.size());
250250

251251
//GENERATE DATA TO SEND INDIRECT
252252
m_vao->bind();
@@ -478,13 +478,13 @@ void Prisma::MeshIndirect::updateAnimation()
478478
m_ssboMaterialAnimation->modifyData(0, sizeof(MaterialData) * m_materialDataAnimation.size(),
479479
m_materialDataAnimation.data());
480480

481-
std::vector<unsigned int> status;
481+
std::vector<StatusData> status;
482482
for (const auto& mesh : meshes)
483483
{
484-
status.push_back(mesh->visible());
484+
status.push_back({ mesh->visible(),mesh->material()->plain(),glm::vec2(0) });
485485
}
486-
m_ssboStatusAnimation->resize(sizeof(unsigned int) * status.size());
487-
m_ssboStatusAnimation->modifyData(0, sizeof(unsigned int) * status.size(), status.data());
486+
m_ssboStatusAnimation->resize(sizeof(StatusData) * status.size());
487+
m_ssboStatusAnimation->modifyData(0, sizeof(StatusData) * status.size(), status.data());
488488

489489
//GENERATE DATA TO SEND INDIRECT
490490
m_vaoAnimation->bind();

0 commit comments

Comments
 (0)