More Eigenization changes.

sensor-dev
Chris Laurel 2009-08-06 00:41:24 +00:00
parent 6aa1046ae2
commit afd7c78574
7 changed files with 74 additions and 65 deletions

View File

@ -517,12 +517,12 @@ setExtendedVertexArrays(const Mesh::VertexDescription& desc,
/***** GLSL render context ******/
GLSL_RenderContext::GLSL_RenderContext(const LightingState& ls, float _objRadius, const Mat4f& _xform) :
GLSL_RenderContext::GLSL_RenderContext(const LightingState& ls, float _objRadius, const Quaternionf& orientation) :
lightingState(ls),
atmosphere(NULL),
blendMode(Mesh::InvalidBlend),
objRadius(_objRadius),
xform(_xform),
objOrientation(orientation),
lunarLambert(0.0f)
{
initLightingEnvironment();
@ -682,9 +682,8 @@ GLSL_RenderContext::makeCurrent(const Mesh::Material& m)
prog->setLightParameters(lightingState, diffuse, m.specular, m.emissive);
Matrix4f xform_e = Map<Matrix4f>(&xform[0][0]);
if (shaderProps.shadowCounts != 0)
prog->setEclipseShadowParameters(lightingState, objRadius, xform_e);
prog->setEclipseShadowParameters(lightingState, objRadius, objOrientation);
// TODO: handle emissive color
prog->shininess = m.specularPower;

View File

@ -111,7 +111,9 @@ class VP_Combiner_RenderContext : public RenderContext
class GLSL_RenderContext : public RenderContext
{
public:
GLSL_RenderContext(const LightingState& ls, float _objRadius, const Mat4f& _xform);
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
GLSL_RenderContext(const LightingState& ls, float _objRadius, const Eigen::Quaternionf& orientation);
virtual ~GLSL_RenderContext();
virtual void makeCurrent(const Mesh::Material&);
@ -131,7 +133,7 @@ class GLSL_RenderContext : public RenderContext
const Atmosphere* atmosphere;
Mesh::BlendMode blendMode;
float objRadius;
Mat4f xform;
Eigen::Quaternionf objOrientation;
// extended material properties
float lunarLambert;

View File

@ -4984,10 +4984,6 @@ void Renderer::renderEllipsoidAtmosphere(const Atmosphere& atmosphere,
Vector3f recipSemiAxes = semiAxes.cwise().inverse();
Vector3f recipAtmSemiAxes = recipSemiAxes / (1.0f + height);
#if CELVEC
Mat3f A = Mat3f::scaling(recipAtmSemiAxes);
Mat3f A1 = Mat3f::scaling(recipSemiAxes);
#endif
// ellipDist is not the true distance from the surface unless the
// planet is spherical. Computing the true distance requires finding
// the roots of a sixth degree polynomial, and isn't actually what we
@ -4995,9 +4991,6 @@ void Renderer::renderEllipsoidAtmosphere(const Atmosphere& atmosphere,
// multiplied by a uniform scale factor. The value that we do compute
// is the distance to the surface along a line from the eye position to
// the center of the ellipsoid.
#if CELVEC
float ellipDist = (float) sqrt((eyeVec * A1) * (eyeVec * A1)) - 1.0f;
#endif
float ellipDist = (eyeVec.cwise() * recipSemiAxes).norm() - 1.0f;
bool within = ellipDist < height;
@ -6520,13 +6513,14 @@ renderEclipseShadows(Geometry* geometry,
vector<EclipseShadow>& eclipseShadows,
RenderInfo& ri,
float planetRadius,
Mat4f& planetMat,
Quaternionf& planetOrientation,
Frustum& viewFrustum,
const GLContext& context)
{
Transform3f planetTransform;
planetTransform.matrix() = Map<Matrix4f>(&planetMat[0][0]);
// Eclipse shadows on mesh objects aren't working yet.
Matrix3f planetTransform = planetOrientation.toRotationMatrix();
// Eclipse shadows on mesh objects are only supported in
// the OpenGL 2.0 path.
if (geometry != NULL)
return;
@ -6558,7 +6552,7 @@ renderEclipseShadows(Geometry* geometry,
// Compute the transformation to use for generating texture
// coordinates from the object vertices.
Vector3f origin = planetTransform * shadow.origin;
Vector3f dir = planetTransform.linear() * shadow.direction;
Vector3f dir = planetTransform * shadow.direction;
float scale = planetRadius / shadow.penumbraRadius;
Vector3f axis = Vector3f::UnitY().cross(dir);
float angle = std::acos(Vector3f::UnitY().dot(dir));
@ -6653,13 +6647,12 @@ renderEclipseShadows_Shaders(Geometry* geometry,
vector<EclipseShadow>& eclipseShadows,
RenderInfo& ri,
float planetRadius,
const Mat4f& planetMat,
const Quaternionf& planetOrientation,
Frustum& viewFrustum,
const GLContext& context)
{
Transform3f planetTransform;
planetTransform.matrix() = Map<Matrix4f>(&planetMat[0][0]);
Matrix3f planetTransform = planetOrientation.toRotationMatrix();
// Eclipse shadows on mesh objects are only implemented in the GLSL path
if (geometry != NULL)
return;
@ -6701,7 +6694,7 @@ renderEclipseShadows_Shaders(Geometry* geometry,
// Compute the transformation to use for generating texture
// coordinates from the object vertices.
Vector3f origin = planetTransform * shadow.origin;
Vector3f dir = planetTransform.linear() * shadow.direction;
Vector3f dir = planetTransform * shadow.direction;
float scale = planetRadius / shadow.penumbraRadius;
Vector3f axis = Vector3f::UnitY().cross(dir);
float angle = (float) acos(Vector3f::UnitY().dot(dir));
@ -6774,7 +6767,7 @@ renderRingShadowsVS(Geometry* /*geometry*/, //TODO: Remove unused para
RenderInfo& ri,
float planetRadius,
float /*oblateness*/,
Mat4f& /*planetMat*/,
Matrix4f& /*planetMat*/,
Frustum& viewFrustum,
const GLContext& context)
{
@ -7262,8 +7255,9 @@ void Renderer::renderObject(const Vector3f& pos,
}
glScale(scaleFactors);
Mat4f planetMat = fromEigen(obj.orientation.conjugate()).toMatrix4();
Matrix3f planetRotation = obj.orientation.toRotationMatrix();
Matrix4f planetMat = Matrix4f::Identity();
planetMat.corner<3, 3>(TopLeft) = planetRotation;
ri.eyeDir_obj = -(planetRotation * pos).normalized();
ri.eyePos_obj = -(planetRotation * (pos.cwise() / scaleFactors));
@ -7336,11 +7330,24 @@ void Renderer::renderObject(const Vector3f& pos,
}
// Compute the inverse model/view matrix
// TODO: This code uses the old vector classes, but will be eliminated when the new planet rendering code
// is adopted. The new planet renderer doesn't require the inverse transformed view frustum.
#if 0
Transform3f invModelView = cameraOrientation.conjugate() *
Translation3f(-pos) *
obj.orientation *
Scaling3f(1.0f / radius);
#endif
Mat4f planetMat_old(Vec4f(planetMat.col(0).x(), planetMat.col(0).y(), planetMat.col(0).z(), planetMat.col(0).w()),
Vec4f(planetMat.col(1).x(), planetMat.col(1).y(), planetMat.col(1).z(), planetMat.col(1).w()),
Vec4f(planetMat.col(2).x(), planetMat.col(2).y(), planetMat.col(2).z(), planetMat.col(2).w()),
Vec4f(planetMat.col(3).x(), planetMat.col(3).y(), planetMat.col(3).z(), planetMat.col(3).w()));
Mat4f invMV = (fromEigen(cameraOrientation).toMatrix4() *
Mat4f::translation(Point3f(-pos.x(), -pos.y(), -pos.z())) *
planetMat *
planetMat_old *
Mat4f::scaling(1.0f / radius));
// The sphere rendering code uses the view frustum to determine which
// patches are visible. In order to avoid rendering patches that can't
// be seen, make the far plane of the frustum as close to the viewer
@ -7418,7 +7425,7 @@ void Renderer::renderObject(const Vector3f& pos,
obj.radius,
textureResolution,
renderFlags,
planetMat, viewFrustum, *context);
obj.orientation, viewFrustum, *context);
break;
case GLContext::GLPath_NV30:
@ -7464,7 +7471,7 @@ void Renderer::renderObject(const Vector3f& pos,
obj.atmosphere,
geometryScale,
renderFlags,
planetMat,
obj.orientation,
astro::daysToSecs(now - astro::J2000));
}
else
@ -7474,7 +7481,7 @@ void Renderer::renderObject(const Vector3f& pos,
texOverride,
geometryScale,
renderFlags,
planetMat,
obj.orientation,
astro::daysToSecs(now - astro::J2000));
}
@ -7548,7 +7555,7 @@ void Renderer::renderObject(const Vector3f& pos,
renderAtmosphere_GLSL(ri, ls,
atmosphere,
radius * atmScale,
planetMat,
obj.orientation,
viewFrustum,
*context);
}
@ -7635,7 +7642,7 @@ void Renderer::renderObject(const Vector3f& pos,
radius,
textureResolution,
renderFlags,
planetMat,
obj.orientation,
viewFrustum,
*context);
}
@ -7702,7 +7709,7 @@ void Renderer::renderObject(const Vector3f& pos,
renderEclipseShadows_Shaders(geometry,
*ls.shadows[0],
ri,
radius, planetMat, viewFrustum,
radius, obj.orientation, viewFrustum,
*context);
}
else
@ -7710,7 +7717,7 @@ void Renderer::renderObject(const Vector3f& pos,
renderEclipseShadows(geometry,
*ls.shadows[0],
ri,
radius, planetMat, viewFrustum,
radius, obj.orientation, viewFrustum,
*context);
}
}

View File

@ -2,7 +2,8 @@
//
// Functions for rendering objects using dynamically generated GLSL shaders.
//
// Copyright (C) 2006-2007, Chris Laurel <claurel@shatters.net>
// Copyright (C) 2006-2009, the Celestia Development Team
// Original version by Chris Laurel <claurel@gmail.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@ -59,7 +60,7 @@ void renderSphere_GLSL(const RenderInfo& ri,
float radius,
unsigned int textureRes,
int renderFlags,
const Mat4f& planetMat,
const Quaternionf& planetOrientation,
const Frustum& frustum,
const GLContext& context)
{
@ -242,9 +243,8 @@ void renderSphere_GLSL(const RenderInfo& ri,
prog->setAtmosphereParameters(*atmosphere, radius, radius);
}
Matrix4f planetMat_e = Map<Matrix4f>(&planetMat[0][0]);
if (shadprop.shadowCounts != 0)
prog->setEclipseShadowParameters(ls, radius, planetMat_e);
prog->setEclipseShadowParameters(ls, radius, planetOrientation);
glColor(ri.color);
@ -271,12 +271,12 @@ void renderGeometry_GLSL(Geometry* geometry,
const Atmosphere* atmosphere,
float geometryScale,
int renderFlags,
const Mat4f& planetMat,
const Quaternionf& planetOrientation,
double tsec)
{
glDisable(GL_LIGHTING);
GLSL_RenderContext rc(ls, geometryScale, planetMat);
GLSL_RenderContext rc(ls, geometryScale, planetOrientation);
if (renderFlags & Renderer::ShowAtmospheres)
{
@ -320,7 +320,7 @@ void renderGeometry_GLSL_Unlit(Geometry* geometry,
ResourceHandle texOverride,
float geometryScale,
int /* renderFlags */,
const Mat4f& /* planetMat */,
const Quaternionf& /* planetOrientation */,
double tsec)
{
glDisable(GL_LIGHTING);
@ -362,7 +362,7 @@ void renderClouds_GLSL(const RenderInfo& ri,
float radius,
unsigned int textureRes,
int renderFlags,
const Mat4f& planetMat,
const Quaternionf& planetOrientation,
const Frustum& frustum,
const GLContext& context)
{
@ -463,9 +463,8 @@ void renderClouds_GLSL(const RenderInfo& ri,
prog->ringWidth = 1.0f / (ringWidth / cloudRadius);
}
Matrix4f planetMat_e = Map<Matrix4f>(&planetMat[0][0]);
if (shadprop.shadowCounts != 0)
prog->setEclipseShadowParameters(ls, cloudRadius, planetMat_e);
prog->setEclipseShadowParameters(ls, cloudRadius, planetOrientation);
unsigned int attributes = LODSphereMesh::Normals;
if (cloudNormalMap != NULL)
@ -487,7 +486,7 @@ renderAtmosphere_GLSL(const RenderInfo& ri,
const LightingState& ls,
Atmosphere* atmosphere,
float radius,
const Mat4f& /*planetMat*/,
const Quaternionf& /*planetOrientation*/,
const Frustum& frustum,
const GLContext& context)
{
@ -524,7 +523,7 @@ renderAtmosphere_GLSL(const RenderInfo& ri,
#if 0
// Currently eclipse shadows are ignored when rendering atmospheres
if (shadprop.shadowCounts != 0)
prog->setEclipseShadowParameters(ls, radius, planetMat);
prog->setEclipseShadowParameters(ls, radius, planetOrientation);
#endif
glPushMatrix();

View File

@ -2,7 +2,8 @@
//
// Functions for rendering objects using dynamically generated GLSL shaders.
//
// Copyright (C) 2006-2007, Chris Laurel <claurel@shatters.net>
// Copyright (C) 2006-2009, the Celestia Development Team
// Original version by Chris Laurel <claurel@gmail.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@ -13,6 +14,8 @@
#define _CELENGINE_RENDERGLSL_H_
#include <celengine/lightenv.h>
#include <Eigen/Geometry>
void renderSphere_GLSL(const RenderInfo& ri,
const LightingState& ls,
@ -22,7 +25,7 @@ void renderSphere_GLSL(const RenderInfo& ri,
float radius,
unsigned int textureRes,
int renderFlags,
const Mat4f& planetMat,
const Eigen::Quaternionf& planetOrientation,
const Frustum& frustum,
const GLContext& context);
@ -33,7 +36,7 @@ void renderGeometry_GLSL(Geometry* geometry,
const Atmosphere* atmosphere,
float geometryScale,
int renderFlags,
const Mat4f& planetMat,
const Eigen::Quaternionf& planetOrientation,
double tsec);
void renderClouds_GLSL(const RenderInfo& ri,
@ -46,7 +49,7 @@ void renderClouds_GLSL(const RenderInfo& ri,
float radius,
unsigned int textureRes,
int renderFlags,
const Mat4f& planetMat,
const Eigen::Quaternionf& planetOrientation,
const Frustum& frustum,
const GLContext& context);
@ -54,7 +57,7 @@ void renderAtmosphere_GLSL(const RenderInfo& ri,
const LightingState& ls,
Atmosphere* atmosphere,
float radius,
const Mat4f& planetMat,
const Eigen::Quaternionf& planetOrientation,
const Frustum& frustum,
const GLContext& context);
@ -72,7 +75,7 @@ void renderGeometry_GLSL_Unlit(Geometry* geometry,
ResourceHandle texOverride,
float geometryScale,
int renderFlags,
const Mat4f& planetMat,
const Eigen::Quaternionf& planetOrientation,
double tsec);

View File

@ -2538,10 +2538,9 @@ CelestiaGLProgram::setLightParameters(const LightingState& ls,
void
CelestiaGLProgram::setEclipseShadowParameters(const LightingState& ls,
float planetRadius,
const Eigen::Matrix4f& planetMat)
const Eigen::Quaternionf& planetOrientation)
{
Transform3f planetTransform;
planetTransform.matrix() = planetMat;
Matrix3f planetTransform = planetOrientation.toRotationMatrix();
for (unsigned int li = 0;
li < min(ls.nLights, MaxShaderLights);
@ -2566,15 +2565,14 @@ CelestiaGLProgram::setEclipseShadowParameters(const LightingState& ls,
// Compute the transformation to use for generating texture
// coordinates from the object vertices.
Vector3f origin = planetTransform * shadow.origin;
Vector3f dir = planetTransform.linear() * shadow.direction;
Vector3f dir = planetTransform * shadow.direction;
float scale = planetRadius / shadow.penumbraRadius;
Vector3f axis = Vector3f::UnitY().cross(dir);
float angle = (float) acos(Vector3f::UnitY().dot(dir));
axis.normalize();
Matrix3f mat = AngleAxisf(angle, axis).toRotationMatrix();
Vector3f sAxis = mat * Vector3f::UnitX() * (0.5f * scale);
Vector3f tAxis = mat * Vector3f::UnitZ() * (0.5f * scale);
Quaternionf shadowRotation;
shadowRotation.setFromTwoVectors(Vector3f::UnitY(), dir);
Matrix3f m = shadowRotation.toRotationMatrix();
Vector3f sAxis = m * Vector3f::UnitX() * (0.5f * scale);
Vector3f tAxis = m * Vector3f::UnitZ() * (0.5f * scale);
Vector4f texGenS;
Vector4f texGenT;
@ -2590,7 +2588,7 @@ CelestiaGLProgram::setEclipseShadowParameters(const LightingState& ls,
}
// Set the scattering and absoroption shader parameters for atmosphere simulation.
// Set the scattering and absorption shader parameters for atmosphere simulation.
// They are from standard units to the normalized system used by the shaders.
// atmPlanetRadius - the radius in km of the planet with the atmosphere
// objRadius - the radius in km of the object we're rendering

View File

@ -15,6 +15,7 @@
#include <celengine/glshader.h>
#include <celengine/lightenv.h>
#include <celengine/atmosphere.h>
#include <Eigen/Geometry>
#define ADVANCED_CLOUD_SHADOWS 0
@ -124,7 +125,7 @@ class CelestiaGLProgram
);
void setEclipseShadowParameters(const LightingState& ls,
float planetRadius,
const Eigen::Matrix4f& planetMat);
const Eigen::Quaternionf& planetOrientation);
void setAtmosphereParameters(const Atmosphere& atmosphere,
float atmPlanetRadius,
float objRadius);