mirror of
https://github.com/godotengine/godot
synced 2024-09-05 12:28:27 +00:00
Merge pull request #79812 from ParsleighScumble/parsleigh/init-sky-scene-state
Use defaults to initialize sky data in case of no sky
This commit is contained in:
commit
08cffc128f
|
@ -608,6 +608,7 @@ void RasterizerSceneGLES3::_setup_sky(const RenderDataGLES3 *p_render_data, cons
|
|||
material = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!material) {
|
||||
sky_material = sky_globals.default_material;
|
||||
|
@ -620,6 +621,7 @@ void RasterizerSceneGLES3::_setup_sky(const RenderDataGLES3 *p_render_data, cons
|
|||
|
||||
ERR_FAIL_COND(!shader_data);
|
||||
|
||||
if (sky) {
|
||||
if (shader_data->uses_time && time - sky->prev_time > 0.00001) {
|
||||
sky->prev_time = time;
|
||||
sky->reflection_dirty = true;
|
||||
|
@ -640,6 +642,7 @@ void RasterizerSceneGLES3::_setup_sky(const RenderDataGLES3 *p_render_data, cons
|
|||
sky->prev_position = p_transform.origin;
|
||||
sky->reflection_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, SKY_DIRECTIONAL_LIGHT_UNIFORM_LOCATION, sky_globals.directional_light_buffer);
|
||||
if (shader_data->uses_light) {
|
||||
|
@ -732,20 +735,21 @@ void RasterizerSceneGLES3::_setup_sky(const RenderDataGLES3 *p_render_data, cons
|
|||
sky_globals.last_frame_directional_lights = sky_globals.directional_lights;
|
||||
sky_globals.directional_lights = temp;
|
||||
sky_globals.last_frame_directional_light_count = sky_globals.directional_light_count;
|
||||
if (sky) {
|
||||
sky->reflection_dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (p_render_data->view_count > 1) {
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, SKY_MULTIVIEW_UNIFORM_LOCATION, scene_state.multiview_buffer);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
}
|
||||
|
||||
if (!sky->radiance) {
|
||||
if (sky && !sky->radiance) {
|
||||
_invalidate_sky(sky);
|
||||
_update_dirty_skys();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::_draw_sky(RID p_env, const Projection &p_projection, const Transform3D &p_transform, float p_luminance_multiplier, bool p_use_multiview, bool p_flip_y) {
|
||||
|
|
|
@ -1021,6 +1021,7 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
material = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!material) {
|
||||
sky_material = sky_shader.default_material;
|
||||
|
@ -1035,11 +1036,12 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
|
||||
material->set_as_used();
|
||||
|
||||
// Save our screen size, our buffers will already have been cleared
|
||||
if (sky) {
|
||||
// Save our screen size; our buffers will already have been cleared.
|
||||
sky->screen_size.x = p_screen_size.x < 4 ? 4 : p_screen_size.x;
|
||||
sky->screen_size.y = p_screen_size.y < 4 ? 4 : p_screen_size.y;
|
||||
|
||||
// Trigger updating radiance buffers
|
||||
// Trigger updating radiance buffers.
|
||||
if (sky->radiance.is_null()) {
|
||||
invalidate_sky(sky);
|
||||
update_dirty_skys();
|
||||
|
@ -1065,12 +1067,13 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
sky->prev_position = p_cam_transform.origin;
|
||||
sky->reflection.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
sky_scene_state.ubo.directional_light_count = 0;
|
||||
if (shader_data->uses_light) {
|
||||
// Run through the list of lights in the scene and pick out the Directional Lights.
|
||||
// This can't be done in RenderSceneRenderRD::_setup lights because that needs to be called
|
||||
// after the depth prepass, but this runs before the depth prepass
|
||||
// after the depth prepass, but this runs before the depth prepass.
|
||||
for (int i = 0; i < (int)p_lights.size(); i++) {
|
||||
if (!light_storage->owns_light_instance(p_lights[i])) {
|
||||
continue;
|
||||
|
@ -1110,8 +1113,8 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
float angular_diameter = light_storage->light_get_param(base, RS::LIGHT_PARAM_SIZE);
|
||||
if (angular_diameter > 0.0) {
|
||||
// I know tan(0) is 0, but let's not risk it with numerical precision.
|
||||
// technically this will keep expanding until reaching the sun, but all we care
|
||||
// is expand until we reach the radius of the near plane (there can't be more occluders than that)
|
||||
// Technically this will keep expanding until reaching the sun, but all we care about
|
||||
// is expanding until we reach the radius of the near plane. There can't be more occluders than that.
|
||||
angular_diameter = Math::tan(Math::deg_to_rad(angular_diameter));
|
||||
} else {
|
||||
angular_diameter = 0.0;
|
||||
|
@ -1123,11 +1126,11 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
}
|
||||
}
|
||||
}
|
||||
// Check whether the directional_light_buffer changes
|
||||
// Check whether the directional_light_buffer changes.
|
||||
bool light_data_dirty = false;
|
||||
|
||||
// Light buffer is dirty if we have fewer or more lights
|
||||
// If we have fewer lights, make sure that old lights are disabled
|
||||
// Light buffer is dirty if we have fewer or more lights.
|
||||
// If we have fewer lights, make sure that old lights are disabled.
|
||||
if (sky_scene_state.ubo.directional_light_count != sky_scene_state.last_frame_directional_light_count) {
|
||||
light_data_dirty = true;
|
||||
for (uint32_t i = sky_scene_state.ubo.directional_light_count; i < sky_scene_state.max_directional_lights; i++) {
|
||||
|
@ -1160,12 +1163,13 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
sky_scene_state.last_frame_directional_lights = sky_scene_state.directional_lights;
|
||||
sky_scene_state.directional_lights = temp;
|
||||
sky_scene_state.last_frame_directional_light_count = sky_scene_state.ubo.directional_light_count;
|
||||
if (sky) {
|
||||
sky->reflection.dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//setup fog variables
|
||||
// Setup fog variables.
|
||||
sky_scene_state.ubo.volumetric_fog_enabled = false;
|
||||
if (p_render_buffers.is_valid()) {
|
||||
if (p_render_buffers->has_custom_data(RB_SCOPE_FOG)) {
|
||||
|
@ -1179,7 +1183,7 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
sky_scene_state.ubo.volumetric_fog_inv_length = 1.0;
|
||||
}
|
||||
|
||||
float fog_detail_spread = fog->spread; //reverse lookup
|
||||
float fog_detail_spread = fog->spread; // Reverse lookup.
|
||||
if (fog_detail_spread > 0.0) {
|
||||
sky_scene_state.ubo.volumetric_fog_detail_spread = 1.0 / fog_detail_spread;
|
||||
} else {
|
||||
|
@ -1192,9 +1196,9 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
|
||||
sky_scene_state.view_count = p_view_count;
|
||||
sky_scene_state.cam_transform = p_cam_transform;
|
||||
sky_scene_state.cam_projection = p_cam_projection; // We only use this when rendering a single view
|
||||
sky_scene_state.cam_projection = p_cam_projection; // We only use this when rendering a single view.
|
||||
|
||||
// Our info in our UBO is only used if we're rendering stereo
|
||||
// Our info in our UBO is only used if we're rendering stereo.
|
||||
for (uint32_t i = 0; i < p_view_count; i++) {
|
||||
Projection view_inv_projection = p_view_projections[i].inverse();
|
||||
if (p_view_count > 1) {
|
||||
|
@ -1211,7 +1215,7 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
|||
sky_scene_state.ubo.view_eye_offsets[i][3] = 0.0;
|
||||
}
|
||||
|
||||
sky_scene_state.ubo.z_far = p_view_projections[0].get_z_far(); // Should be the same for all projection
|
||||
sky_scene_state.ubo.z_far = p_view_projections[0].get_z_far(); // Should be the same for all projection.
|
||||
sky_scene_state.ubo.fog_enabled = RendererSceneRenderRD::get_singleton()->environment_get_fog_enabled(p_env);
|
||||
sky_scene_state.ubo.fog_density = RendererSceneRenderRD::get_singleton()->environment_get_fog_density(p_env);
|
||||
sky_scene_state.ubo.fog_aerial_perspective = RendererSceneRenderRD::get_singleton()->environment_get_fog_aerial_perspective(p_env);
|
||||
|
|
Loading…
Reference in a new issue