Skip to content
Snippets Groups Projects
Commit fe1bcc1c authored by sdegrande's avatar sdegrande
Browse files

Add a TransparencyProgramExtension

Used to force transparency to 20% in Materials.
Mainly used for debug purpose (to see what in inside an object).
parent 2f8a106c
No related branches found
No related tags found
No related merge requests found
// SPDX-FileCopyrightText: Copyright (c) 2020 CRIStAL/PIRVI. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2020-2025 CRIStAL/PIRVI. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2020 Paul-Elian Tabarant
// SPDX-FileCopyrightText: Copyright (c) 2020 Samuel Degrande
// SPDX-FileCopyrightText: Copyright (c) 2020-2025 Samuel Degrande
// SPDX-FileCopyrightText: Copyright (c) 2020 Stevens Jourdain
// SPDX-License-Identifier: BSD-3-Clause
#version 420 core
// @define placeholder@
//////////////////// UNIFORM ////////////////////
uniform vec3 Ambient;
uniform vec4 LightColor[8];
......@@ -46,7 +48,8 @@ in VertexData
vec3 TangentLightPos[8];
vec3 TangentViewPos;
vec3 TangentFragPos;
}fs_in;
}
fs_in;
//////////////////// CONST ////////////////////
......@@ -122,8 +125,7 @@ void main()
// DISPLACEMENT_TEX
if (hasMaterialMap.hasDisplacement > 0.5f) {
texCoords = ParallaxMapping(viewDir);
if (texCoords.x > 1.0 || texCoords.y > 1.0 || texCoords.x < 0.0 || texCoords.y < 0.0)
discard;
if (texCoords.x > 1.0 || texCoords.y > 1.0 || texCoords.x < 0.0 || texCoords.y < 0.0) discard;
}
// -
......@@ -139,8 +141,7 @@ void main()
float alpha = 1.0;
if (hasMaterialMap.hasOpacity > 0.5f) {
alpha = texture(material.opacityMap, texCoords).r;
if (alpha == 0.0)
discard;
if (alpha == 0.0) discard;
} else {
alpha = material.opacity;
}
......@@ -150,8 +151,7 @@ void main()
ambient = Ambient * material.ambient.rgb * texture(material.ambientMap, texCoords).rgb;
// -
// AMBIENTOCCLUSION_TEX
if (hasMaterialMap.hasLightmap > 0.5f)
ambient *= texture(material.lightMap, texCoords).r;
if (hasMaterialMap.hasLightmap > 0.5f) ambient *= texture(material.lightMap, texCoords).r;
// -
// Multiple lights (Phong shading)
......@@ -175,6 +175,9 @@ void main()
// Set lights
vec4 totalColor = vec4((ambient + diffuseSum + specularSum), alpha);
#if FORCE_TRANSPARENCY
totalColor.a = 0.8;
#endif
// Clamp
FragColor = clamp(totalColor, 0.0, 1.0);
......
// SPDX-FileCopyrightText: Copyright (c) 2016-2024 CRIStAL/PIRVI. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2016-2024 Samuel Degrande
// SPDX-FileCopyrightText: Copyright (c) 2016-2025 CRIStAL/PIRVI. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2016-2025 Samuel Degrande
// SPDX-FileCopyrightText: Copyright (c) 2019 Paul-Elian Tabarant
// SPDX-FileCopyrightText: Copyright (c) 2020 Stevens Jourdain
// SPDX-License-Identifier: BSD-3-Clause
#version 420 core
// @define placeholder@
//////////////////// UNIFORM ////////////////////
// Builtins
......@@ -53,7 +55,8 @@ in VertexData
vec3 Position;
vec3 Normal;
vec2 TexCoord;
} fs_in;
}
fs_in;
//////////////////// OUT ////////////////////
......@@ -96,6 +99,9 @@ void main()
// Set lights
vec4 totalColor = vec4(vec3(ambient + diffuseSum + specularSum), material.opacity);
#if FORCE_TRANSPARENCY
totalColor.a = 0.8;
#endif
// Clamp
FragColor = clamp(totalColor, 0.0, 1.0);
......
// SPDX-FileCopyrightText: Copyright (c) 2020-2024 CRIStAL/PIRVI. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2020-2025 CRIStAL/PIRVI. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2020 Stevens Jourdain
// SPDX-FileCopyrightText: Copyright (c) 2020-2024 Samuel Degrande
// SPDX-FileCopyrightText: Copyright (c) 2020-2025 Samuel Degrande
// SPDX-License-Identifier: BSD-3-Clause
#version 420 core
// @define placeholder@
//////////////////// UNIFORM ////////////////////
uniform mat4 ModelMat;
......@@ -37,7 +39,8 @@ in VertexData
vec3 Position;
vec3 Normal;
vec2 TexCoord;
} fs_in;
}
fs_in;
//////////////////// OUT ////////////////////
......@@ -55,7 +58,8 @@ void computeLight(int lightIndex, vec3 position, vec3 norm, out vec3 diffuse, ou
vec3 viewDir = normalize(vec3(ViewPos) - position);
vec3 reflectDir = reflect(-s, n);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
specular = material.shininessStrength * spec * LightColor[lightIndex].rgb * texture(material.specular, fs_in.TexCoord).rgb;
specular =
material.shininessStrength * spec * LightColor[lightIndex].rgb * texture(material.specular, fs_in.TexCoord).rgb;
}
void main()
......@@ -76,7 +80,9 @@ void main()
// Set lights
vec4 totalColor = vec4(vec3(ambient + diffuseSum + specularSum), material.opacity);
#if FORCE_TRANSPARENCY
totalColor.a = 0.8;
#endif
// Clamp
FragColor = clamp(totalColor, 0.0, 1.0);
}
......@@ -101,14 +101,9 @@ void main()
// Set lights
vec4 totalColor =
vec4(vec3(ambient + diffuseSum + specularSum), 1.0) * texture(material.diffuseMap, fs_in.TexCoord);
#if FORCE_TRANSPARENCY
totalColor.a = 0.8;
#endif
// Clamp
#if RED
FragColor = vec4(1, 0, 0, 1);
#else
FragColor = clamp(totalColor, 0.0, 1.0);
#endif
#if BLUE
FragColor.b = 1.0;
#endif
}
......@@ -74,3 +74,17 @@ void SkeletonProgramExtension::extensionSetUniforms(GLuint programID, Renderer*
{
glProgramUniformMatrix4fv(programID, boneMatsID, 32, GL_FALSE, glm::value_ptr(boneMats[0]));
}
//=============================================================================
TransparencyProgramExtension::TransparencyProgramExtension()
{
std::string config = R"({ "fragment" : { "defines" : { "FORCE_TRANSPARENCY" : 1 } } })";
programConf = jsonFromString(config);
}
void TransparencyProgramExtension::extensionGetUniformsID(GLuint programID) {}
void TransparencyProgramExtension::extensionSetUniforms(GLuint programID, Renderer* renderer,
const glm::mat4& modelMat) const
{}
......@@ -71,4 +71,15 @@ private:
GLint boneMatsID {};
};
class TransparencyProgramExtension : public ProgramExtension
{
public:
TransparencyProgramExtension();
~TransparencyProgramExtension() override = default;
protected:
void extensionGetUniformsID(GLuint programID) override;
void extensionSetUniforms(GLuint programID, Renderer* renderer, const glm::mat4& modelMat) const override;
};
#endif // SRC_RENDERER_PROGRAMEXTENSION_HPP_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment