Fixed ISS' normals transformation.

This commit is contained in:
Jonathas Costa
2020-06-28 13:08:07 -04:00
parent 6c57e395e7
commit 071bea6b25
3 changed files with 20 additions and 8 deletions

View File

@@ -47,10 +47,11 @@ namespace {
constexpr const char* ProgramName = "ModelProgram";
constexpr const char* KeyGeometry = "Geometry";
constexpr const std::array<const char*, 11> UniformNames = {
constexpr const std::array<const char*, 12> UniformNames = {
"opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities",
"modelViewTransform", "projectionTransform", "performShading", "texture1",
"ambientIntensity", "diffuseIntensity", "specularIntensity"
"modelViewTransform", "crippedModelViewTransform", "projectionTransform",
"performShading", "texture1", "ambientIntensity", "diffuseIntensity",
"specularIntensity"
};
constexpr openspace::properties::Property::PropertyInfo TextureInfo = {
@@ -380,6 +381,16 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
_uniformCache.modelViewTransform,
glm::mat4(modelViewTransform)
);
glm::dmat4 crippedModelViewTransform = glm::transpose(glm::inverse(
glm::dmat4(glm::inverse(data.camera.sgctInternal.viewMatrix())) * modelViewTransform
));
_program->setUniform(
_uniformCache.crippedModelViewTransform,
glm::mat4(crippedModelViewTransform)
);
_program->setUniform(
_uniformCache.projectionTransform,
data.camera.projectionMatrix()

View File

@@ -88,8 +88,9 @@ private:
ghoul::opengl::ProgramObject* _program = nullptr;
UniformCache(opacity, nLightSources, lightDirectionsViewSpace, lightIntensities,
modelViewTransform, projectionTransform, performShading, texture,
ambientIntensity, diffuseIntensity, specularIntensity) _uniformCache;
modelViewTransform, crippedModelViewTransform, projectionTransform,
performShading, texture, ambientIntensity, diffuseIntensity,
specularIntensity) _uniformCache;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::vector<std::unique_ptr<LightSource>> _lightSources;

View File

@@ -37,7 +37,7 @@ out vec4 vs_positionCameraSpace;
uniform mat4 modelViewTransform;
uniform mat4 projectionTransform;
uniform mat4 crippedModelViewTransform;
void main() {
vs_positionCameraSpace = modelViewTransform * in_position;
@@ -48,6 +48,6 @@ void main() {
vs_st = in_st;
vs_screenSpaceDepth = positionScreenSpace.w;
// The normal transform should be the transposed inverse of the model transform?
vs_normalViewSpace = normalize(mat3(modelViewTransform) * in_normal);
//vs_normalViewSpace = normalize(transpose(inverse(mat3(crippedModelViewTransform))) * in_normal);
vs_normalViewSpace = normalize(mat3(crippedModelViewTransform) * in_normal);
}