+++ /dev/null
-#ifndef MSP_GL_CAMERA_BACKEND_H_
-#define MSP_GL_CAMERA_BACKEND_H_
-
-namespace Msp {
-namespace GL {
-
-class Matrix;
-
-class OpenGLCamera
-{
-protected:
- static void adjust_projection_matrix(Matrix &) { }
-};
-
-using CameraBackend = OpenGLCamera;
-
-} // namespace GL
-} // namespace Msp
-
-#endif
+++ /dev/null
-#include "camera_backend.h"
-#include "matrix.h"
-
-namespace Msp {
-namespace GL {
-
-void VulkanCamera::adjust_projection_matrix(Matrix &proj_matrix)
-{
- Matrix adjust;
- adjust(2, 2) = 0.5f;
- adjust(2, 3) = 0.5f;
- proj_matrix = adjust*proj_matrix;
-}
-
-} // namespace GL
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_GL_CAMERA_BACKEND_H_
-#define MSP_GL_CAMERA_BACKEND_H_
-
-namespace Msp {
-namespace GL {
-
-class Matrix;
-
-class VulkanCamera
-{
-protected:
- static void adjust_projection_matrix(Matrix &);
-};
-
-using CameraBackend = VulkanCamera;
-
-} // namespace GL
-} // namespace Msp
-
-#endif
Matrix result;
result(0, 0) = 2/(r-l);
result(1, 1) = 2/(t-b);
- result(2, 2) = -2/(f-n);
+ result(2, 2) = -1/(f-n);
result(0, 3) = -(r+l)/(r-l);
result(1, 3) = -(t+b)/(t-b);
- result(2, 3) = -(f+n)/(f-n);
+ result(2, 3) = 0.5f-0.5f*(f+n)/(f-n);
return result;
}
result(1, 1) = 2*n/(t-b);
result(0, 2) = (r+l)/(r-l);
result(1, 2) = (t+b)/(t-b);
- result(2, 2) = -(f+n)/(f-n);
+ result(2, 2) = -f/(f-n);
result(3, 2) = -1;
- result(2, 3) = -2*f*n/(f-n);
+ result(2, 3) = -f*n/(f-n);
result(3, 3) = 0;
return result;
}
{
float distance = (sqrt(2.0f/3.0f)-sqrt(3.0f/8.0f))*2.0f;
float bias = depth_bias*2.0f/(distance*l.region.width);
- shdata.uniform(base+".bias", -1001.0f/999.0f, 1.0f-bias);
+ shdata.uniform(base+".bias", views[l.view_index].camera.get_projection_matrix()(2, 2), 1.0f-bias);
}
}
v.camera.set_depth_clip(radius/1000.0f, radius);
}
- Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.5f)).scale(0.5f);
+ Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.0f)).scale(Vector3(0.5f, 0.5f, 1.0f));
shadow_matrices.push_back(to_texcoord*v.camera.get_projection_matrix()*v.camera.get_view_matrix());
}
for(Stage &s: module->stages)
ConstantSpecializer().apply(s, spec_values);
}
+ if(mode==PROGRAM)
+ {
+ for(Stage &s: module->stages)
+ DepthRangeConverter().apply(s, features);
+ }
for(auto i=module->stages.begin(); i!=module->stages.end(); )
{
OptimizeResult result = optimize(*i);
}
+void DepthRangeConverter::apply(Stage &stage, const Features &features)
+{
+ if(stage.type!=Stage::VERTEX || features.target_api==VULKAN)
+ return;
+
+ stage.content.visit(*this);
+}
+
+void DepthRangeConverter::visit(FunctionDeclaration &func)
+{
+ if(func.definition==&func && func.name=="main")
+ {
+ VariableReference *position = new VariableReference;
+ position->name = "gl_Position";
+
+ MemberAccess *z = new MemberAccess;
+ z->left = position;
+ z->member = "z";
+
+ Literal *scale = new Literal;
+ scale->token = "2.0";
+ scale->value = 2.0f;
+
+ BinaryExpression *multiply = new BinaryExpression;
+ multiply->oper = &Operator::get_operator("*", Operator::BINARY);
+ multiply->left = z;
+ multiply->right = scale;
+
+ MemberAccess *w = new MemberAccess;
+ w->left = position->clone();
+ w->member = "w";
+
+ BinaryExpression *subtract = new BinaryExpression;
+ subtract->oper = &Operator::get_operator("-", Operator::BINARY);
+ subtract->left = multiply;
+ subtract->right = w;
+
+ Assignment *assign = new Assignment;
+ assign->oper = &Operator::get_operator("=", Operator::BINARY);
+ assign->left = z->clone();
+ assign->right = subtract;
+
+ ExpressionStatement *statement = new ExpressionStatement;
+ statement->expression = assign;
+
+ func.body.body.push_back(statement);
+ }
+}
+
+
void PrecisionConverter::apply(Stage &s)
{
stage = &s;
virtual void visit(FunctionDeclaration &) { }
};
+/**
+Converts the output depth range to match expectations of the target API.
+*/
+class DepthRangeConverter: private TraversingVisitor
+{
+public:
+ void apply(Stage &, const Features &);
+
+private:
+ virtual void visit(FunctionDeclaration &);
+};
+
/** Generates default precision declarations or removes precision declarations
according to the requirements of the target API. */
class PrecisionConverter: private TraversingVisitor
proj_matrix = Matrix::ortho(left, right, bottom, top, clip_near, clip_far);
proj_matrix = Matrix::rotation(rotate, Vector3(0, 0, 1))*proj_matrix;
- adjust_projection_matrix(proj_matrix);
-
shdata.uniform("clip_eye_matrix", proj_matrix);
shdata.uniform("eye_clip_matrix", invert(proj_matrix));
}
#define MSP_GL_CAMERA_H_
#include <msp/datafile/objectloader.h>
-#include "camera_backend.h"
#include "placeable.h"
#include "programdata.h"
directions. Setting the up direction to the opposite of gravity direction is
an easy way to keep the camera upright.
*/
-class Camera: public CameraBackend, public Placeable
+class Camera: public Placeable
{
public:
class Loader: public DataFile::ObjectLoader<Camera>