Fix modelshader example in Debug mode

This commit is contained in:
Malin E
2023-05-22 11:37:28 +02:00
parent 156d0a8459
commit 0490e94350
5 changed files with 59 additions and 35 deletions
@@ -45,8 +45,8 @@ uniform sampler2D texture_diffuse;
uniform sampler2D texture_normal;
uniform sampler2D texture_specular;
uniform vec3 color_diffuse;
uniform vec3 color_specular;
uniform vec4 color_diffuse;
uniform vec4 color_specular;
uniform float opacity = 1.0;
uniform int nLightSources;
@@ -83,14 +83,17 @@ Fragment getFragment() {
}
// Frag color is the values of the normal vector
vec3 normal;
if (has_texture_normal) {
vec3 normalAlbedo = texture(texture_normal, vs_st).rgb;
normalAlbedo = normalize(normalAlbedo * 2.0 - 1.0);
frag.color.rgb = normalize(vs_TBN * normalAlbedo);
normal = normalize(vs_TBN * normalAlbedo);
}
else {
frag.color.rgb = normalize(vs_normalViewSpace);
normal = normalize(vs_normalViewSpace);
}
frag.color.rgb = normal;
frag.color.a = opacity;
return frag;
}
@@ -43,6 +43,7 @@ uniform mat4 normalTransform;
uniform mat4 meshTransform;
uniform mat4 meshNormalTransform;
void main() {
vs_positionCameraSpace = modelViewTransform * (meshTransform * in_position);
vec4 positionClipSpace = projectionTransform * vs_positionCameraSpace;
@@ -21,10 +21,9 @@ local model = {
Type = "RenderableModel",
GeometryFile = model .. "BoxAnimated.glb",
ModelScale = 3E7,
LightSources = {
sun.LightSource
},
PerformShading = true,
-- (malej 2023-MAY-22) Note that PerformShading should be false in this example,
-- these example shaders dont't contain any light calculations
PerformShading = false,
VertexShader = asset.localResource("model_vs.glsl"),
FragmentShader = asset.localResource("model_fs.glsl"),
EnableAnimation = true,
+40 -22
View File
@@ -73,12 +73,14 @@ namespace {
GL_COLOR_ATTACHMENT2,
};
constexpr std::array<const char*, 14> UniformNames = {
"nLightSources", "lightDirectionsViewSpace", "lightIntensities",
"modelViewTransform", "normalTransform", "projectionTransform",
"performShading", "ambientIntensity", "diffuseIntensity",
"specularIntensity", "performManualDepthTest", "gBufferDepthTexture",
"resolution", "opacity"
constexpr std::array<const char*, 26> UniformNames = {
"modelViewTransform", "projectionTransform", "normalTransform", "meshTransform",
"meshNormalTransform", "ambientIntensity", "diffuseIntensity",
"specularIntensity", "performShading", "use_forced_color", "has_texture_diffuse",
"has_texture_normal", "has_texture_specular", "has_color_specular",
"texture_diffuse", "texture_normal", "texture_specular", "color_diffuse",
"color_specular", "opacity", "nLightSources", "lightDirectionsViewSpace",
"lightIntensities", "performManualDepthTest", "gBufferDepthTexture", "resolution"
};
constexpr std::array<const char*, 5> UniformOpacityNames = {
@@ -737,18 +739,29 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
++nLightSources;
}
_program->setUniform(
_uniformCache.nLightSources,
nLightSources
);
_program->setUniform(
_uniformCache.lightIntensities,
_lightIntensitiesBuffer
);
_program->setUniform(
_uniformCache.lightDirectionsViewSpace,
_lightDirectionsViewSpaceBuffer
);
if (_uniformCache.performShading != -1) {
_program->setUniform(_uniformCache.performShading, _performShading);
}
if (_performShading) {
_program->setUniform(
_uniformCache.nLightSources,
nLightSources
);
_program->setUniform(
_uniformCache.lightIntensities,
_lightIntensitiesBuffer
);
_program->setUniform(
_uniformCache.lightDirectionsViewSpace,
_lightDirectionsViewSpaceBuffer
);
_program->setUniform(_uniformCache.ambientIntensity, _ambientIntensity);
_program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity);
_program->setUniform(_uniformCache.specularIntensity, _specularIntensity);
}
_program->setUniform(
_uniformCache.modelViewTransform,
glm::mat4(modelViewTransform)
@@ -765,10 +778,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
_uniformCache.projectionTransform,
data.camera.projectionMatrix()
);
_program->setUniform(_uniformCache.ambientIntensity, _ambientIntensity);
_program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity);
_program->setUniform(_uniformCache.specularIntensity, _specularIntensity);
_program->setUniform(_uniformCache.performShading, _performShading);
if (!_enableFaceCulling) {
glDisable(GL_CULL_FACE);
@@ -944,6 +953,15 @@ void RenderableModel::update(const UpdateData& data) {
ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames);
}
if (_quadProgram->isDirty()) {
_quadProgram->rebuildFromFile();
ghoul::opengl::updateUniformLocations(
*_quadProgram,
_uniformOpacityCache,
UniformOpacityNames
);
}
if (!hasOverrideRenderBin()) {
// Only render two pass if the model is in any way transparent
const float o = opacity();
+8 -5
View File
@@ -102,11 +102,14 @@ private:
std::string _vertexShaderPath;
std::string _fragmentShaderPath;
ghoul::opengl::ProgramObject* _program = nullptr;
UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities,
modelViewTransform, normalTransform, projectionTransform,
performShading, ambientIntensity, diffuseIntensity,
specularIntensity, performManualDepthTest, gBufferDepthTexture,
resolution, opacity) _uniformCache;
UniformCache(modelViewTransform, projectionTransform, normalTransform, meshTransform,
meshNormalTransform, ambientIntensity, diffuseIntensity,
specularIntensity, performShading, use_forced_color, has_texture_diffuse,
has_texture_normal, has_texture_specular, has_color_specular,
texture_diffuse, texture_normal, texture_specular, color_diffuse,
color_specular, opacity, nLightSources, lightDirectionsViewSpace,
lightIntensities, performManualDepthTest, gBufferDepthTexture, resolution
) _uniformCache;
std::vector<std::unique_ptr<LightSource>> _lightSources;