From: Mikko Rasa Date: Sat, 9 Oct 2021 09:52:29 +0000 (+0300) Subject: Add an option to use a fixed position in EnvironmentMap X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3867df2040d1fb955158ca3bd8fbf5271ad66fb2;p=libs%2Fgl.git Add an option to use a fixed position in EnvironmentMap 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. --- diff --git a/source/effects/environmentmap.cpp b/source/effects/environmentmap.cpp index 315390b1..47cea090 100644 --- a/source/effects/environmentmap.cpp +++ b/source/effects/environmentmap.cpp @@ -79,6 +79,12 @@ EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, unsigned l, Renderable shdata.uniform("env_world_matrix", LinAl::SquareMatrix::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); diff --git a/source/effects/environmentmap.h b/source/effects/environmentmap.h index bf6fbaf0..2d27ee7d 100644 --- a/source/effects/environmentmap.h +++ b/source/effects/environmentmap.h @@ -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