]> git.tdb.fi Git - libs/gl.git/commitdiff
Add an option to use a fixed position in EnvironmentMap
authorMikko Rasa <tdb@tdb.fi>
Sat, 9 Oct 2021 09:52:29 +0000 (12:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 9 Oct 2021 09:53:31 +0000 (12:53 +0300)
This allows environment maps which are not tied to a particular object.

It's required for 0b76663 but I forgot to commit it before that.

source/effects/environmentmap.cpp
source/effects/environmentmap.h

index 315390b1ca81664c47a2a5c940ef445ee94faa97..47cea0904017c2daa7bbeff4328ec7d5d4128573 100644 (file)
@@ -79,6 +79,12 @@ EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, unsigned l, Renderable
        shdata.uniform("env_world_matrix", LinAl::SquareMatrix<float, 3>::identity());
 }
 
+void EnvironmentMap::set_fixed_position(const Vector3 &p)
+{
+       fixed_position = p;
+       use_fixed_pos = true;
+}
+
 void EnvironmentMap::set_depth_clip(float n, float f)
 {
        for(unsigned i=0; i<6; ++i)
@@ -113,16 +119,22 @@ void EnvironmentMap::setup_frame(Renderer &renderer)
        update_delay = update_interval-1;
        environment.setup_frame(renderer);
 
-       const Matrix *matrix = renderable.get_matrix();
-       if(!matrix)
-               return;
+       Vector3 center;
+       if(use_fixed_pos)
+               center = fixed_position;
+       else
+       {
+               const Matrix *matrix = renderable.get_matrix();
+               if(!matrix)
+                       return;
+
+               center = matrix->column(3).slice<3>(0);
+       }
 
        Renderer::Push push(renderer);
        Renderer::Exclude exclude1(renderer, renderable);
        Renderer::Exclude exclude2(renderer, *this);
 
-       Vector3 center = matrix->column(3).slice<3>(0);
-
        for(unsigned i=0; i<6; ++i)
        {
                faces[i].camera.set_position(center);
index bf6fbaf0f2b77081ffea4638400554837b91775c..2d27ee7d86cfd53e82af53589ecfb8f420d01a59 100644 (file)
@@ -38,6 +38,8 @@ private:
        TextureCube env_tex;
        Texture2D depth_buf;
        Face faces[6];
+       Vector3 fixed_position;
+       bool use_fixed_pos = false;
 
        TextureCube irradiance;
        const Program &irradiance_shprog;
@@ -58,6 +60,8 @@ public:
        EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
        EnvironmentMap(unsigned size, PixelFormat, unsigned, Renderable &rend, Renderable &env);
 
+       void set_fixed_position(const Vector3 &);
+
        void set_depth_clip(float, float);
 
        /** Sets the interval in frames between environment map updates.  A value of