summaryrefslogtreecommitdiff
path: root/drivers/gles3
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2018-12-15 16:27:03 +1100
committerBastiaan Olij <mux213@gmail.com>2018-12-15 19:41:34 +1100
commitf3dd3c0830e620b20ba6d0364537bf6e9235a8fb (patch)
tree8f1436334ce4e0493afdeafc9ea95f2cd1733a75 /drivers/gles3
parent5f32fc82087404ac2c803770dc9d1e3711fc14fd (diff)
Adding option to re-orient our sky
Diffstat (limited to 'drivers/gles3')
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp23
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h6
-rw-r--r--drivers/gles3/shaders/copy.glsl10
3 files changed, 32 insertions, 7 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index ffe9e1c831..183fe8c5f8 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -791,6 +791,14 @@ void RasterizerSceneGLES3::environment_set_sky_custom_fov(RID p_env, float p_sca
env->sky_custom_fov = p_scale;
}
+void RasterizerSceneGLES3::environment_set_sky_orientation(RID p_env, const Basis &p_orientation) {
+
+ Environment *env = environment_owner.getornull(p_env);
+ ERR_FAIL_COND(!env);
+
+ env->sky_orientation = p_orientation;
+}
+
void RasterizerSceneGLES3::environment_set_bg_color(RID p_env, const Color &p_color) {
Environment *env = environment_owner.getornull(p_env);
@@ -2427,7 +2435,7 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G
}
}
-void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy) {
+void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation) {
ERR_FAIL_COND(!p_sky);
@@ -2519,7 +2527,12 @@ void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const C
storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_PANORAMA, !asymmetrical);
storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_MULTIPLIER, true);
storage->shaders.copy.bind();
+
storage->shaders.copy.set_uniform(CopyShaderGLES3::MULTIPLIER, p_energy);
+
+ // don't know why but I always have problems setting a uniform mat3, so we're using a transform
+ storage->shaders.copy.set_uniform(CopyShaderGLES3::SKY_TRANSFORM, Transform(p_sky_orientation, Vector3(0.0, 0.0, 0.0)).affine_inverse());
+
if (asymmetrical) {
// pack the bits we need from our projection matrix
storage->shaders.copy.set_uniform(CopyShaderGLES3::ASYM_PROJ, camera.matrix[2][0], camera.matrix[0][0], camera.matrix[2][1], camera.matrix[1][1]);
@@ -2538,6 +2551,7 @@ void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const C
}
void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform, bool p_no_fog) {
+ Transform sky_orientation;
//store camera into ubo
store_camera(p_cam_projection, state.ubo_data.projection_matrix);
@@ -2578,6 +2592,9 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr
state.ubo_data.bg_color[2] = bg_color.b;
state.ubo_data.bg_color[3] = bg_color.a;
+ //use the inverse of our sky_orientation, we may need to skip this if we're using a reflection probe?
+ sky_orientation = Transform(env->sky_orientation, Vector3(0.0, 0.0, 0.0)).affine_inverse();
+
state.env_radiance_data.ambient_contribution = env->ambient_sky_contribution;
state.ubo_data.ambient_occlusion_affect_light = env->ssao_light_affect;
state.ubo_data.ambient_occlusion_affect_ssao = env->ssao_ao_channel_affect;
@@ -2646,7 +2663,7 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr
//fill up environment
- store_transform(p_cam_transform, state.env_radiance_data.transform);
+ store_transform(sky_orientation * p_cam_transform, state.env_radiance_data.transform);
glBindBuffer(GL_UNIFORM_BUFFER, state.env_radiance_ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(State::EnvironmentRadianceUBO), &state.env_radiance_data);
@@ -4389,7 +4406,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
*/
if (sky && sky->panorama.is_valid())
- _draw_sky(sky, p_cam_projection, p_cam_transform, false, env->sky_custom_fov, env->bg_energy);
+ _draw_sky(sky, p_cam_projection, p_cam_transform, false, env->sky_custom_fov, env->bg_energy, env->sky_orientation);
}
//_render_list_forward(&alpha_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting,true);
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index 1d84fb487b..a198168da8 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -114,7 +114,7 @@ public:
TonemapShaderGLES3 tonemap_shader;
struct SceneDataUBO {
- //this is a std140 compatible struct. Please read the OpenGL 3.3 Specificaiton spec before doing any changes
+ //this is a std140 compatible struct. Please read the OpenGL 3.3 Specification spec before doing any changes
float projection_matrix[16];
float inv_projection_matrix[16];
float camera_inverse_matrix[16];
@@ -365,6 +365,7 @@ public:
RID sky;
float sky_custom_fov;
+ Basis sky_orientation;
Color bg_color;
float bg_energy;
@@ -531,6 +532,7 @@ public:
virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg);
virtual void environment_set_sky(RID p_env, RID p_sky);
virtual void environment_set_sky_custom_fov(RID p_env, float p_scale);
+ virtual void environment_set_sky_orientation(RID p_env, const Basis &p_orientation);
virtual void environment_set_bg_color(RID p_env, const Color &p_color);
virtual void environment_set_bg_energy(RID p_env, float p_energy);
virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer);
@@ -823,7 +825,7 @@ public:
_FORCE_INLINE_ void _add_geometry_with_material(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, RasterizerStorageGLES3::Material *p_material, bool p_depth_pass, bool p_shadow_pass);
- void _draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy);
+ void _draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation);
void _setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform, bool p_no_fog = false);
void _setup_directional_light(int p_index, const Transform &p_camera_inverse_transform, bool p_use_shadows);
diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl
index a5637537d2..3b36bc7cc1 100644
--- a/drivers/gles3/shaders/copy.glsl
+++ b/drivers/gles3/shaders/copy.glsl
@@ -79,6 +79,7 @@ uniform float multiplier;
#endif
#if defined(USE_PANORAMA) || defined(USE_ASYM_PANO)
+uniform highp mat4 sky_transform;
vec4 texturePanorama(vec3 normal, sampler2D pano) {
@@ -121,7 +122,12 @@ void main() {
#ifdef USE_PANORAMA
- vec4 color = texturePanorama(normalize(cube_interp), source);
+ vec3 cube_normal = normalize(cube_interp);
+ cube_normal.z = -cube_normal.z;
+ cube_normal = mat3(sky_transform) * cube_normal;
+ cube_normal.z = -cube_normal.z;
+
+ vec4 color = texturePanorama(cube_normal, source);
#elif defined(USE_ASYM_PANO)
@@ -133,7 +139,7 @@ void main() {
cube_normal.z = -1000000.0;
cube_normal.x = (cube_normal.z * (-uv_interp.x - asym_proj.x)) / asym_proj.y;
cube_normal.y = (cube_normal.z * (-uv_interp.y - asym_proj.z)) / asym_proj.a;
- cube_normal = mat3(pano_transform) * cube_normal;
+ cube_normal = mat3(sky_transform) * mat3(pano_transform) * cube_normal;
cube_normal.z = -cube_normal.z;
vec4 color = texturePanorama(normalize(cube_normal.xyz), source);