feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#ifndef FORWARD_ID_STORAGE_H
|
||||
#define FORWARD_ID_STORAGE_H
|
||||
|
||||
#include "servers/rendering/storage/utilities.h"
|
||||
#include <stdint.h>
|
||||
|
||||
class RendererSceneRenderRD;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,18 @@ LightStorage::LightStorage() {
|
|||
|
||||
if (textures_per_stage <= 256) {
|
||||
lightmap_textures.resize(32);
|
||||
shadowmask_textures.resize(32);
|
||||
} else {
|
||||
lightmap_textures.resize(1024);
|
||||
shadowmask_textures.resize(1024);
|
||||
}
|
||||
|
||||
for (int i = 0; i < lightmap_textures.size(); i++) {
|
||||
lightmap_textures.write[i] = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE);
|
||||
for (RID &lightmap_texture : lightmap_textures) {
|
||||
lightmap_texture = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE);
|
||||
}
|
||||
|
||||
for (RID &shadowmask_texture : shadowmask_textures) {
|
||||
shadowmask_texture = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -285,6 +291,23 @@ void LightStorage::light_set_reverse_cull_face_mode(RID p_light, bool p_enabled)
|
|||
light->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_LIGHT);
|
||||
}
|
||||
|
||||
void LightStorage::light_set_shadow_caster_mask(RID p_light, uint32_t p_caster_mask) {
|
||||
Light *light = light_owner.get_or_null(p_light);
|
||||
ERR_FAIL_NULL(light);
|
||||
|
||||
light->shadow_caster_mask = p_caster_mask;
|
||||
|
||||
light->version++;
|
||||
light->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_LIGHT);
|
||||
}
|
||||
|
||||
uint32_t LightStorage::light_get_shadow_caster_mask(RID p_light) const {
|
||||
Light *light = light_owner.get_or_null(p_light);
|
||||
ERR_FAIL_NULL_V(light, 0);
|
||||
|
||||
return light->shadow_caster_mask;
|
||||
}
|
||||
|
||||
void LightStorage::light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) {
|
||||
Light *light = light_owner.get_or_null(p_light);
|
||||
ERR_FAIL_NULL(light);
|
||||
|
|
@ -313,6 +336,12 @@ void LightStorage::light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMo
|
|||
|
||||
light->version++;
|
||||
light->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_LIGHT);
|
||||
|
||||
if (p_mode == RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID) {
|
||||
shadow_dual_paraboloid_used = true;
|
||||
} else if (p_mode == RS::LIGHT_OMNI_SHADOW_CUBE) {
|
||||
shadow_cubemaps_used = true;
|
||||
}
|
||||
}
|
||||
|
||||
RS::LightOmniShadowMode LightStorage::light_omni_get_shadow_mode(RID p_light) {
|
||||
|
|
@ -653,12 +682,13 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged
|
|||
angular_diameter = 0.0;
|
||||
}
|
||||
|
||||
light_data.bake_mode = light->bake_mode;
|
||||
|
||||
if (light_data.shadow_opacity > 0.001) {
|
||||
RS::LightDirectionalShadowMode smode = light->directional_shadow_mode;
|
||||
|
||||
light_data.soft_shadow_scale = light->param[RS::LIGHT_PARAM_SHADOW_BLUR];
|
||||
light_data.softshadow_angle = angular_diameter;
|
||||
light_data.bake_mode = light->bake_mode;
|
||||
|
||||
if (angular_diameter <= 0.0) {
|
||||
light_data.soft_shadow_scale *= RendererSceneRenderRD::get_singleton()->directional_shadow_quality_radius_get(); // Only use quality radius for PCF
|
||||
|
|
@ -685,7 +715,7 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged
|
|||
float bias_scale = light_instance->shadow_transform[j].bias_scale * light_data.soft_shadow_scale;
|
||||
light_data.shadow_bias[j] = light->param[RS::LIGHT_PARAM_SHADOW_BIAS] / 100.0 * bias_scale;
|
||||
light_data.shadow_normal_bias[j] = light->param[RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS] * light_instance->shadow_transform[j].shadow_texel_size;
|
||||
light_data.shadow_transmittance_bias[j] = light->param[RS::LIGHT_PARAM_TRANSMITTANCE_BIAS] * bias_scale;
|
||||
light_data.shadow_transmittance_bias[j] = light->param[RS::LIGHT_PARAM_TRANSMITTANCE_BIAS] / 100.0 * bias_scale;
|
||||
light_data.shadow_z_range[j] = light_instance->shadow_transform[j].farplane;
|
||||
light_data.shadow_range_begin[j] = light_instance->shadow_transform[j].range_begin;
|
||||
RendererRD::MaterialStorage::store_camera(shadow_mtx, light_data.shadow_matrices[j]);
|
||||
|
|
@ -1026,7 +1056,7 @@ void LightStorage::reflection_probe_free(RID p_rid) {
|
|||
ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_rid);
|
||||
reflection_probe->dependency.deleted_notify(p_rid);
|
||||
reflection_probe_owner.free(p_rid);
|
||||
};
|
||||
}
|
||||
|
||||
void LightStorage::reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) {
|
||||
ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_probe);
|
||||
|
|
@ -1043,6 +1073,13 @@ void LightStorage::reflection_probe_set_intensity(RID p_probe, float p_intensity
|
|||
reflection_probe->intensity = p_intensity;
|
||||
}
|
||||
|
||||
void LightStorage::reflection_probe_set_blend_distance(RID p_probe, float p_blend_distance) {
|
||||
ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_probe);
|
||||
ERR_FAIL_NULL(reflection_probe);
|
||||
|
||||
reflection_probe->blend_distance = p_blend_distance;
|
||||
}
|
||||
|
||||
void LightStorage::reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) {
|
||||
ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_probe);
|
||||
ERR_FAIL_NULL(reflection_probe);
|
||||
|
|
@ -1243,6 +1280,13 @@ float LightStorage::reflection_probe_get_intensity(RID p_probe) const {
|
|||
return reflection_probe->intensity;
|
||||
}
|
||||
|
||||
float LightStorage::reflection_probe_get_blend_distance(RID p_probe) const {
|
||||
const ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_probe);
|
||||
ERR_FAIL_NULL_V(reflection_probe, 0);
|
||||
|
||||
return reflection_probe->blend_distance;
|
||||
}
|
||||
|
||||
bool LightStorage::reflection_probe_is_interior(RID p_probe) const {
|
||||
const ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_probe);
|
||||
ERR_FAIL_NULL_V(reflection_probe, false);
|
||||
|
|
@ -1478,21 +1522,20 @@ bool LightStorage::reflection_probe_instance_begin_render(RID p_instance, RID p_
|
|||
//reflection atlas was unused, create:
|
||||
RD::TextureFormat tf;
|
||||
tf.array_layers = 6 * atlas->count;
|
||||
tf.format = RendererSceneRenderRD::get_singleton()->_render_buffers_get_color_format();
|
||||
tf.format = get_reflection_probe_color_format();
|
||||
tf.texture_type = RD::TEXTURE_TYPE_CUBE_ARRAY;
|
||||
tf.mipmaps = mipmaps;
|
||||
tf.width = atlas->size;
|
||||
tf.height = atlas->size;
|
||||
tf.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | (RendererSceneRenderRD::get_singleton()->_render_buffers_can_be_storage() ? RD::TEXTURE_USAGE_STORAGE_BIT : 0);
|
||||
|
||||
tf.usage_bits = get_reflection_probe_color_usage_bits();
|
||||
atlas->reflection = RD::get_singleton()->texture_create(tf, RD::TextureView());
|
||||
}
|
||||
{
|
||||
RD::TextureFormat tf;
|
||||
tf.format = RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_D32_SFLOAT, RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ? RD::DATA_FORMAT_D32_SFLOAT : RD::DATA_FORMAT_X8_D24_UNORM_PACK32;
|
||||
tf.format = get_reflection_probe_depth_format();
|
||||
tf.width = atlas->size;
|
||||
tf.height = atlas->size;
|
||||
tf.usage_bits = RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
tf.usage_bits = get_reflection_probe_depth_usage_bits();
|
||||
atlas->depth_buffer = RD::get_singleton()->texture_create(tf, RD::TextureView());
|
||||
}
|
||||
atlas->reflections.resize(atlas->count);
|
||||
|
|
@ -1689,11 +1732,12 @@ void LightStorage::update_reflection_probe_buffer(RenderDataRD *p_render_data, c
|
|||
if (!rpi) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Transform3D transform = rpi->transform;
|
||||
ReflectionProbe *probe = reflection_probe_owner.get_or_null(rpi->probe);
|
||||
Vector3 extents = probe->size / 2;
|
||||
float probe_size = extents.length();
|
||||
|
||||
reflection_sort[reflection_count].probe_instance = rpi;
|
||||
reflection_sort[reflection_count].depth = -p_camera_inverse_transform.xform(transform.origin).z;
|
||||
reflection_sort[reflection_count].size = -probe_size;
|
||||
reflection_count++;
|
||||
}
|
||||
|
||||
|
|
@ -1733,6 +1777,7 @@ void LightStorage::update_reflection_probe_buffer(RenderDataRD *p_render_data, c
|
|||
reflection_ubo.mask = probe->reflection_mask;
|
||||
|
||||
reflection_ubo.intensity = probe->intensity;
|
||||
reflection_ubo.blend_distance = probe->blend_distance;
|
||||
reflection_ubo.ambient_mode = probe->ambient_mode;
|
||||
|
||||
reflection_ubo.exterior = !probe->interior;
|
||||
|
|
@ -1763,6 +1808,22 @@ void LightStorage::update_reflection_probe_buffer(RenderDataRD *p_render_data, c
|
|||
}
|
||||
}
|
||||
|
||||
RD::DataFormat LightStorage::get_reflection_probe_color_format() {
|
||||
return RendererSceneRenderRD::get_singleton()->_render_buffers_get_color_format();
|
||||
}
|
||||
|
||||
uint32_t LightStorage::get_reflection_probe_color_usage_bits() {
|
||||
return RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | (RendererSceneRenderRD::get_singleton()->_render_buffers_can_be_storage() ? RD::TEXTURE_USAGE_STORAGE_BIT : 0);
|
||||
}
|
||||
|
||||
RD::DataFormat LightStorage::get_reflection_probe_depth_format() {
|
||||
return RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_D32_SFLOAT, RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ? RD::DATA_FORMAT_D32_SFLOAT : RD::DATA_FORMAT_X8_D24_UNORM_PACK32;
|
||||
}
|
||||
|
||||
uint32_t LightStorage::get_reflection_probe_depth_usage_bits() {
|
||||
return RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
}
|
||||
|
||||
/* LIGHTMAP API */
|
||||
|
||||
RID LightStorage::lightmap_allocate() {
|
||||
|
|
@ -1813,6 +1874,7 @@ void LightStorage::lightmap_set_textures(RID p_lightmap, RID p_light, bool p_use
|
|||
}
|
||||
|
||||
t->lightmap_users.insert(p_lightmap);
|
||||
lm->light_texture_size = Vector2i(t->width, t->height);
|
||||
|
||||
if (using_lightmap_array) {
|
||||
if (lm->array_index < 0) {
|
||||
|
|
@ -1963,6 +2025,64 @@ AABB LightStorage::lightmap_get_aabb(RID p_lightmap) const {
|
|||
return lm->bounds;
|
||||
}
|
||||
|
||||
void LightStorage::lightmap_set_shadowmask_textures(RID p_lightmap, RID p_shadow) {
|
||||
TextureStorage *texture_storage = TextureStorage::get_singleton();
|
||||
|
||||
Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
|
||||
ERR_FAIL_NULL(lm);
|
||||
|
||||
// Erase lightmap users from shadow texture.
|
||||
if (lm->shadow_texture.is_valid()) {
|
||||
TextureStorage::Texture *t = texture_storage->get_texture(lm->shadow_texture);
|
||||
if (t) {
|
||||
t->lightmap_users.erase(p_lightmap);
|
||||
}
|
||||
}
|
||||
|
||||
TextureStorage::Texture *t = texture_storage->get_texture(p_shadow);
|
||||
lm->shadow_texture = p_shadow;
|
||||
|
||||
RID default_2d_array = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE);
|
||||
if (!t) {
|
||||
if (lm->array_index >= 0) {
|
||||
shadowmask_textures.write[lm->array_index] = default_2d_array;
|
||||
lm->array_index = -1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
t->lightmap_users.insert(p_lightmap);
|
||||
|
||||
if (lm->array_index < 0) {
|
||||
// Not in array, try to put in array.
|
||||
for (int i = 0; i < shadowmask_textures.size(); i++) {
|
||||
if (shadowmask_textures[i] == default_2d_array) {
|
||||
lm->array_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_MSG(lm->array_index < 0, vformat("Maximum amount of shadowmasks in use (%d) has been exceeded, shadowmask will not display properly.", shadowmask_textures.size()));
|
||||
|
||||
shadowmask_textures.write[lm->array_index] = t->rd_texture;
|
||||
}
|
||||
|
||||
RS::ShadowmaskMode LightStorage::lightmap_get_shadowmask_mode(RID p_lightmap) {
|
||||
Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
|
||||
ERR_FAIL_NULL_V(lm, RS::SHADOWMASK_MODE_NONE);
|
||||
|
||||
return lm->shadowmask_mode;
|
||||
}
|
||||
|
||||
void LightStorage::lightmap_set_shadowmask_mode(RID p_lightmap, RS::ShadowmaskMode p_mode) {
|
||||
Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
|
||||
ERR_FAIL_NULL(lm);
|
||||
|
||||
lm->shadowmask_mode = p_mode;
|
||||
}
|
||||
|
||||
/* LIGHTMAP INSTANCE */
|
||||
|
||||
RID LightStorage::lightmap_instance_create(RID p_lightmap) {
|
||||
|
|
@ -1995,10 +2115,10 @@ void LightStorage::shadow_atlas_free(RID p_atlas) {
|
|||
void LightStorage::_update_shadow_atlas(ShadowAtlas *shadow_atlas) {
|
||||
if (shadow_atlas->size > 0 && shadow_atlas->depth.is_null()) {
|
||||
RD::TextureFormat tf;
|
||||
tf.format = shadow_atlas->use_16_bits ? RD::DATA_FORMAT_D16_UNORM : RD::DATA_FORMAT_D32_SFLOAT;
|
||||
tf.format = get_shadow_atlas_depth_format(shadow_atlas->use_16_bits);
|
||||
tf.width = shadow_atlas->size;
|
||||
tf.height = shadow_atlas->size;
|
||||
tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
tf.usage_bits = get_shadow_atlas_depth_usage_bits();
|
||||
|
||||
shadow_atlas->depth = RD::get_singleton()->texture_create(tf, RD::TextureView());
|
||||
Vector<RID> fb_tex;
|
||||
|
|
@ -2289,7 +2409,7 @@ bool LightStorage::shadow_atlas_update_light(RID p_atlas, RID p_light_instance,
|
|||
old_quadrant = (old_key >> QUADRANT_SHIFT) & 0x3;
|
||||
old_shadow = old_key & SHADOW_INDEX_MASK;
|
||||
|
||||
should_realloc = shadow_atlas->quadrants[old_quadrant].subdivision != (uint32_t)best_subdiv && (shadow_atlas->quadrants[old_quadrant].shadows[old_shadow].alloc_tick - tick > shadow_atlas_realloc_tolerance_msec);
|
||||
should_realloc = shadow_atlas->quadrants[old_quadrant].subdivision != (uint32_t)best_subdiv && (tick - shadow_atlas->quadrants[old_quadrant].shadows[old_shadow].alloc_tick > shadow_atlas_realloc_tolerance_msec);
|
||||
should_redraw = shadow_atlas->quadrants[old_quadrant].shadows[old_shadow].version != p_light_version;
|
||||
|
||||
if (!should_realloc) {
|
||||
|
|
@ -2383,15 +2503,23 @@ void LightStorage::shadow_atlas_update(RID p_atlas) {
|
|||
_update_shadow_atlas(shadow_atlas);
|
||||
}
|
||||
|
||||
RD::DataFormat LightStorage::get_shadow_atlas_depth_format(bool p_16_bits) {
|
||||
return p_16_bits ? RD::DATA_FORMAT_D16_UNORM : RD::DATA_FORMAT_D32_SFLOAT;
|
||||
}
|
||||
|
||||
uint32_t LightStorage::get_shadow_atlas_depth_usage_bits() {
|
||||
return RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
}
|
||||
|
||||
/* DIRECTIONAL SHADOW */
|
||||
|
||||
void LightStorage::update_directional_shadow_atlas() {
|
||||
if (directional_shadow.depth.is_null() && directional_shadow.size > 0) {
|
||||
RD::TextureFormat tf;
|
||||
tf.format = directional_shadow.use_16_bits ? RD::DATA_FORMAT_D16_UNORM : RD::DATA_FORMAT_D32_SFLOAT;
|
||||
tf.format = get_shadow_atlas_depth_format(directional_shadow.use_16_bits);
|
||||
tf.width = directional_shadow.size;
|
||||
tf.height = directional_shadow.size;
|
||||
tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
tf.usage_bits = get_shadow_atlas_depth_usage_bits();
|
||||
|
||||
directional_shadow.depth = RD::get_singleton()->texture_create(tf, RD::TextureView());
|
||||
Vector<RID> fb_tex;
|
||||
|
|
@ -2447,12 +2575,12 @@ Rect2i LightStorage::get_directional_shadow_rect() {
|
|||
return _get_directional_shadow_rect(directional_shadow.size, directional_shadow.light_count, directional_shadow.current_light);
|
||||
}
|
||||
|
||||
int LightStorage::get_directional_light_shadow_size(RID p_light_intance) {
|
||||
int LightStorage::get_directional_light_shadow_size(RID p_light_instance) {
|
||||
ERR_FAIL_COND_V(directional_shadow.light_count == 0, 0);
|
||||
|
||||
Rect2i r = _get_directional_shadow_rect(directional_shadow.size, directional_shadow.light_count, 0);
|
||||
|
||||
LightInstance *light_instance = light_instance_owner.get_or_null(p_light_intance);
|
||||
LightInstance *light_instance = light_instance_owner.get_or_null(p_light_instance);
|
||||
ERR_FAIL_NULL_V(light_instance, 0);
|
||||
|
||||
switch (light_directional_get_shadow_mode(light_instance->light)) {
|
||||
|
|
@ -2476,12 +2604,12 @@ LightStorage::ShadowCubemap *LightStorage::_get_shadow_cubemap(int p_size) {
|
|||
ShadowCubemap sc;
|
||||
{
|
||||
RD::TextureFormat tf;
|
||||
tf.format = RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_D32_SFLOAT, RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ? RD::DATA_FORMAT_D32_SFLOAT : RD::DATA_FORMAT_X8_D24_UNORM_PACK32;
|
||||
tf.format = get_cubemap_depth_format();
|
||||
tf.width = p_size;
|
||||
tf.height = p_size;
|
||||
tf.texture_type = RD::TEXTURE_TYPE_CUBE;
|
||||
tf.array_layers = 6;
|
||||
tf.usage_bits = RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
tf.usage_bits = get_cubemap_depth_usage_bits();
|
||||
sc.cubemap = RD::get_singleton()->texture_create(tf, RD::TextureView());
|
||||
}
|
||||
|
||||
|
|
@ -2509,3 +2637,19 @@ RID LightStorage::get_cubemap_fb(int p_size, int p_pass) {
|
|||
|
||||
return cubemap->side_fb[p_pass];
|
||||
}
|
||||
|
||||
RD::DataFormat LightStorage::get_cubemap_depth_format() {
|
||||
return RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_D32_SFLOAT, RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ? RD::DATA_FORMAT_D32_SFLOAT : RD::DATA_FORMAT_X8_D24_UNORM_PACK32;
|
||||
}
|
||||
|
||||
uint32_t LightStorage::get_cubemap_depth_usage_bits() {
|
||||
return RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
}
|
||||
|
||||
bool LightStorage::get_shadow_cubemaps_used() const {
|
||||
return shadow_cubemaps_used;
|
||||
}
|
||||
|
||||
bool LightStorage::get_shadow_dual_paraboloid_used() const {
|
||||
return shadow_dual_paraboloid_used;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace RendererRD {
|
|||
|
||||
class LightStorage : public RendererLightStorage {
|
||||
public:
|
||||
enum ShadowAtlastQuadrant {
|
||||
enum ShadowAtlastQuadrant : uint32_t {
|
||||
QUADRANT_SHIFT = 27,
|
||||
OMNI_LIGHT_FLAG = 1 << 26,
|
||||
SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1,
|
||||
|
|
@ -72,6 +72,7 @@ private:
|
|||
RS::LightBakeMode bake_mode = RS::LIGHT_BAKE_DYNAMIC;
|
||||
uint32_t max_sdfgi_cascade = 2;
|
||||
uint32_t cull_mask = 0xFFFFFFFF;
|
||||
uint32_t shadow_caster_mask = 0xFFFFFFFF;
|
||||
bool distance_fade = false;
|
||||
real_t distance_fade_begin = 40.0;
|
||||
real_t distance_fade_shadow = 50.0;
|
||||
|
|
@ -222,6 +223,7 @@ private:
|
|||
RS::ReflectionProbeUpdateMode update_mode = RS::REFLECTION_PROBE_UPDATE_ONCE;
|
||||
int resolution = 256;
|
||||
float intensity = 1.0;
|
||||
float blend_distance = 1.0;
|
||||
RS::ReflectionProbeAmbientMode ambient_mode = RS::REFLECTION_PROBE_AMBIENT_ENVIRONMENT;
|
||||
Color ambient_color;
|
||||
float ambient_color_energy = 1.0;
|
||||
|
|
@ -302,18 +304,22 @@ private:
|
|||
uint32_t mask;
|
||||
float ambient[3]; // ambient color,
|
||||
float intensity;
|
||||
float blend_distance;
|
||||
uint32_t exterior;
|
||||
uint32_t box_project;
|
||||
uint32_t ambient_mode;
|
||||
float exposure_normalization;
|
||||
uint32_t pad0;
|
||||
uint32_t pad1;
|
||||
uint32_t pad2;
|
||||
float local_matrix[16]; // up to here for spot and omni, rest is for directional
|
||||
};
|
||||
|
||||
struct ReflectionProbeInstanceSort {
|
||||
float depth;
|
||||
float size;
|
||||
ReflectionProbeInstance *probe_instance;
|
||||
bool operator<(const ReflectionProbeInstanceSort &p_sort) const {
|
||||
return depth < p_sort.depth;
|
||||
return size < p_sort.size;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -328,10 +334,13 @@ private:
|
|||
|
||||
struct Lightmap {
|
||||
RID light_texture;
|
||||
RID shadow_texture;
|
||||
RS::ShadowmaskMode shadowmask_mode = RS::SHADOWMASK_MODE_NONE;
|
||||
bool uses_spherical_harmonics = false;
|
||||
bool interior = false;
|
||||
AABB bounds = AABB(Vector3(), Vector3(1, 1, 1));
|
||||
float baked_exposure = 1.0;
|
||||
Vector2i light_texture_size;
|
||||
int32_t array_index = -1; //unassigned
|
||||
PackedVector3Array points;
|
||||
PackedColorArray point_sh;
|
||||
|
|
@ -354,6 +363,8 @@ private:
|
|||
|
||||
mutable RID_Owner<Lightmap, true> lightmap_owner;
|
||||
|
||||
Vector<RID> shadowmask_textures;
|
||||
|
||||
/* LIGHTMAP INSTANCE */
|
||||
|
||||
struct LightmapInstance {
|
||||
|
|
@ -433,6 +444,11 @@ private:
|
|||
HashMap<int, ShadowCubemap> shadow_cubemaps;
|
||||
ShadowCubemap *_get_shadow_cubemap(int p_size);
|
||||
|
||||
/* PIPELINE HINTS */
|
||||
|
||||
bool shadow_cubemaps_used = false;
|
||||
bool shadow_dual_paraboloid_used = false;
|
||||
|
||||
public:
|
||||
static LightStorage *get_singleton();
|
||||
|
||||
|
|
@ -474,6 +490,8 @@ public:
|
|||
virtual void light_set_cull_mask(RID p_light, uint32_t p_mask) override;
|
||||
virtual void light_set_distance_fade(RID p_light, bool p_enabled, float p_begin, float p_shadow, float p_length) override;
|
||||
virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) override;
|
||||
virtual void light_set_shadow_caster_mask(RID p_light, uint32_t p_caster_mask) override;
|
||||
virtual uint32_t light_get_shadow_caster_mask(RID p_light) const override;
|
||||
virtual void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) override;
|
||||
virtual void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) override;
|
||||
|
||||
|
|
@ -581,7 +599,7 @@ public:
|
|||
|
||||
/* LIGHT INSTANCE API */
|
||||
|
||||
bool owns_light_instance(RID p_rid) { return light_instance_owner.owns(p_rid); };
|
||||
bool owns_light_instance(RID p_rid) { return light_instance_owner.owns(p_rid); }
|
||||
|
||||
virtual RID light_instance_create(RID p_light) override;
|
||||
virtual void light_instance_free(RID p_light) override;
|
||||
|
|
@ -790,6 +808,16 @@ public:
|
|||
RID get_spot_light_buffer() { return spot_light_buffer; }
|
||||
RID get_directional_light_buffer() { return directional_light_buffer; }
|
||||
uint32_t get_max_directional_lights() { return max_directional_lights; }
|
||||
uint32_t get_directional_light_blend_splits(uint32_t p_directional_light_count) const {
|
||||
uint32_t blend_splits = 0;
|
||||
for (uint32_t i = 0; i < p_directional_light_count; i++) {
|
||||
if (directional_lights[i].blend_splits) {
|
||||
blend_splits |= 1U << i;
|
||||
}
|
||||
}
|
||||
|
||||
return blend_splits;
|
||||
}
|
||||
bool has_directional_shadows(const uint32_t p_directional_light_count) {
|
||||
for (uint32_t i = 0; i < p_directional_light_count; i++) {
|
||||
if (directional_lights[i].shadow_opacity > 0.001) {
|
||||
|
|
@ -802,7 +830,7 @@ public:
|
|||
|
||||
/* REFLECTION PROBE */
|
||||
|
||||
bool owns_reflection_probe(RID p_rid) { return reflection_probe_owner.owns(p_rid); };
|
||||
bool owns_reflection_probe(RID p_rid) { return reflection_probe_owner.owns(p_rid); }
|
||||
|
||||
virtual RID reflection_probe_allocate() override;
|
||||
virtual void reflection_probe_initialize(RID p_reflection_probe) override;
|
||||
|
|
@ -810,6 +838,7 @@ public:
|
|||
|
||||
virtual void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) override;
|
||||
virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity) override;
|
||||
virtual void reflection_probe_set_blend_distance(RID p_probe, float p_blend_distance) override;
|
||||
virtual void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) override;
|
||||
virtual void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) override;
|
||||
virtual void reflection_probe_set_ambient_energy(RID p_probe, float p_energy) override;
|
||||
|
|
@ -840,6 +869,7 @@ public:
|
|||
virtual bool reflection_probe_renders_shadows(RID p_probe) const override;
|
||||
|
||||
float reflection_probe_get_intensity(RID p_probe) const;
|
||||
float reflection_probe_get_blend_distance(RID p_probe) const;
|
||||
bool reflection_probe_is_interior(RID p_probe) const;
|
||||
bool reflection_probe_is_box_projection(RID p_probe) const;
|
||||
RS::ReflectionProbeAmbientMode reflection_probe_get_ambient_mode(RID p_probe) const;
|
||||
|
|
@ -937,10 +967,14 @@ public:
|
|||
void set_max_reflection_probes(const uint32_t p_max_reflection_probes);
|
||||
RID get_reflection_probe_buffer() { return reflection_buffer; }
|
||||
void update_reflection_probe_buffer(RenderDataRD *p_render_data, const PagedArray<RID> &p_reflections, const Transform3D &p_camera_inverse_transform, RID p_environment);
|
||||
static RD::DataFormat get_reflection_probe_color_format();
|
||||
static uint32_t get_reflection_probe_color_usage_bits();
|
||||
static RD::DataFormat get_reflection_probe_depth_format();
|
||||
static uint32_t get_reflection_probe_depth_usage_bits();
|
||||
|
||||
/* LIGHTMAP */
|
||||
|
||||
bool owns_lightmap(RID p_rid) { return lightmap_owner.owns(p_rid); };
|
||||
bool owns_lightmap(RID p_rid) { return lightmap_owner.owns(p_rid); }
|
||||
|
||||
virtual RID lightmap_allocate() override;
|
||||
virtual void lightmap_initialize(RID p_lightmap) override;
|
||||
|
|
@ -962,6 +996,10 @@ public:
|
|||
|
||||
Dependency *lightmap_get_dependency(RID p_lightmap) const;
|
||||
|
||||
virtual void lightmap_set_shadowmask_textures(RID p_lightmap, RID p_shadow) override;
|
||||
virtual RS::ShadowmaskMode lightmap_get_shadowmask_mode(RID p_lightmap) override;
|
||||
virtual void lightmap_set_shadowmask_mode(RID p_lightmap, RS::ShadowmaskMode p_mode) override;
|
||||
|
||||
virtual float lightmap_get_probe_capture_update_speed() const override {
|
||||
return lightmap_probe_capture_update_speed;
|
||||
}
|
||||
|
|
@ -985,6 +1023,10 @@ public:
|
|||
const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
|
||||
return lm->uses_spherical_harmonics;
|
||||
}
|
||||
_FORCE_INLINE_ Vector2i lightmap_get_light_texture_size(RID p_lightmap) const {
|
||||
const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
|
||||
return lm->light_texture_size;
|
||||
}
|
||||
_FORCE_INLINE_ uint64_t lightmap_array_get_version() const {
|
||||
ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
|
||||
return lightmap_array_version;
|
||||
|
|
@ -1000,9 +1042,15 @@ public:
|
|||
return lightmap_textures;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID shadowmask_get_texture(RID p_lightmap) const {
|
||||
const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
|
||||
ERR_FAIL_NULL_V(lm, RID());
|
||||
return lm->shadow_texture;
|
||||
}
|
||||
|
||||
/* LIGHTMAP INSTANCE */
|
||||
|
||||
bool owns_lightmap_instance(RID p_rid) { return lightmap_instance_owner.owns(p_rid); };
|
||||
bool owns_lightmap_instance(RID p_rid) { return lightmap_instance_owner.owns(p_rid); }
|
||||
|
||||
virtual RID lightmap_instance_create(RID p_lightmap) override;
|
||||
virtual void lightmap_instance_free(RID p_lightmap) override;
|
||||
|
|
@ -1022,7 +1070,7 @@ public:
|
|||
|
||||
/* SHADOW ATLAS API */
|
||||
|
||||
bool owns_shadow_atlas(RID p_rid) { return shadow_atlas_owner.owns(p_rid); };
|
||||
bool owns_shadow_atlas(RID p_rid) { return shadow_atlas_owner.owns(p_rid); }
|
||||
|
||||
virtual RID shadow_atlas_create() override;
|
||||
virtual void shadow_atlas_free(RID p_atlas) override;
|
||||
|
|
@ -1074,6 +1122,8 @@ public:
|
|||
}
|
||||
|
||||
virtual void shadow_atlas_update(RID p_atlas) override;
|
||||
static RD::DataFormat get_shadow_atlas_depth_format(bool p_16_bits);
|
||||
static uint32_t get_shadow_atlas_depth_usage_bits();
|
||||
|
||||
/* DIRECTIONAL SHADOW */
|
||||
|
||||
|
|
@ -1104,6 +1154,13 @@ public:
|
|||
|
||||
RID get_cubemap(int p_size);
|
||||
RID get_cubemap_fb(int p_size, int p_pass);
|
||||
static RD::DataFormat get_cubemap_depth_format();
|
||||
static uint32_t get_cubemap_depth_usage_bits();
|
||||
|
||||
/* PIPELINE HINTS */
|
||||
|
||||
bool get_shadow_cubemaps_used() const;
|
||||
bool get_shadow_dual_paraboloid_used() const;
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include "core/config/engine.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h"
|
||||
#include "servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h"
|
||||
#include "servers/rendering/storage/variant_converters.h"
|
||||
#include "texture_storage.h"
|
||||
|
||||
|
|
@ -342,7 +344,7 @@ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataType type, int p_
|
|||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, const Vector<ShaderLanguage::ConstantNode::Value> &value, uint8_t *data) {
|
||||
_FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, const Vector<ShaderLanguage::Scalar> &value, uint8_t *data, bool p_use_linear_color) {
|
||||
switch (type) {
|
||||
case ShaderLanguage::TYPE_BOOL: {
|
||||
uint32_t *gui = (uint32_t *)data;
|
||||
|
|
@ -439,18 +441,28 @@ _FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type,
|
|||
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_VEC3: {
|
||||
Color c = Color(value[0].real, value[1].real, value[2].real);
|
||||
if (p_use_linear_color) {
|
||||
c = c.srgb_to_linear();
|
||||
}
|
||||
|
||||
float *gui = reinterpret_cast<float *>(data);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
gui[i] = value[i].real;
|
||||
gui[i] = c.components[i];
|
||||
}
|
||||
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_VEC4: {
|
||||
Color c = Color(value[0].real, value[1].real, value[2].real, value[3].real);
|
||||
if (p_use_linear_color) {
|
||||
c = c.srgb_to_linear();
|
||||
}
|
||||
|
||||
float *gui = reinterpret_cast<float *>(data);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
gui[i] = value[i].real;
|
||||
gui[i] = c.components[i];
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_MAT2: {
|
||||
|
|
@ -566,7 +578,10 @@ void MaterialStorage::ShaderData::set_default_texture_parameter(const StringName
|
|||
Variant MaterialStorage::ShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
Vector<ShaderLanguage::Scalar> default_value = uniform.default_value;
|
||||
if (default_value.is_empty()) {
|
||||
return ShaderLanguage::get_default_datatype_value(uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
|
|
@ -580,11 +595,7 @@ void MaterialStorage::ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_
|
|||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) {
|
||||
continue;
|
||||
}
|
||||
if (E.value.texture_order >= 0) {
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.texture_order + 100000));
|
||||
} else {
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.order));
|
||||
}
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.prop_order));
|
||||
}
|
||||
int uniform_count = filtered_uniforms.size();
|
||||
sorter.sort(filtered_uniforms.ptr(), uniform_count);
|
||||
|
|
@ -634,7 +645,94 @@ bool MaterialStorage::ShaderData::is_parameter_texture(const StringName &p_param
|
|||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
return uniforms[p_param].is_texture();
|
||||
}
|
||||
|
||||
RD::PipelineColorBlendState::Attachment MaterialStorage::ShaderData::blend_mode_to_blend_attachment(BlendMode p_mode) {
|
||||
RD::PipelineColorBlendState::Attachment attachment;
|
||||
|
||||
switch (p_mode) {
|
||||
case BLEND_MODE_MIX: {
|
||||
attachment.enable_blend = true;
|
||||
attachment.alpha_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.color_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
|
||||
attachment.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
attachment.src_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
attachment.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
} break;
|
||||
case BLEND_MODE_ADD: {
|
||||
attachment.enable_blend = true;
|
||||
attachment.alpha_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.color_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
|
||||
attachment.dst_color_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
attachment.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
|
||||
attachment.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
} break;
|
||||
case BLEND_MODE_SUB: {
|
||||
attachment.enable_blend = true;
|
||||
attachment.alpha_blend_op = RD::BLEND_OP_REVERSE_SUBTRACT;
|
||||
attachment.color_blend_op = RD::BLEND_OP_REVERSE_SUBTRACT;
|
||||
attachment.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
|
||||
attachment.dst_color_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
attachment.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
|
||||
attachment.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
} break;
|
||||
case BLEND_MODE_MUL: {
|
||||
attachment.enable_blend = true;
|
||||
attachment.alpha_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.color_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.src_color_blend_factor = RD::BLEND_FACTOR_DST_COLOR;
|
||||
attachment.dst_color_blend_factor = RD::BLEND_FACTOR_ZERO;
|
||||
attachment.src_alpha_blend_factor = RD::BLEND_FACTOR_DST_ALPHA;
|
||||
attachment.dst_alpha_blend_factor = RD::BLEND_FACTOR_ZERO;
|
||||
} break;
|
||||
case BLEND_MODE_ALPHA_TO_COVERAGE: {
|
||||
attachment.enable_blend = true;
|
||||
attachment.alpha_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.color_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
|
||||
attachment.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
attachment.src_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
attachment.dst_alpha_blend_factor = RD::BLEND_FACTOR_ZERO;
|
||||
} break;
|
||||
case BLEND_MODE_PREMULTIPLIED_ALPHA: {
|
||||
attachment.enable_blend = true;
|
||||
attachment.alpha_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.color_blend_op = RD::BLEND_OP_ADD;
|
||||
attachment.src_color_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
attachment.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
attachment.src_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
|
||||
attachment.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
} break;
|
||||
case BLEND_MODE_DISABLED:
|
||||
default: {
|
||||
// Use default attachment values.
|
||||
} break;
|
||||
}
|
||||
|
||||
return attachment;
|
||||
}
|
||||
|
||||
bool MaterialStorage::ShaderData::blend_mode_uses_blend_alpha(BlendMode p_mode) {
|
||||
switch (p_mode) {
|
||||
case BLEND_MODE_MIX:
|
||||
return false;
|
||||
case BLEND_MODE_ADD:
|
||||
return true;
|
||||
case BLEND_MODE_SUB:
|
||||
return true;
|
||||
case BLEND_MODE_MUL:
|
||||
return true;
|
||||
case BLEND_MODE_ALPHA_TO_COVERAGE:
|
||||
return false;
|
||||
case BLEND_MODE_PREMULTIPLIED_ALPHA:
|
||||
return true;
|
||||
case BLEND_MODE_DISABLED:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -645,7 +743,7 @@ void MaterialStorage::MaterialData::update_uniform_buffer(const HashMap<StringNa
|
|||
bool uses_global_buffer = false;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : p_uniforms) {
|
||||
if (E.value.order < 0) {
|
||||
if (E.value.is_texture()) {
|
||||
continue; // texture, does not go here
|
||||
}
|
||||
|
||||
|
|
@ -701,7 +799,7 @@ void MaterialStorage::MaterialData::update_uniform_buffer(const HashMap<StringNa
|
|||
|
||||
} else if (E.value.default_value.size()) {
|
||||
//default value
|
||||
_fill_std140_ubo_value(E.value.type, E.value.default_value, data);
|
||||
_fill_std140_ubo_value(E.value.type, E.value.default_value, data, p_use_linear_color);
|
||||
//value=E.value.default_value;
|
||||
} else {
|
||||
//zero because it was not provided
|
||||
|
|
@ -1094,24 +1192,25 @@ void MaterialStorage::MaterialData::set_as_used() {
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// MaterialStorage::Samplers
|
||||
|
||||
Vector<RD::Uniform> MaterialStorage::Samplers::get_uniforms(int p_first_index) const {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
template void MaterialStorage::Samplers::append_uniforms(LocalVector<RD::Uniform> &p_uniforms, int p_first_index) const;
|
||||
|
||||
template void MaterialStorage::Samplers::append_uniforms(Vector<RD::Uniform> &p_uniforms, int p_first_index) const;
|
||||
|
||||
template <typename Collection>
|
||||
void MaterialStorage::Samplers::append_uniforms(Collection &p_uniforms, int p_first_index) const {
|
||||
// Binding ids are aligned with samplers_inc.glsl.
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 0, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 1, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 2, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 3, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 4, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 5, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 6, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 7, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 8, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 9, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 10, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 11, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
|
||||
return uniforms;
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 0, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 1, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 2, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 3, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 4, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 5, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 6, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 7, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 8, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 9, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 10, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 11, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
}
|
||||
|
||||
bool MaterialStorage::Samplers::is_valid() const {
|
||||
|
|
@ -1643,6 +1742,7 @@ void MaterialStorage::global_shader_parameters_load_settings(bool p_load_texture
|
|||
"sampler2DArray",
|
||||
"sampler3D",
|
||||
"samplerCube",
|
||||
"samplerExternalOES",
|
||||
};
|
||||
|
||||
RS::GlobalShaderParameterType gvtype = RS::GLOBAL_VAR_TYPE_MAX;
|
||||
|
|
@ -2024,6 +2124,7 @@ void MaterialStorage::_material_uniform_set_erased(void *p_material) {
|
|||
}
|
||||
|
||||
void MaterialStorage::_material_queue_update(Material *material, bool p_uniform, bool p_texture) {
|
||||
MutexLock lock(material_update_list_mutex);
|
||||
material->uniform_dirty = material->uniform_dirty || p_uniform;
|
||||
material->texture_dirty = material->texture_dirty || p_texture;
|
||||
|
||||
|
|
@ -2035,6 +2136,7 @@ void MaterialStorage::_material_queue_update(Material *material, bool p_uniform,
|
|||
}
|
||||
|
||||
void MaterialStorage::_update_queued_materials() {
|
||||
MutexLock lock(material_update_list_mutex);
|
||||
while (material_update_list.first()) {
|
||||
Material *material = material_update_list.first()->self();
|
||||
bool uniforms_changed = false;
|
||||
|
|
@ -2215,6 +2317,24 @@ bool MaterialStorage::material_casts_shadows(RID p_material) {
|
|||
return true; //by default everything casts shadows
|
||||
}
|
||||
|
||||
RS::CullMode RendererRD::MaterialStorage::material_get_cull_mode(RID p_material) const {
|
||||
Material *material = material_owner.get_or_null(p_material);
|
||||
ERR_FAIL_NULL_V(material, RS::CULL_MODE_DISABLED);
|
||||
ERR_FAIL_NULL_V(material->shader, RS::CULL_MODE_DISABLED);
|
||||
if (material->shader->type == ShaderType::SHADER_TYPE_3D && material->shader->data) {
|
||||
RendererSceneRenderImplementation::SceneShaderForwardClustered::ShaderData *sd_clustered = dynamic_cast<RendererSceneRenderImplementation::SceneShaderForwardClustered::ShaderData *>(material->shader->data);
|
||||
if (sd_clustered) {
|
||||
return (RS::CullMode)sd_clustered->cull_mode;
|
||||
}
|
||||
|
||||
RendererSceneRenderImplementation::SceneShaderForwardMobile::ShaderData *sd_mobile = dynamic_cast<RendererSceneRenderImplementation::SceneShaderForwardMobile::ShaderData *>(material->shader->data);
|
||||
if (sd_mobile) {
|
||||
return (RS::CullMode)sd_mobile->cull_mode;
|
||||
}
|
||||
}
|
||||
return RS::CULL_MODE_DISABLED;
|
||||
}
|
||||
|
||||
void MaterialStorage::material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) {
|
||||
Material *material = material_owner.get_or_null(p_material);
|
||||
ERR_FAIL_NULL(material);
|
||||
|
|
@ -2236,11 +2356,11 @@ void MaterialStorage::material_update_dependency(RID p_material, DependencyTrack
|
|||
}
|
||||
}
|
||||
|
||||
MaterialStorage::Samplers MaterialStorage::samplers_rd_allocate(float p_mipmap_bias) const {
|
||||
MaterialStorage::Samplers MaterialStorage::samplers_rd_allocate(float p_mipmap_bias, RS::ViewportAnisotropicFiltering anisotropic_filtering_level) const {
|
||||
Samplers samplers;
|
||||
samplers.mipmap_bias = p_mipmap_bias;
|
||||
samplers.anisotropic_filtering_level = (int)anisotropic_filtering_level;
|
||||
samplers.use_nearest_mipmap_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
|
||||
samplers.anisotropic_filtering_level = int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"));
|
||||
|
||||
RD::SamplerFilter mip_filter = samplers.use_nearest_mipmap_filter ? RD::SAMPLER_FILTER_NEAREST : RD::SAMPLER_FILTER_LINEAR;
|
||||
float anisotropy_max = float(1 << samplers.anisotropic_filtering_level);
|
||||
|
|
|
|||
|
|
@ -56,6 +56,16 @@ public:
|
|||
};
|
||||
|
||||
struct ShaderData {
|
||||
enum BlendMode {
|
||||
BLEND_MODE_MIX,
|
||||
BLEND_MODE_ADD,
|
||||
BLEND_MODE_SUB,
|
||||
BLEND_MODE_MUL,
|
||||
BLEND_MODE_ALPHA_TO_COVERAGE,
|
||||
BLEND_MODE_PREMULTIPLIED_ALPHA,
|
||||
BLEND_MODE_DISABLED
|
||||
};
|
||||
|
||||
String path;
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
|
@ -73,6 +83,9 @@ public:
|
|||
virtual RS::ShaderNativeSourceCode get_native_source_code() const { return RS::ShaderNativeSourceCode(); }
|
||||
|
||||
virtual ~ShaderData() {}
|
||||
|
||||
static RD::PipelineColorBlendState::Attachment blend_mode_to_blend_attachment(BlendMode p_mode);
|
||||
static bool blend_mode_uses_blend_alpha(BlendMode p_mode);
|
||||
};
|
||||
|
||||
struct MaterialData {
|
||||
|
|
@ -115,7 +128,8 @@ public:
|
|||
return rids[p_filter][p_repeat];
|
||||
}
|
||||
|
||||
Vector<RD::Uniform> get_uniforms(int p_first_index) const;
|
||||
template <typename Collection>
|
||||
void append_uniforms(Collection &p_uniforms, int p_first_index) const;
|
||||
bool is_valid() const;
|
||||
bool is_null() const;
|
||||
};
|
||||
|
|
@ -241,9 +255,10 @@ private:
|
|||
|
||||
MaterialDataRequestFunction material_data_request_func[SHADER_TYPE_MAX];
|
||||
mutable RID_Owner<Material, true> material_owner;
|
||||
Material *get_material(RID p_rid) { return material_owner.get_or_null(p_rid); };
|
||||
Material *get_material(RID p_rid) { return material_owner.get_or_null(p_rid); }
|
||||
|
||||
SelfList<Material>::List material_update_list;
|
||||
Mutex material_update_list_mutex;
|
||||
|
||||
static void _material_uniform_set_erased(void *p_material);
|
||||
|
||||
|
|
@ -349,7 +364,7 @@ public:
|
|||
|
||||
/* Samplers */
|
||||
|
||||
Samplers samplers_rd_allocate(float p_mipmap_bias = 0.0f) const;
|
||||
Samplers samplers_rd_allocate(float p_mipmap_bias = 0.0f, RS::ViewportAnisotropicFiltering anisotropic_filtering_level = RS::ViewportAnisotropicFiltering::VIEWPORT_ANISOTROPY_4X) const;
|
||||
void samplers_rd_free(Samplers &p_samplers) const;
|
||||
|
||||
_FORCE_INLINE_ RID sampler_rd_get_default(RS::CanvasItemTextureFilter p_filter, RS::CanvasItemTextureRepeat p_repeat) {
|
||||
|
|
@ -389,7 +404,7 @@ public:
|
|||
|
||||
/* SHADER API */
|
||||
|
||||
bool owns_shader(RID p_rid) { return shader_owner.owns(p_rid); };
|
||||
bool owns_shader(RID p_rid) { return shader_owner.owns(p_rid); }
|
||||
|
||||
virtual RID shader_allocate() override;
|
||||
virtual void shader_initialize(RID p_shader) override;
|
||||
|
|
@ -409,7 +424,7 @@ public:
|
|||
|
||||
/* MATERIAL API */
|
||||
|
||||
bool owns_material(RID p_rid) { return material_owner.owns(p_rid); };
|
||||
bool owns_material(RID p_rid) { return material_owner.owns(p_rid); }
|
||||
|
||||
void _material_queue_update(Material *material, bool p_uniform, bool p_texture);
|
||||
void _update_queued_materials();
|
||||
|
|
@ -429,6 +444,7 @@ public:
|
|||
|
||||
virtual bool material_is_animated(RID p_material) override;
|
||||
virtual bool material_casts_shadows(RID p_material) override;
|
||||
virtual RS::CullMode material_get_cull_mode(RID p_material) const override;
|
||||
|
||||
virtual void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -370,7 +370,8 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
|
|||
s->format = new_surface.format;
|
||||
s->primitive = new_surface.primitive;
|
||||
|
||||
bool use_as_storage = (new_surface.skin_data.size() || mesh->blend_shape_count > 0);
|
||||
const bool use_as_storage = (new_surface.skin_data.size() || mesh->blend_shape_count > 0);
|
||||
const BitField<RD::BufferCreationBits> as_storage_flag = use_as_storage ? RD::BUFFER_CREATION_AS_STORAGE_BIT : 0;
|
||||
|
||||
if (new_surface.vertex_data.size()) {
|
||||
// If we have an uncompressed surface that contains normals, but not tangents, we need to differentiate the array
|
||||
|
|
@ -384,10 +385,10 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
|
|||
Vector<uint8_t> new_vertex_data;
|
||||
new_vertex_data.resize_zeroed(new_surface.vertex_data.size() + sizeof(uint16_t) * 2);
|
||||
memcpy(new_vertex_data.ptrw(), new_surface.vertex_data.ptr(), new_surface.vertex_data.size());
|
||||
s->vertex_buffer = RD::get_singleton()->vertex_buffer_create(new_vertex_data.size(), new_vertex_data, use_as_storage);
|
||||
s->vertex_buffer = RD::get_singleton()->vertex_buffer_create(new_vertex_data.size(), new_vertex_data, as_storage_flag);
|
||||
s->vertex_buffer_size = new_vertex_data.size();
|
||||
} else {
|
||||
s->vertex_buffer = RD::get_singleton()->vertex_buffer_create(new_surface.vertex_data.size(), new_surface.vertex_data, use_as_storage);
|
||||
s->vertex_buffer = RD::get_singleton()->vertex_buffer_create(new_surface.vertex_data.size(), new_surface.vertex_data, as_storage_flag);
|
||||
s->vertex_buffer_size = new_surface.vertex_data.size();
|
||||
}
|
||||
}
|
||||
|
|
@ -396,7 +397,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
|
|||
s->attribute_buffer = RD::get_singleton()->vertex_buffer_create(new_surface.attribute_data.size(), new_surface.attribute_data);
|
||||
}
|
||||
if (new_surface.skin_data.size()) {
|
||||
s->skin_buffer = RD::get_singleton()->vertex_buffer_create(new_surface.skin_data.size(), new_surface.skin_data, use_as_storage);
|
||||
s->skin_buffer = RD::get_singleton()->vertex_buffer_create(new_surface.skin_data.size(), new_surface.skin_data, as_storage_flag);
|
||||
s->skin_buffer_size = new_surface.skin_data.size();
|
||||
}
|
||||
|
||||
|
|
@ -505,6 +506,40 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
|
|||
mesh->material_cache.clear();
|
||||
}
|
||||
|
||||
void MeshStorage::_mesh_surface_clear(Mesh *p_mesh, int p_surface) {
|
||||
Mesh::Surface &s = *p_mesh->surfaces[p_surface];
|
||||
|
||||
if (s.vertex_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.vertex_buffer); // Clears arrays as dependency automatically, including all versions.
|
||||
}
|
||||
if (s.attribute_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.attribute_buffer);
|
||||
}
|
||||
if (s.skin_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.skin_buffer);
|
||||
}
|
||||
if (s.versions) {
|
||||
memfree(s.versions); // reallocs, so free with memfree.
|
||||
}
|
||||
|
||||
if (s.index_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.index_buffer);
|
||||
}
|
||||
|
||||
if (s.lod_count) {
|
||||
for (uint32_t j = 0; j < s.lod_count; j++) {
|
||||
RD::get_singleton()->free(s.lods[j].index_buffer);
|
||||
}
|
||||
memdelete_arr(s.lods);
|
||||
}
|
||||
|
||||
if (s.blend_shape_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.blend_shape_buffer);
|
||||
}
|
||||
|
||||
memdelete(p_mesh->surfaces[p_surface]);
|
||||
}
|
||||
|
||||
int MeshStorage::mesh_get_blend_shape_count(RID p_mesh) const {
|
||||
const Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_NULL_V(mesh, -1);
|
||||
|
|
@ -783,6 +818,7 @@ String MeshStorage::mesh_get_path(RID p_mesh) const {
|
|||
}
|
||||
|
||||
void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) {
|
||||
ERR_FAIL_COND_MSG(p_mesh == p_shadow_mesh, "Cannot set a mesh as its own shadow mesh.");
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_NULL(mesh);
|
||||
|
||||
|
|
@ -811,36 +847,7 @@ void MeshStorage::mesh_clear(RID p_mesh) {
|
|||
}
|
||||
|
||||
for (uint32_t i = 0; i < mesh->surface_count; i++) {
|
||||
Mesh::Surface &s = *mesh->surfaces[i];
|
||||
if (s.vertex_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.vertex_buffer); //clears arrays as dependency automatically, including all versions
|
||||
}
|
||||
if (s.attribute_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.attribute_buffer);
|
||||
}
|
||||
if (s.skin_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.skin_buffer);
|
||||
}
|
||||
if (s.versions) {
|
||||
memfree(s.versions); //reallocs, so free with memfree.
|
||||
}
|
||||
|
||||
if (s.index_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.index_buffer);
|
||||
}
|
||||
|
||||
if (s.lod_count) {
|
||||
for (uint32_t j = 0; j < s.lod_count; j++) {
|
||||
RD::get_singleton()->free(s.lods[j].index_buffer);
|
||||
}
|
||||
memdelete_arr(s.lods);
|
||||
}
|
||||
|
||||
if (s.blend_shape_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(s.blend_shape_buffer);
|
||||
}
|
||||
|
||||
memdelete(mesh->surfaces[i]);
|
||||
_mesh_surface_clear(mesh, i);
|
||||
}
|
||||
if (mesh->surfaces) {
|
||||
memfree(mesh->surfaces);
|
||||
|
|
@ -850,6 +857,57 @@ void MeshStorage::mesh_clear(RID p_mesh) {
|
|||
mesh->surface_count = 0;
|
||||
mesh->material_cache.clear();
|
||||
mesh->has_bone_weights = false;
|
||||
mesh->aabb = AABB();
|
||||
mesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_MESH);
|
||||
|
||||
for (Mesh *E : mesh->shadow_owners) {
|
||||
Mesh *shadow_owner = E;
|
||||
shadow_owner->shadow_mesh = RID();
|
||||
shadow_owner->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_MESH);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_surface_remove(RID p_mesh, int p_surface) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_NULL(mesh);
|
||||
ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count);
|
||||
|
||||
// Clear instance data before mesh data.
|
||||
for (MeshInstance *mi : mesh->instances) {
|
||||
_mesh_instance_remove_surface(mi, p_surface);
|
||||
}
|
||||
|
||||
_mesh_surface_clear(mesh, p_surface);
|
||||
|
||||
if ((uint32_t)p_surface < mesh->surface_count - 1) {
|
||||
memmove(mesh->surfaces + p_surface, mesh->surfaces + p_surface + 1, sizeof(Mesh::Surface *) * (mesh->surface_count - (p_surface + 1)));
|
||||
}
|
||||
mesh->surfaces = (Mesh::Surface **)memrealloc(mesh->surfaces, sizeof(Mesh::Surface *) * (mesh->surface_count - 1));
|
||||
--mesh->surface_count;
|
||||
|
||||
mesh->material_cache.clear();
|
||||
|
||||
mesh->skeleton_aabb_version = 0;
|
||||
|
||||
if (mesh->has_bone_weights) {
|
||||
mesh->has_bone_weights = false;
|
||||
for (uint32_t i = 0; i < mesh->surface_count; i++) {
|
||||
if (mesh->surfaces[i]->format & RS::ARRAY_FORMAT_BONES) {
|
||||
mesh->has_bone_weights = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh->surface_count == 0) {
|
||||
mesh->aabb = AABB();
|
||||
} else {
|
||||
mesh->aabb = mesh->surfaces[0]->aabb;
|
||||
for (uint32_t i = 1; i < mesh->surface_count; i++) {
|
||||
mesh->aabb.merge_with(mesh->surfaces[i]->aabb);
|
||||
}
|
||||
}
|
||||
|
||||
mesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_MESH);
|
||||
|
||||
for (Mesh *E : mesh->shadow_owners) {
|
||||
|
|
@ -924,29 +982,10 @@ void MeshStorage::mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int
|
|||
}
|
||||
|
||||
void MeshStorage::_mesh_instance_clear(MeshInstance *mi) {
|
||||
for (const RendererRD::MeshStorage::MeshInstance::Surface &surface : mi->surfaces) {
|
||||
if (surface.versions) {
|
||||
for (uint32_t j = 0; j < surface.version_count; j++) {
|
||||
RD::get_singleton()->free(surface.versions[j].vertex_array);
|
||||
}
|
||||
memfree(surface.versions);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
if (surface.vertex_buffer[i].is_valid()) {
|
||||
RD::get_singleton()->free(surface.vertex_buffer[i]);
|
||||
}
|
||||
}
|
||||
while (mi->surfaces.size()) {
|
||||
_mesh_instance_remove_surface(mi, mi->surfaces.size() - 1);
|
||||
}
|
||||
mi->surfaces.clear();
|
||||
|
||||
if (mi->blend_weights_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(mi->blend_weights_buffer);
|
||||
mi->blend_weights_buffer = RID();
|
||||
}
|
||||
mi->blend_weights.clear();
|
||||
mi->weights_dirty = false;
|
||||
mi->skeleton_version = 0;
|
||||
mi->dirty = false;
|
||||
}
|
||||
|
||||
void MeshStorage::_mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface) {
|
||||
|
|
@ -969,7 +1008,7 @@ void MeshStorage::_mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint3
|
|||
}
|
||||
|
||||
void MeshStorage::_mesh_instance_add_surface_buffer(MeshInstance *mi, Mesh *mesh, MeshInstance::Surface *s, uint32_t p_surface, uint32_t p_buffer_index) {
|
||||
s->vertex_buffer[p_buffer_index] = RD::get_singleton()->vertex_buffer_create(mesh->surfaces[p_surface]->vertex_buffer_size, Vector<uint8_t>(), true);
|
||||
s->vertex_buffer[p_buffer_index] = RD::get_singleton()->vertex_buffer_create(mesh->surfaces[p_surface]->vertex_buffer_size, Vector<uint8_t>(), RD::BUFFER_CREATION_AS_STORAGE_BIT);
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
{
|
||||
|
|
@ -993,6 +1032,36 @@ void MeshStorage::_mesh_instance_add_surface_buffer(MeshInstance *mi, Mesh *mesh
|
|||
s->uniform_set[p_buffer_index] = RD::get_singleton()->uniform_set_create(uniforms, skeleton_shader.version_shader[0], SkeletonShader::UNIFORM_SET_INSTANCE);
|
||||
}
|
||||
|
||||
void MeshStorage::_mesh_instance_remove_surface(MeshInstance *mi, int p_surface) {
|
||||
MeshInstance::Surface &surface = mi->surfaces[p_surface];
|
||||
|
||||
if (surface.versions) {
|
||||
for (uint32_t j = 0; j < surface.version_count; j++) {
|
||||
RD::get_singleton()->free(surface.versions[j].vertex_array);
|
||||
}
|
||||
memfree(surface.versions);
|
||||
}
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
if (surface.vertex_buffer[i].is_valid()) {
|
||||
RD::get_singleton()->free(surface.vertex_buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
mi->surfaces.remove_at(p_surface);
|
||||
|
||||
if (mi->surfaces.is_empty()) {
|
||||
if (mi->blend_weights_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(mi->blend_weights_buffer);
|
||||
mi->blend_weights_buffer = RID();
|
||||
}
|
||||
|
||||
mi->blend_weights.clear();
|
||||
mi->weights_dirty = false;
|
||||
mi->skeleton_version = 0;
|
||||
}
|
||||
mi->dirty = true;
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_instance_check_for_update(RID p_mesh_instance) {
|
||||
MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
|
||||
|
||||
|
|
@ -1056,8 +1125,9 @@ void MeshStorage::update_mesh_instances() {
|
|||
|
||||
mi->surfaces[i].previous_buffer = mi->surfaces[i].current_buffer;
|
||||
|
||||
if (uses_motion_vectors && (frame - mi->surfaces[i].last_change) == 1) {
|
||||
// Previous buffer's data can only be one frame old to be able to use motion vectors.
|
||||
if (uses_motion_vectors && mi->surfaces[i].last_change && (frame - mi->surfaces[i].last_change) <= 2) {
|
||||
// Use a 2-frame tolerance so that stepped skeletal animations have correct motion vectors
|
||||
// (stepped animation is common for distant NPCs).
|
||||
uint32_t new_buffer_index = mi->surfaces[i].current_buffer ^ 1;
|
||||
|
||||
if (mi->surfaces[i].uniform_set[new_buffer_index].is_null()) {
|
||||
|
|
@ -1140,97 +1210,71 @@ void MeshStorage::update_mesh_instances() {
|
|||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint64_t p_input_mask, bool p_input_motion_vectors, MeshInstance::Surface *mis, uint32_t p_current_buffer, uint32_t p_previous_buffer) {
|
||||
RD::VertexFormatID MeshStorage::_mesh_surface_generate_vertex_format(uint64_t p_surface_format, uint64_t p_input_mask, bool p_instanced_surface, bool p_input_motion_vectors, uint32_t &r_position_stride) {
|
||||
Vector<RD::VertexAttribute> attributes;
|
||||
Vector<RID> buffers;
|
||||
Vector<uint64_t> offsets;
|
||||
|
||||
uint32_t position_stride = 0;
|
||||
uint32_t normal_tangent_stride = 0;
|
||||
uint32_t attribute_stride = 0;
|
||||
uint32_t skin_stride = 0;
|
||||
|
||||
r_position_stride = 0;
|
||||
|
||||
for (int i = 0; i < RS::ARRAY_INDEX; i++) {
|
||||
RD::VertexAttribute vd;
|
||||
RID buffer;
|
||||
vd.location = i;
|
||||
uint64_t offset = 0;
|
||||
|
||||
if (!(s->format & (1ULL << i))) {
|
||||
// Not supplied by surface, use default value
|
||||
buffer = mesh_default_rd_buffers[i];
|
||||
if (!(p_surface_format & (1ULL << i))) {
|
||||
vd.stride = 0;
|
||||
switch (i) {
|
||||
case RS::ARRAY_VERTEX: {
|
||||
case RS::ARRAY_VERTEX:
|
||||
case RS::ARRAY_NORMAL:
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32_SFLOAT;
|
||||
|
||||
} break;
|
||||
case RS::ARRAY_NORMAL: {
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32_SFLOAT;
|
||||
} break;
|
||||
case RS::ARRAY_TANGENT: {
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_SFLOAT;
|
||||
} break;
|
||||
case RS::ARRAY_COLOR: {
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_SFLOAT;
|
||||
|
||||
} break;
|
||||
case RS::ARRAY_TEX_UV: {
|
||||
break;
|
||||
case RS::ARRAY_TEX_UV:
|
||||
case RS::ARRAY_TEX_UV2:
|
||||
vd.format = RD::DATA_FORMAT_R32G32_SFLOAT;
|
||||
|
||||
} break;
|
||||
case RS::ARRAY_TEX_UV2: {
|
||||
vd.format = RD::DATA_FORMAT_R32G32_SFLOAT;
|
||||
} break;
|
||||
break;
|
||||
case RS::ARRAY_BONES:
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_UINT;
|
||||
break;
|
||||
case RS::ARRAY_TANGENT:
|
||||
case RS::ARRAY_COLOR:
|
||||
case RS::ARRAY_CUSTOM0:
|
||||
case RS::ARRAY_CUSTOM1:
|
||||
case RS::ARRAY_CUSTOM2:
|
||||
case RS::ARRAY_CUSTOM3: {
|
||||
//assumed weights too
|
||||
case RS::ARRAY_CUSTOM3:
|
||||
case RS::ARRAY_WEIGHTS:
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_SFLOAT;
|
||||
} break;
|
||||
case RS::ARRAY_BONES: {
|
||||
//assumed weights too
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_UINT;
|
||||
} break;
|
||||
case RS::ARRAY_WEIGHTS: {
|
||||
//assumed weights too
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_SFLOAT;
|
||||
} break;
|
||||
break;
|
||||
default:
|
||||
DEV_ASSERT(false && "Unknown vertex format element.");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
//Supplied, use it
|
||||
|
||||
vd.stride = 1; //mark that it needs a stride set (default uses 0)
|
||||
// Mark that it needs a stride set (default uses 0).
|
||||
vd.stride = 1;
|
||||
|
||||
switch (i) {
|
||||
case RS::ARRAY_VERTEX: {
|
||||
vd.offset = position_stride;
|
||||
vd.offset = r_position_stride;
|
||||
|
||||
if (s->format & RS::ARRAY_FLAG_USE_2D_VERTICES) {
|
||||
if (p_surface_format & RS::ARRAY_FLAG_USE_2D_VERTICES) {
|
||||
vd.format = RD::DATA_FORMAT_R32G32_SFLOAT;
|
||||
position_stride = sizeof(float) * 2;
|
||||
r_position_stride = sizeof(float) * 2;
|
||||
} else {
|
||||
if (!mis && (s->format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
|
||||
if (!p_instanced_surface && (p_surface_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
|
||||
vd.format = RD::DATA_FORMAT_R16G16B16A16_UNORM;
|
||||
position_stride = sizeof(uint16_t) * 4;
|
||||
r_position_stride = sizeof(uint16_t) * 4;
|
||||
} else {
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32_SFLOAT;
|
||||
position_stride = sizeof(float) * 3;
|
||||
r_position_stride = sizeof(float) * 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (mis) {
|
||||
buffer = mis->vertex_buffer[p_current_buffer];
|
||||
} else {
|
||||
buffer = s->vertex_buffer;
|
||||
}
|
||||
|
||||
} break;
|
||||
case RS::ARRAY_NORMAL: {
|
||||
vd.offset = 0;
|
||||
offset = position_stride * s->vertex_count;
|
||||
if (!mis && (s->format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
|
||||
|
||||
if (!p_instanced_surface && (p_surface_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES)) {
|
||||
vd.format = RD::DATA_FORMAT_R16G16_UNORM;
|
||||
normal_tangent_stride += sizeof(uint16_t) * 2;
|
||||
} else {
|
||||
|
|
@ -1238,20 +1282,14 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V
|
|||
// A small trick here: if we are uncompressed and we have normals, but no tangents. We need
|
||||
// the shader to think there are 4 components to "axis_tangent_attrib". So we give a size of 4,
|
||||
// but a stride based on only having 2 elements.
|
||||
if (!(s->format & RS::ARRAY_FORMAT_TANGENT)) {
|
||||
if (!(p_surface_format & RS::ARRAY_FORMAT_TANGENT)) {
|
||||
normal_tangent_stride += sizeof(uint16_t) * 2;
|
||||
} else {
|
||||
normal_tangent_stride += sizeof(uint16_t) * 4;
|
||||
}
|
||||
}
|
||||
if (mis) {
|
||||
buffer = mis->vertex_buffer[p_current_buffer];
|
||||
} else {
|
||||
buffer = s->vertex_buffer;
|
||||
}
|
||||
} break;
|
||||
case RS::ARRAY_TANGENT: {
|
||||
buffer = mesh_default_rd_buffers[i];
|
||||
vd.stride = 0;
|
||||
vd.format = RD::DATA_FORMAT_R32G32B32A32_SFLOAT;
|
||||
} break;
|
||||
|
|
@ -1260,30 +1298,27 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V
|
|||
|
||||
vd.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
attribute_stride += sizeof(int8_t) * 4;
|
||||
buffer = s->attribute_buffer;
|
||||
} break;
|
||||
case RS::ARRAY_TEX_UV: {
|
||||
vd.offset = attribute_stride;
|
||||
if (s->format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
|
||||
if (p_surface_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
|
||||
vd.format = RD::DATA_FORMAT_R16G16_UNORM;
|
||||
attribute_stride += sizeof(uint16_t) * 2;
|
||||
} else {
|
||||
vd.format = RD::DATA_FORMAT_R32G32_SFLOAT;
|
||||
attribute_stride += sizeof(float) * 2;
|
||||
}
|
||||
buffer = s->attribute_buffer;
|
||||
|
||||
} break;
|
||||
case RS::ARRAY_TEX_UV2: {
|
||||
vd.offset = attribute_stride;
|
||||
if (s->format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
|
||||
if (p_surface_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) {
|
||||
vd.format = RD::DATA_FORMAT_R16G16_UNORM;
|
||||
attribute_stride += sizeof(uint16_t) * 2;
|
||||
} else {
|
||||
vd.format = RD::DATA_FORMAT_R32G32_SFLOAT;
|
||||
attribute_stride += sizeof(float) * 2;
|
||||
}
|
||||
buffer = s->attribute_buffer;
|
||||
} break;
|
||||
case RS::ARRAY_CUSTOM0:
|
||||
case RS::ARRAY_CUSTOM1:
|
||||
|
|
@ -1293,26 +1328,23 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V
|
|||
|
||||
int idx = i - RS::ARRAY_CUSTOM0;
|
||||
const uint32_t fmt_shift[RS::ARRAY_CUSTOM_COUNT] = { RS::ARRAY_FORMAT_CUSTOM0_SHIFT, RS::ARRAY_FORMAT_CUSTOM1_SHIFT, RS::ARRAY_FORMAT_CUSTOM2_SHIFT, RS::ARRAY_FORMAT_CUSTOM3_SHIFT };
|
||||
uint32_t fmt = (s->format >> fmt_shift[idx]) & RS::ARRAY_FORMAT_CUSTOM_MASK;
|
||||
uint32_t fmt = (p_surface_format >> fmt_shift[idx]) & RS::ARRAY_FORMAT_CUSTOM_MASK;
|
||||
const uint32_t fmtsize[RS::ARRAY_CUSTOM_MAX] = { 4, 4, 4, 8, 4, 8, 12, 16 };
|
||||
const RD::DataFormat fmtrd[RS::ARRAY_CUSTOM_MAX] = { RD::DATA_FORMAT_R8G8B8A8_UNORM, RD::DATA_FORMAT_R8G8B8A8_SNORM, RD::DATA_FORMAT_R16G16_SFLOAT, RD::DATA_FORMAT_R16G16B16A16_SFLOAT, RD::DATA_FORMAT_R32_SFLOAT, RD::DATA_FORMAT_R32G32_SFLOAT, RD::DATA_FORMAT_R32G32B32_SFLOAT, RD::DATA_FORMAT_R32G32B32A32_SFLOAT };
|
||||
vd.format = fmtrd[fmt];
|
||||
attribute_stride += fmtsize[fmt];
|
||||
buffer = s->attribute_buffer;
|
||||
} break;
|
||||
case RS::ARRAY_BONES: {
|
||||
vd.offset = skin_stride;
|
||||
|
||||
vd.format = RD::DATA_FORMAT_R16G16B16A16_UINT;
|
||||
skin_stride += sizeof(int16_t) * 4;
|
||||
buffer = s->skin_buffer;
|
||||
} break;
|
||||
case RS::ARRAY_WEIGHTS: {
|
||||
vd.offset = skin_stride;
|
||||
|
||||
vd.format = RD::DATA_FORMAT_R16G16B16A16_UNORM;
|
||||
skin_stride += sizeof(int16_t) * 4;
|
||||
buffer = s->skin_buffer;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1322,13 +1354,10 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V
|
|||
}
|
||||
|
||||
attributes.push_back(vd);
|
||||
buffers.push_back(buffer);
|
||||
offsets.push_back(offset);
|
||||
|
||||
if (p_input_motion_vectors) {
|
||||
// Since the previous vertex, normal and tangent can't be part of the vertex format but they are required when motion
|
||||
// vectors are enabled, we opt to push a copy of the vertex attribute with a different location and buffer (if it's
|
||||
// part of an instance that has one).
|
||||
// Since the previous vertex, normal and tangent can't be part of the vertex format but they are required when
|
||||
// motion vectors are enabled, we opt to push a copy of the vertex attribute with a different location.
|
||||
switch (i) {
|
||||
case RS::ARRAY_VERTEX: {
|
||||
vd.location = ATTRIBUTE_LOCATION_PREV_VERTEX;
|
||||
|
|
@ -1342,25 +1371,21 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V
|
|||
}
|
||||
|
||||
if (int(vd.location) != i) {
|
||||
if (mis && buffer != mesh_default_rd_buffers[i]) {
|
||||
buffer = mis->vertex_buffer[p_previous_buffer];
|
||||
}
|
||||
|
||||
attributes.push_back(vd);
|
||||
buffers.push_back(buffer);
|
||||
offsets.push_back(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//update final stride
|
||||
// Update final stride.
|
||||
for (int i = 0; i < attributes.size(); i++) {
|
||||
if (attributes[i].stride == 0) {
|
||||
continue; //default location
|
||||
// Default location.
|
||||
continue;
|
||||
}
|
||||
|
||||
int loc = attributes[i].location;
|
||||
if (loc == RS::ARRAY_VERTEX || loc == ATTRIBUTE_LOCATION_PREV_VERTEX) {
|
||||
attributes.write[i].stride = position_stride;
|
||||
attributes.write[i].stride = r_position_stride;
|
||||
} else if ((loc < RS::ARRAY_COLOR) || ((loc >= ATTRIBUTE_LOCATION_PREV_NORMAL) && (loc <= ATTRIBUTE_LOCATION_PREV_TANGENT))) {
|
||||
attributes.write[i].stride = normal_tangent_stride;
|
||||
} else if (loc < RS::ARRAY_BONES) {
|
||||
|
|
@ -1370,24 +1395,90 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V
|
|||
}
|
||||
}
|
||||
|
||||
return RD::get_singleton()->vertex_format_create(attributes);
|
||||
}
|
||||
|
||||
void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint64_t p_input_mask, bool p_input_motion_vectors, MeshInstance::Surface *mis, uint32_t p_current_buffer, uint32_t p_previous_buffer) {
|
||||
uint32_t position_stride = 0;
|
||||
v.vertex_format = _mesh_surface_generate_vertex_format(s->format, p_input_mask, mis != nullptr, p_input_motion_vectors, position_stride);
|
||||
|
||||
Vector<RID> buffers;
|
||||
Vector<uint64_t> offsets;
|
||||
RID buffer;
|
||||
uint64_t offset = 0;
|
||||
for (int i = 0; i < RS::ARRAY_INDEX; i++) {
|
||||
offset = 0;
|
||||
|
||||
if (!(s->format & (1ULL << i))) {
|
||||
// Not supplied by surface, use default buffers.
|
||||
buffer = mesh_default_rd_buffers[i];
|
||||
} else {
|
||||
// Supplied by surface, use buffer.
|
||||
switch (i) {
|
||||
case RS::ARRAY_VERTEX:
|
||||
case RS::ARRAY_NORMAL:
|
||||
offset = i == RS::ARRAY_NORMAL ? position_stride * s->vertex_count : 0;
|
||||
buffer = mis != nullptr ? mis->vertex_buffer[p_current_buffer] : s->vertex_buffer;
|
||||
break;
|
||||
case RS::ARRAY_TANGENT:
|
||||
buffer = mesh_default_rd_buffers[i];
|
||||
break;
|
||||
case RS::ARRAY_COLOR:
|
||||
case RS::ARRAY_TEX_UV:
|
||||
case RS::ARRAY_TEX_UV2:
|
||||
case RS::ARRAY_CUSTOM0:
|
||||
case RS::ARRAY_CUSTOM1:
|
||||
case RS::ARRAY_CUSTOM2:
|
||||
case RS::ARRAY_CUSTOM3:
|
||||
buffer = s->attribute_buffer;
|
||||
break;
|
||||
case RS::ARRAY_BONES:
|
||||
case RS::ARRAY_WEIGHTS:
|
||||
buffer = s->skin_buffer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(p_input_mask & (1ULL << i))) {
|
||||
continue; // Shader does not need this, skip it (but computing stride was important anyway)
|
||||
}
|
||||
|
||||
buffers.push_back(buffer);
|
||||
offsets.push_back(offset);
|
||||
|
||||
if (p_input_motion_vectors) {
|
||||
// Push the buffer for motion vector inputs.
|
||||
if (i == RS::ARRAY_VERTEX || i == RS::ARRAY_NORMAL || i == RS::ARRAY_TANGENT) {
|
||||
if (mis && buffer != mesh_default_rd_buffers[i]) {
|
||||
buffers.push_back(mis->vertex_buffer[p_previous_buffer]);
|
||||
} else {
|
||||
buffers.push_back(buffer);
|
||||
}
|
||||
|
||||
offsets.push_back(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v.input_mask = p_input_mask;
|
||||
v.current_buffer = p_current_buffer;
|
||||
v.previous_buffer = p_previous_buffer;
|
||||
v.input_motion_vectors = p_input_motion_vectors;
|
||||
v.vertex_format = RD::get_singleton()->vertex_format_create(attributes);
|
||||
v.vertex_array = RD::get_singleton()->vertex_array_create(s->vertex_count, v.vertex_format, buffers, offsets);
|
||||
}
|
||||
|
||||
////////////////// MULTIMESH
|
||||
|
||||
RID MeshStorage::multimesh_allocate() {
|
||||
RID MeshStorage::_multimesh_allocate() {
|
||||
return multimesh_owner.allocate_rid();
|
||||
}
|
||||
void MeshStorage::multimesh_initialize(RID p_rid) {
|
||||
void MeshStorage::_multimesh_initialize(RID p_rid) {
|
||||
multimesh_owner.initialize_rid(p_rid, MultiMesh());
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_free(RID p_rid) {
|
||||
void MeshStorage::_multimesh_free(RID p_rid) {
|
||||
// Remove from interpolator.
|
||||
_interpolation_data.notify_free_multimesh(p_rid);
|
||||
_update_dirty_multimeshes();
|
||||
multimesh_allocate_data(p_rid, 0, RS::MULTIMESH_TRANSFORM_2D);
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_rid);
|
||||
|
|
@ -1395,7 +1486,7 @@ void MeshStorage::multimesh_free(RID p_rid) {
|
|||
multimesh_owner.free(p_rid);
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors, bool p_use_custom_data) {
|
||||
void MeshStorage::_multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors, bool p_use_custom_data, bool p_use_indirect) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
|
||||
|
|
@ -1431,6 +1522,9 @@ void MeshStorage::multimesh_allocate_data(RID p_multimesh, int p_instances, RS::
|
|||
multimesh->stride_cache = multimesh->custom_data_offset_cache + (p_use_custom_data ? 4 : 0);
|
||||
multimesh->buffer_set = false;
|
||||
|
||||
multimesh->indirect = p_use_indirect;
|
||||
multimesh->command_buffer = RID();
|
||||
|
||||
//print_line("allocate, elements: " + itos(p_instances) + " 2D: " + itos(p_transform_format == RS::MULTIMESH_TRANSFORM_2D) + " colors " + itos(multimesh->uses_colors) + " data " + itos(multimesh->uses_custom_data) + " stride " + itos(multimesh->stride_cache) + " total size " + itos(multimesh->stride_cache * multimesh->instances));
|
||||
multimesh->data_cache = Vector<float>();
|
||||
multimesh->aabb = AABB();
|
||||
|
|
@ -1439,12 +1533,10 @@ void MeshStorage::multimesh_allocate_data(RID p_multimesh, int p_instances, RS::
|
|||
multimesh->motion_vectors_current_offset = 0;
|
||||
multimesh->motion_vectors_previous_offset = 0;
|
||||
multimesh->motion_vectors_last_change = -1;
|
||||
multimesh->motion_vectors_enabled = false;
|
||||
|
||||
if (multimesh->instances) {
|
||||
uint32_t buffer_size = multimesh->instances * multimesh->stride_cache * sizeof(float);
|
||||
if (multimesh->motion_vectors_enabled) {
|
||||
buffer_size *= 2;
|
||||
}
|
||||
multimesh->buffer = RD::get_singleton()->storage_buffer_create(buffer_size);
|
||||
}
|
||||
|
||||
|
|
@ -1507,13 +1599,13 @@ bool MeshStorage::_multimesh_uses_motion_vectors_offsets(RID p_multimesh) {
|
|||
return _multimesh_uses_motion_vectors(multimesh);
|
||||
}
|
||||
|
||||
int MeshStorage::multimesh_get_instance_count(RID p_multimesh) const {
|
||||
int MeshStorage::_multimesh_get_instance_count(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, 0);
|
||||
return multimesh->instances;
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
|
||||
void MeshStorage::_multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
if (multimesh->mesh == p_mesh) {
|
||||
|
|
@ -1521,6 +1613,30 @@ void MeshStorage::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
|
|||
}
|
||||
multimesh->mesh = p_mesh;
|
||||
|
||||
if (multimesh->indirect) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_NULL(mesh);
|
||||
if (mesh->surface_count > 0) {
|
||||
if (multimesh->command_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(multimesh->command_buffer);
|
||||
}
|
||||
|
||||
Vector<uint8_t> newVector;
|
||||
newVector.resize_zeroed(sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE * mesh->surface_count);
|
||||
|
||||
for (uint32_t i = 0; i < mesh->surface_count; i++) {
|
||||
uint32_t count = mesh_surface_get_vertices_drawn_count(mesh->surfaces[i]);
|
||||
newVector.set(i * sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE, static_cast<uint8_t>(count));
|
||||
newVector.set(i * sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE + 1, static_cast<uint8_t>(count >> 8));
|
||||
newVector.set(i * sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE + 2, static_cast<uint8_t>(count >> 16));
|
||||
newVector.set(i * sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE + 3, static_cast<uint8_t>(count >> 24));
|
||||
}
|
||||
|
||||
RID newBuffer = RD::get_singleton()->storage_buffer_create(sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE * mesh->surface_count, newVector, RD::STORAGE_BUFFER_USAGE_DISPATCH_INDIRECT);
|
||||
multimesh->command_buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
if (multimesh->instances == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1703,7 +1819,7 @@ void MeshStorage::_multimesh_re_create_aabb(MultiMesh *multimesh, const float *p
|
|||
multimesh->aabb = aabb;
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) {
|
||||
void MeshStorage::_multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
ERR_FAIL_INDEX(p_index, multimesh->instances);
|
||||
|
|
@ -1740,7 +1856,7 @@ void MeshStorage::multimesh_instance_set_transform(RID p_multimesh, int p_index,
|
|||
_multimesh_mark_dirty(multimesh, p_index, true);
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {
|
||||
void MeshStorage::_multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
ERR_FAIL_INDEX(p_index, multimesh->instances);
|
||||
|
|
@ -1767,7 +1883,7 @@ void MeshStorage::multimesh_instance_set_transform_2d(RID p_multimesh, int p_ind
|
|||
_multimesh_mark_dirty(multimesh, p_index, true);
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
void MeshStorage::_multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
ERR_FAIL_INDEX(p_index, multimesh->instances);
|
||||
|
|
@ -1790,7 +1906,7 @@ void MeshStorage::multimesh_instance_set_color(RID p_multimesh, int p_index, con
|
|||
_multimesh_mark_dirty(multimesh, p_index, false);
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
void MeshStorage::_multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
ERR_FAIL_INDEX(p_index, multimesh->instances);
|
||||
|
|
@ -1813,7 +1929,7 @@ void MeshStorage::multimesh_instance_set_custom_data(RID p_multimesh, int p_inde
|
|||
_multimesh_mark_dirty(multimesh, p_index, false);
|
||||
}
|
||||
|
||||
RID MeshStorage::multimesh_get_mesh(RID p_multimesh) const {
|
||||
RID MeshStorage::_multimesh_get_mesh(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, RID());
|
||||
|
||||
|
|
@ -1827,7 +1943,7 @@ Dependency *MeshStorage::multimesh_get_dependency(RID p_multimesh) const {
|
|||
return &multimesh->dependency;
|
||||
}
|
||||
|
||||
Transform3D MeshStorage::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
|
||||
Transform3D MeshStorage::_multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, Transform3D());
|
||||
ERR_FAIL_INDEX_V(p_index, multimesh->instances, Transform3D());
|
||||
|
|
@ -1858,7 +1974,7 @@ Transform3D MeshStorage::multimesh_instance_get_transform(RID p_multimesh, int p
|
|||
return t;
|
||||
}
|
||||
|
||||
Transform2D MeshStorage::multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const {
|
||||
Transform2D MeshStorage::_multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, Transform2D());
|
||||
ERR_FAIL_INDEX_V(p_index, multimesh->instances, Transform2D());
|
||||
|
|
@ -1883,7 +1999,7 @@ Transform2D MeshStorage::multimesh_instance_get_transform_2d(RID p_multimesh, in
|
|||
return t;
|
||||
}
|
||||
|
||||
Color MeshStorage::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
|
||||
Color MeshStorage::_multimesh_instance_get_color(RID p_multimesh, int p_index) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, Color());
|
||||
ERR_FAIL_INDEX_V(p_index, multimesh->instances, Color());
|
||||
|
|
@ -1906,7 +2022,7 @@ Color MeshStorage::multimesh_instance_get_color(RID p_multimesh, int p_index) co
|
|||
return c;
|
||||
}
|
||||
|
||||
Color MeshStorage::multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const {
|
||||
Color MeshStorage::_multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, Color());
|
||||
ERR_FAIL_INDEX_V(p_index, multimesh->instances, Color());
|
||||
|
|
@ -1929,11 +2045,12 @@ Color MeshStorage::multimesh_instance_get_custom_data(RID p_multimesh, int p_ind
|
|||
return c;
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {
|
||||
void MeshStorage::_multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
ERR_FAIL_COND(p_buffer.size() != (multimesh->instances * (int)multimesh->stride_cache));
|
||||
|
||||
bool used_motion_vectors = multimesh->motion_vectors_enabled;
|
||||
bool uses_motion_vectors = (RSG::viewport->get_num_viewports_with_motion_vectors() > 0) || (RendererCompositorStorage::get_singleton()->get_num_compositor_effects_with_motion_vectors() > 0);
|
||||
if (uses_motion_vectors) {
|
||||
_multimesh_enable_motion_vectors(multimesh);
|
||||
|
|
@ -1952,6 +2069,11 @@ void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_b
|
|||
{
|
||||
const float *r = p_buffer.ptr();
|
||||
RD::get_singleton()->buffer_update(multimesh->buffer, multimesh->motion_vectors_current_offset * multimesh->stride_cache * sizeof(float), p_buffer.size() * sizeof(float), r);
|
||||
if (multimesh->motion_vectors_enabled && !used_motion_vectors) {
|
||||
// Motion vectors were just enabled, and the other half of the buffer will be empty.
|
||||
// Need to ensure that both halves are filled for correct operation.
|
||||
RD::get_singleton()->buffer_update(multimesh->buffer, multimesh->motion_vectors_previous_offset * multimesh->stride_cache * sizeof(float), p_buffer.size() * sizeof(float), r);
|
||||
}
|
||||
multimesh->buffer_set = true;
|
||||
}
|
||||
|
||||
|
|
@ -1970,7 +2092,19 @@ void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_b
|
|||
}
|
||||
}
|
||||
|
||||
Vector<float> MeshStorage::multimesh_get_buffer(RID p_multimesh) const {
|
||||
RID MeshStorage::_multimesh_get_command_buffer_rd_rid(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, RID());
|
||||
return multimesh->command_buffer;
|
||||
}
|
||||
|
||||
RID MeshStorage::_multimesh_get_buffer_rd_rid(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, RID());
|
||||
return multimesh->buffer;
|
||||
}
|
||||
|
||||
Vector<float> MeshStorage::_multimesh_get_buffer(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, Vector<float>());
|
||||
if (multimesh->buffer.is_null()) {
|
||||
|
|
@ -1992,7 +2126,7 @@ Vector<float> MeshStorage::multimesh_get_buffer(RID p_multimesh) const {
|
|||
}
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
|
||||
void MeshStorage::_multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
ERR_FAIL_COND(p_visible < -1 || p_visible > multimesh->instances);
|
||||
|
|
@ -2011,29 +2145,38 @@ void MeshStorage::multimesh_set_visible_instances(RID p_multimesh, int p_visible
|
|||
|
||||
multimesh->visible_instances = p_visible;
|
||||
|
||||
if (multimesh->indirect) { //we have to update the command buffer for the instance counts, in each stride this will be the second integer.
|
||||
Mesh *mesh = mesh_owner.get_or_null(multimesh->mesh);
|
||||
if (mesh != nullptr) {
|
||||
for (uint32_t i = 0; i < mesh->surface_count; i++) {
|
||||
RD::get_singleton()->buffer_update(multimesh->command_buffer, (i * sizeof(uint32_t) * INDIRECT_MULTIMESH_COMMAND_STRIDE) + sizeof(uint32_t), sizeof(uint32_t), &p_visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_MULTIMESH_VISIBLE_INSTANCES);
|
||||
}
|
||||
|
||||
int MeshStorage::multimesh_get_visible_instances(RID p_multimesh) const {
|
||||
int MeshStorage::_multimesh_get_visible_instances(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, 0);
|
||||
return multimesh->visible_instances;
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_custom_aabb(RID p_multimesh, const AABB &p_aabb) {
|
||||
void MeshStorage::_multimesh_set_custom_aabb(RID p_multimesh, const AABB &p_aabb) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL(multimesh);
|
||||
multimesh->custom_aabb = p_aabb;
|
||||
multimesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_AABB);
|
||||
}
|
||||
|
||||
AABB MeshStorage::multimesh_get_custom_aabb(RID p_multimesh) const {
|
||||
AABB MeshStorage::_multimesh_get_custom_aabb(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, AABB());
|
||||
return multimesh->custom_aabb;
|
||||
}
|
||||
|
||||
AABB MeshStorage::multimesh_get_aabb(RID p_multimesh) const {
|
||||
AABB MeshStorage::_multimesh_get_aabb(RID p_multimesh) {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V(multimesh, AABB());
|
||||
if (multimesh->custom_aabb != AABB()) {
|
||||
|
|
@ -2041,11 +2184,18 @@ AABB MeshStorage::multimesh_get_aabb(RID p_multimesh) const {
|
|||
}
|
||||
|
||||
if (multimesh->aabb_dirty) {
|
||||
const_cast<MeshStorage *>(this)->_update_dirty_multimeshes();
|
||||
_update_dirty_multimeshes();
|
||||
}
|
||||
return multimesh->aabb;
|
||||
}
|
||||
|
||||
MeshStorage::MultiMeshInterpolator *MeshStorage::_multimesh_get_interpolator(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
ERR_FAIL_NULL_V_MSG(multimesh, nullptr, "Multimesh not found: " + itos(p_multimesh.get_id()));
|
||||
|
||||
return &multimesh->interpolator;
|
||||
}
|
||||
|
||||
void MeshStorage::_update_dirty_multimeshes() {
|
||||
while (multimesh_dirty_list) {
|
||||
MultiMesh *multimesh = multimesh_dirty_list;
|
||||
|
|
@ -2151,7 +2301,7 @@ void MeshStorage::skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_
|
|||
if (skeleton->size) {
|
||||
skeleton->data.resize(skeleton->size * (skeleton->use_2d ? 8 : 12));
|
||||
skeleton->buffer = RD::get_singleton()->storage_buffer_create(skeleton->data.size() * sizeof(float));
|
||||
memset(skeleton->data.ptrw(), 0, skeleton->data.size() * sizeof(float));
|
||||
memset(skeleton->data.ptr(), 0, skeleton->data.size() * sizeof(float));
|
||||
|
||||
_skeleton_make_dirty(skeleton);
|
||||
|
||||
|
|
@ -2185,7 +2335,7 @@ void MeshStorage::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const
|
|||
ERR_FAIL_INDEX(p_bone, skeleton->size);
|
||||
ERR_FAIL_COND(skeleton->use_2d);
|
||||
|
||||
float *dataptr = skeleton->data.ptrw() + p_bone * 12;
|
||||
float *dataptr = skeleton->data.ptr() + p_bone * 12;
|
||||
|
||||
dataptr[0] = p_transform.basis.rows[0][0];
|
||||
dataptr[1] = p_transform.basis.rows[0][1];
|
||||
|
|
@ -2236,8 +2386,7 @@ void MeshStorage::skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, con
|
|||
ERR_FAIL_NULL(skeleton);
|
||||
ERR_FAIL_INDEX(p_bone, skeleton->size);
|
||||
ERR_FAIL_COND(!skeleton->use_2d);
|
||||
|
||||
float *dataptr = skeleton->data.ptrw() + p_bone * 8;
|
||||
float *dataptr = skeleton->data.ptr() + p_bone * 8;
|
||||
|
||||
dataptr[0] = p_transform.columns[0][0];
|
||||
dataptr[1] = p_transform.columns[1][0];
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ public:
|
|||
DEFAULT_RD_BUFFER_MAX,
|
||||
};
|
||||
|
||||
enum IndirectMultiMesh : uint32_t {
|
||||
INDIRECT_MULTIMESH_COMMAND_STRIDE = 5
|
||||
};
|
||||
|
||||
private:
|
||||
static MeshStorage *singleton;
|
||||
|
||||
|
|
@ -199,11 +203,14 @@ private:
|
|||
weight_update_list(this), array_update_list(this) {}
|
||||
};
|
||||
|
||||
RD::VertexFormatID _mesh_surface_generate_vertex_format(uint64_t p_surface_format, uint64_t p_input_mask, bool p_instanced_surface, bool p_input_motion_vectors, uint32_t &r_position_stride);
|
||||
void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint64_t p_input_mask, bool p_input_motion_vectors, MeshInstance::Surface *mis = nullptr, uint32_t p_current_buffer = 0, uint32_t p_previous_buffer = 0);
|
||||
void _mesh_surface_clear(Mesh *p_mesh, int p_surface);
|
||||
|
||||
void _mesh_instance_clear(MeshInstance *mi);
|
||||
void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
|
||||
void _mesh_instance_add_surface_buffer(MeshInstance *mi, Mesh *mesh, MeshInstance::Surface *s, uint32_t p_surface, uint32_t p_buffer_index);
|
||||
void _mesh_instance_remove_surface(MeshInstance *mi, int p_surface);
|
||||
|
||||
mutable RID_Owner<MeshInstance> mesh_instance_owner;
|
||||
|
||||
|
|
@ -223,6 +230,7 @@ private:
|
|||
AABB custom_aabb;
|
||||
bool aabb_dirty = false;
|
||||
bool buffer_set = false;
|
||||
bool indirect = false;
|
||||
bool motion_vectors_enabled = false;
|
||||
uint32_t motion_vectors_current_offset = 0;
|
||||
uint32_t motion_vectors_previous_offset = 0;
|
||||
|
|
@ -240,10 +248,13 @@ private:
|
|||
RID buffer; //storage buffer
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_2d;
|
||||
RID command_buffer; //used if indirect setting is used
|
||||
|
||||
bool dirty = false;
|
||||
MultiMesh *dirty_list = nullptr;
|
||||
|
||||
RendererMeshStorage::MultiMeshInterpolator interpolator;
|
||||
|
||||
Dependency dependency;
|
||||
};
|
||||
|
||||
|
|
@ -309,7 +320,7 @@ private:
|
|||
struct Skeleton {
|
||||
bool use_2d = false;
|
||||
int size = 0;
|
||||
Vector<float> data;
|
||||
LocalVector<float> data;
|
||||
RID buffer;
|
||||
|
||||
bool dirty = false;
|
||||
|
|
@ -348,7 +359,7 @@ public:
|
|||
|
||||
/* MESH API */
|
||||
|
||||
bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); };
|
||||
bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); }
|
||||
|
||||
virtual RID mesh_allocate() override;
|
||||
virtual void mesh_initialize(RID p_mesh) override;
|
||||
|
|
@ -385,6 +396,7 @@ public:
|
|||
virtual String mesh_get_path(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_clear(RID p_mesh) override;
|
||||
virtual void mesh_surface_remove(RID p_mesh, int p_surface) override;
|
||||
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
|
||||
|
||||
|
|
@ -603,11 +615,17 @@ public:
|
|||
return s->particles_render_index;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RD::VertexFormatID mesh_surface_get_vertex_format(void *p_surface, uint64_t p_input_mask, bool p_instanced_surface, bool p_input_motion_vectors) {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
uint32_t position_stride = 0;
|
||||
return _mesh_surface_generate_vertex_format(s->format, p_input_mask, p_instanced_surface, p_input_motion_vectors, position_stride);
|
||||
}
|
||||
|
||||
Dependency *mesh_get_dependency(RID p_mesh) const;
|
||||
|
||||
/* MESH INSTANCE API */
|
||||
|
||||
bool owns_mesh_instance(RID p_rid) const { return mesh_instance_owner.owns(p_rid); };
|
||||
bool owns_mesh_instance(RID p_rid) const { return mesh_instance_owner.owns(p_rid); }
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base) override;
|
||||
virtual void mesh_instance_free(RID p_rid) override;
|
||||
|
|
@ -619,44 +637,53 @@ public:
|
|||
|
||||
/* MULTIMESH API */
|
||||
|
||||
bool owns_multimesh(RID p_rid) { return multimesh_owner.owns(p_rid); };
|
||||
bool owns_multimesh(RID p_rid) { return multimesh_owner.owns(p_rid); }
|
||||
|
||||
virtual RID multimesh_allocate() override;
|
||||
virtual void multimesh_initialize(RID p_multimesh) override;
|
||||
virtual void multimesh_free(RID p_rid) override;
|
||||
virtual RID _multimesh_allocate() override;
|
||||
virtual void _multimesh_initialize(RID p_multimesh) override;
|
||||
virtual void _multimesh_free(RID p_rid) override;
|
||||
|
||||
virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override;
|
||||
virtual int multimesh_get_instance_count(RID p_multimesh) const override;
|
||||
virtual void _multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false, bool p_use_indirect = false) override;
|
||||
virtual int _multimesh_get_instance_count(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
|
||||
virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
|
||||
virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
|
||||
virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
virtual void _multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
|
||||
virtual void _multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
|
||||
virtual void _multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
|
||||
virtual void _multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
virtual void _multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
|
||||
virtual RID multimesh_get_mesh(RID p_multimesh) const override;
|
||||
virtual RID _multimesh_get_mesh(RID p_multimesh) const override;
|
||||
|
||||
virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
|
||||
virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
|
||||
virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
|
||||
virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
|
||||
virtual Transform3D _multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
|
||||
virtual Transform2D _multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
|
||||
virtual Color _multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
|
||||
virtual Color _multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
|
||||
|
||||
virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
|
||||
virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const override;
|
||||
virtual void _multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
|
||||
virtual RID _multimesh_get_command_buffer_rd_rid(RID p_multimesh) const override;
|
||||
virtual RID _multimesh_get_buffer_rd_rid(RID p_multimesh) const override;
|
||||
virtual Vector<float> _multimesh_get_buffer(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
|
||||
virtual int multimesh_get_visible_instances(RID p_multimesh) const override;
|
||||
virtual void _multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
|
||||
virtual int _multimesh_get_visible_instances(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_custom_aabb(RID p_multimesh, const AABB &p_aabb) override;
|
||||
virtual AABB multimesh_get_custom_aabb(RID p_multimesh) const override;
|
||||
virtual void _multimesh_set_custom_aabb(RID p_multimesh, const AABB &p_aabb) override;
|
||||
virtual AABB _multimesh_get_custom_aabb(RID p_multimesh) const override;
|
||||
|
||||
virtual AABB multimesh_get_aabb(RID p_multimesh) const override;
|
||||
virtual AABB _multimesh_get_aabb(RID p_multimesh) override;
|
||||
|
||||
virtual MultiMeshInterpolator *_multimesh_get_interpolator(RID p_multimesh) const override;
|
||||
|
||||
void _update_dirty_multimeshes();
|
||||
void _multimesh_get_motion_vectors_offsets(RID p_multimesh, uint32_t &r_current_offset, uint32_t &r_prev_offset);
|
||||
bool _multimesh_uses_motion_vectors_offsets(RID p_multimesh);
|
||||
bool _multimesh_uses_motion_vectors(RID p_multimesh);
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_indirect(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->indirect;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->xform_format;
|
||||
|
|
@ -726,7 +753,7 @@ public:
|
|||
|
||||
/* SKELETON API */
|
||||
|
||||
bool owns_skeleton(RID p_rid) const { return skeleton_owner.owns(p_rid); };
|
||||
bool owns_skeleton(RID p_rid) const { return skeleton_owner.owns(p_rid); }
|
||||
|
||||
virtual RID skeleton_allocate() override;
|
||||
virtual void skeleton_initialize(RID p_skeleton) override;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ ParticlesStorage::ParticlesStorage() {
|
|||
|
||||
actions.renames["COLOR"] = "PARTICLE.color";
|
||||
actions.renames["VELOCITY"] = "PARTICLE.velocity";
|
||||
//actions.renames["MASS"] = "mass"; ?
|
||||
actions.renames["MASS"] = "mass";
|
||||
actions.renames["ACTIVE"] = "particle_active";
|
||||
actions.renames["RESTART"] = "restart";
|
||||
actions.renames["CUSTOM"] = "PARTICLE.custom";
|
||||
|
|
@ -155,7 +155,7 @@ void process() {
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(material_storage->samplers_rd_get_default().get_uniforms(SAMPLERS_BINDING_FIRST_INDEX));
|
||||
material_storage->samplers_rd_get_default().append_uniforms(uniforms, SAMPLERS_BINDING_FIRST_INDEX);
|
||||
|
||||
particles_shader.base_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, particles_shader.default_shader_rd, BASE_UNIFORM_SET);
|
||||
}
|
||||
|
|
@ -306,9 +306,14 @@ void ParticlesStorage::_particles_free_data(Particles *particles) {
|
|||
particles->emission_storage_buffer = RID();
|
||||
}
|
||||
|
||||
if (particles->unused_storage_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(particles->unused_storage_buffer);
|
||||
particles->unused_storage_buffer = RID();
|
||||
if (particles->unused_emission_storage_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(particles->unused_emission_storage_buffer);
|
||||
particles->unused_emission_storage_buffer = RID();
|
||||
}
|
||||
|
||||
if (particles->unused_trail_storage_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(particles->unused_trail_storage_buffer);
|
||||
particles->unused_trail_storage_buffer = RID();
|
||||
}
|
||||
|
||||
if (RD::get_singleton()->uniform_set_is_valid(particles->particles_material_uniform_set)) {
|
||||
|
|
@ -362,6 +367,13 @@ void ParticlesStorage::particles_set_pre_process_time(RID p_particles, double p_
|
|||
ERR_FAIL_NULL(particles);
|
||||
particles->pre_process_time = p_time;
|
||||
}
|
||||
|
||||
void ParticlesStorage::particles_request_process_time(RID p_particles, real_t p_request_process_time) {
|
||||
Particles *particles = particles_owner.get_or_null(p_particles);
|
||||
ERR_FAIL_NULL(particles);
|
||||
particles->request_process_time = p_request_process_time;
|
||||
}
|
||||
|
||||
void ParticlesStorage::particles_set_explosiveness_ratio(RID p_particles, real_t p_ratio) {
|
||||
Particles *particles = particles_owner.get_or_null(p_particles);
|
||||
ERR_FAIL_NULL(particles);
|
||||
|
|
@ -517,6 +529,12 @@ void ParticlesStorage::particles_restart(RID p_particles) {
|
|||
particles->restart_request = true;
|
||||
}
|
||||
|
||||
void ParticlesStorage::particles_set_seed(RID p_particles, uint32_t p_seed) {
|
||||
Particles *particles = particles_owner.get_or_null(p_particles);
|
||||
ERR_FAIL_NULL(particles);
|
||||
particles->random_seed = p_seed;
|
||||
}
|
||||
|
||||
void ParticlesStorage::_particles_allocate_emission_buffer(Particles *particles) {
|
||||
ERR_FAIL_COND(particles->emission_buffer != nullptr);
|
||||
|
||||
|
|
@ -534,9 +552,17 @@ void ParticlesStorage::_particles_allocate_emission_buffer(Particles *particles)
|
|||
}
|
||||
}
|
||||
|
||||
void ParticlesStorage::_particles_ensure_unused_buffer(Particles *particles) {
|
||||
if (particles->unused_storage_buffer.is_null()) {
|
||||
particles->unused_storage_buffer = RD::get_singleton()->storage_buffer_create(sizeof(uint32_t) * 4);
|
||||
void ParticlesStorage::_particles_ensure_unused_emission_buffer(Particles *particles) {
|
||||
if (particles->unused_emission_storage_buffer.is_null()) {
|
||||
// For rendering devices that do not support empty arrays (like C++),
|
||||
// we need to size the buffer with at least 1 element.
|
||||
particles->unused_emission_storage_buffer = RD::get_singleton()->storage_buffer_create(sizeof(ParticleEmissionBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
void ParticlesStorage::_particles_ensure_unused_trail_buffer(Particles *particles) {
|
||||
if (particles->unused_trail_storage_buffer.is_null()) {
|
||||
particles->unused_trail_storage_buffer = RD::get_singleton()->storage_buffer_create(16 * sizeof(float)); // Size of mat4.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -763,8 +789,8 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta
|
|||
if (p_particles->emission_storage_buffer.is_valid()) {
|
||||
u.append_id(p_particles->emission_storage_buffer);
|
||||
} else {
|
||||
_particles_ensure_unused_buffer(p_particles);
|
||||
u.append_id(p_particles->unused_storage_buffer);
|
||||
_particles_ensure_unused_emission_buffer(p_particles);
|
||||
u.append_id(p_particles->unused_emission_storage_buffer);
|
||||
}
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
|
@ -779,8 +805,8 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta
|
|||
}
|
||||
u.append_id(sub_emitter->emission_storage_buffer);
|
||||
} else {
|
||||
_particles_ensure_unused_buffer(p_particles);
|
||||
u.append_id(p_particles->unused_storage_buffer);
|
||||
_particles_ensure_unused_emission_buffer(p_particles);
|
||||
u.append_id(p_particles->unused_emission_storage_buffer);
|
||||
}
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
|
@ -799,7 +825,6 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta
|
|||
|
||||
if (p_particles->clear) {
|
||||
p_particles->cycle_number = 0;
|
||||
p_particles->random_seed = Math::rand();
|
||||
} else if (new_phase < p_particles->phase) {
|
||||
if (p_particles->one_shot) {
|
||||
p_particles->emitting = false;
|
||||
|
|
@ -1300,10 +1325,11 @@ void ParticlesStorage::particles_set_view_axis(RID p_particles, const Vector3 &p
|
|||
void ParticlesStorage::_particles_update_buffers(Particles *particles) {
|
||||
uint32_t userdata_count = 0;
|
||||
|
||||
MaterialStorage::ShaderData *shader_data = MaterialStorage::get_singleton()->material_get_shader_data(particles->process_material);
|
||||
if (shader_data) {
|
||||
const ParticlesShaderData *particle_shader_data = static_cast<const ParticlesShaderData *>(shader_data);
|
||||
userdata_count = particle_shader_data->userdata_count;
|
||||
if (particles->process_material.is_valid()) {
|
||||
ParticleProcessMaterialData *material_data = static_cast<ParticleProcessMaterialData *>(MaterialStorage::get_singleton()->material_get_data(particles->process_material, MaterialStorage::SHADER_TYPE_PARTICLES));
|
||||
if (material_data && material_data->shader_data->version.is_valid() && material_data->shader_data->valid) {
|
||||
userdata_count = material_data->shader_data->userdata_count;
|
||||
}
|
||||
}
|
||||
|
||||
bool uses_motion_vectors = RSG::viewport->get_num_viewports_with_motion_vectors() > 0 || (RendererCompositorStorage::get_singleton()->get_num_compositor_effects_with_motion_vectors() > 0);
|
||||
|
|
@ -1481,8 +1507,8 @@ void ParticlesStorage::update_particles() {
|
|||
if (particles->trail_bind_pose_buffer.is_valid()) {
|
||||
u.append_id(particles->trail_bind_pose_buffer);
|
||||
} else {
|
||||
_particles_ensure_unused_buffer(particles);
|
||||
u.append_id(particles->unused_storage_buffer);
|
||||
_particles_ensure_unused_trail_buffer(particles);
|
||||
u.append_id(particles->unused_trail_storage_buffer);
|
||||
}
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
|
@ -1504,8 +1530,12 @@ void ParticlesStorage::update_particles() {
|
|||
}
|
||||
|
||||
bool zero_time_scale = Engine::get_singleton()->get_time_scale() <= 0.0;
|
||||
double todo = particles->request_process_time;
|
||||
if (particles->clear) {
|
||||
todo += particles->pre_process_time;
|
||||
}
|
||||
|
||||
if (particles->clear && particles->pre_process_time > 0.0) {
|
||||
if (todo > 0.0) {
|
||||
double frame_time;
|
||||
if (fixed_fps > 0) {
|
||||
frame_time = 1.0 / fixed_fps;
|
||||
|
|
@ -1513,12 +1543,15 @@ void ParticlesStorage::update_particles() {
|
|||
frame_time = 1.0 / 30.0;
|
||||
}
|
||||
|
||||
double todo = particles->pre_process_time;
|
||||
|
||||
float tmp_scale = particles->speed_scale;
|
||||
// We need this otherwise the speed scale of the particle system influences the TODO.
|
||||
particles->speed_scale = 1.0;
|
||||
while (todo >= 0) {
|
||||
_particles_process(particles, frame_time);
|
||||
todo -= frame_time;
|
||||
}
|
||||
particles->request_process_time = 0.0;
|
||||
particles->speed_scale = tmp_scale;
|
||||
}
|
||||
|
||||
if (fixed_fps > 0) {
|
||||
|
|
@ -1537,7 +1570,7 @@ void ParticlesStorage::update_particles() {
|
|||
} else if (delta <= 0.0) { //unlikely but..
|
||||
delta = 0.001;
|
||||
}
|
||||
double todo = particles->frame_remainder + delta;
|
||||
todo = particles->frame_remainder + delta;
|
||||
|
||||
while (todo >= frame_time || particles->clear) {
|
||||
_particles_process(particles, frame_time);
|
||||
|
|
@ -1825,6 +1858,18 @@ void ParticlesStorage::particles_collision_set_cull_mask(RID p_particles_collisi
|
|||
particles_collision->cull_mask = p_cull_mask;
|
||||
}
|
||||
|
||||
uint32_t ParticlesStorage::particles_collision_get_height_field_mask(RID p_particles_collision) const {
|
||||
const ParticlesCollision *particles_collision = particles_collision_owner.get_or_null(p_particles_collision);
|
||||
ERR_FAIL_NULL_V(particles_collision, false);
|
||||
return particles_collision->heightfield_mask;
|
||||
}
|
||||
|
||||
void ParticlesStorage::particles_collision_set_height_field_mask(RID p_particles_collision, uint32_t p_heightfield_mask) {
|
||||
ParticlesCollision *particles_collision = particles_collision_owner.get_or_null(p_particles_collision);
|
||||
ERR_FAIL_NULL(particles_collision);
|
||||
particles_collision->heightfield_mask = p_heightfield_mask;
|
||||
}
|
||||
|
||||
void ParticlesStorage::particles_collision_set_sphere_radius(RID p_particles_collision, real_t p_radius) {
|
||||
ParticlesCollision *particles_collision = particles_collision_owner.get_or_null(p_particles_collision);
|
||||
ERR_FAIL_NULL(particles_collision);
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ private:
|
|||
int amount = 0;
|
||||
double lifetime = 1.0;
|
||||
double pre_process_time = 0.0;
|
||||
real_t request_process_time = 0.0;
|
||||
real_t explosiveness = 0.0;
|
||||
real_t randomness = 0.0;
|
||||
bool restart_request = false;
|
||||
|
|
@ -247,7 +248,8 @@ private:
|
|||
ParticleEmissionBuffer *emission_buffer = nullptr;
|
||||
RID emission_storage_buffer;
|
||||
|
||||
RID unused_storage_buffer;
|
||||
RID unused_emission_storage_buffer;
|
||||
RID unused_trail_storage_buffer;
|
||||
|
||||
HashSet<RID> collisions;
|
||||
|
||||
|
|
@ -260,12 +262,14 @@ private:
|
|||
|
||||
Particles() :
|
||||
update_list(this) {
|
||||
random_seed = Math::rand();
|
||||
}
|
||||
};
|
||||
|
||||
void _particles_process(Particles *p_particles, double p_delta);
|
||||
void _particles_allocate_emission_buffer(Particles *particles);
|
||||
void _particles_ensure_unused_buffer(Particles *particles);
|
||||
void _particles_ensure_unused_emission_buffer(Particles *particles);
|
||||
void _particles_ensure_unused_trail_buffer(Particles *particles);
|
||||
void _particles_free_data(Particles *particles);
|
||||
void _particles_update_buffers(Particles *particles);
|
||||
|
||||
|
|
@ -400,6 +404,7 @@ private:
|
|||
RID heightfield_texture;
|
||||
RID heightfield_fb;
|
||||
Size2i heightfield_fb_size;
|
||||
uint32_t heightfield_mask = (1 << 20) - 1;
|
||||
|
||||
RS::ParticlesCollisionHeightfieldResolution heightfield_resolution = RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024;
|
||||
|
||||
|
|
@ -439,6 +444,7 @@ public:
|
|||
virtual void particles_set_lifetime(RID p_particles, double p_lifetime) override;
|
||||
virtual void particles_set_one_shot(RID p_particles, bool p_one_shot) override;
|
||||
virtual void particles_set_pre_process_time(RID p_particles, double p_time) override;
|
||||
virtual void particles_request_process_time(RID p_particles, real_t p_request_process_time) override;
|
||||
virtual void particles_set_explosiveness_ratio(RID p_particles, real_t p_ratio) override;
|
||||
virtual void particles_set_randomness_ratio(RID p_particles, real_t p_ratio) override;
|
||||
virtual void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb) override;
|
||||
|
|
@ -452,6 +458,7 @@ public:
|
|||
virtual void particles_set_fractional_delta(RID p_particles, bool p_enable) override;
|
||||
virtual void particles_set_collision_base_size(RID p_particles, real_t p_size) override;
|
||||
virtual void particles_set_transform_align(RID p_particles, RS::ParticlesTransformAlign p_transform_align) override;
|
||||
virtual void particles_set_seed(RID p_particles, uint32_t p_seed) override;
|
||||
|
||||
virtual void particles_set_trails(RID p_particles, bool p_enable, double p_length) override;
|
||||
virtual void particles_set_trail_bind_poses(RID p_particles, const Vector<Transform3D> &p_bind_poses) override;
|
||||
|
|
@ -509,7 +516,7 @@ public:
|
|||
|
||||
_FORCE_INLINE_ bool particles_has_collision(RID p_particles) {
|
||||
Particles *particles = particles_owner.get_or_null(p_particles);
|
||||
ERR_FAIL_NULL_V(particles, 0);
|
||||
ERR_FAIL_NULL_V(particles, false);
|
||||
|
||||
return particles->has_collision_cache;
|
||||
}
|
||||
|
|
@ -575,6 +582,8 @@ public:
|
|||
Vector3 particles_collision_get_extents(RID p_particles_collision) const;
|
||||
virtual bool particles_collision_is_heightfield(RID p_particles_collision) const override;
|
||||
RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const;
|
||||
virtual uint32_t particles_collision_get_height_field_mask(RID p_particles_collision) const override;
|
||||
virtual void particles_collision_set_height_field_mask(RID p_particles_collision, uint32_t p_heightfield_mask) override;
|
||||
|
||||
Dependency *particles_collision_get_dependency(RID p_particles) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,6 @@
|
|||
|
||||
#include "render_data_rd.h"
|
||||
|
||||
void RenderDataRD::_bind_methods() {
|
||||
}
|
||||
|
||||
Ref<RenderSceneBuffers> RenderDataRD::get_render_scene_buffers() const {
|
||||
return render_buffers;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,6 @@
|
|||
class RenderDataRD : public RenderData {
|
||||
GDCLASS(RenderDataRD, RenderData);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
// Access methods to expose data externally
|
||||
virtual Ref<RenderSceneBuffers> get_render_scene_buffers() const override;
|
||||
|
|
@ -76,10 +73,13 @@ public:
|
|||
uint32_t directional_light_count = 0;
|
||||
bool directional_light_soft_shadows = false;
|
||||
|
||||
bool lightmap_bicubic_filter = false;
|
||||
|
||||
RenderingMethod::RenderInfo *render_info = nullptr;
|
||||
|
||||
/* Viewport data */
|
||||
bool transparent_bg = false;
|
||||
Rect2i render_region;
|
||||
|
||||
/* Shadow data */
|
||||
const RendererSceneRender::RenderShadowData *render_shadows = nullptr;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,10 @@ RID RenderSceneBuffersRD::_get_velocity_layer_compat_80214(const uint32_t p_laye
|
|||
return _get_velocity_layer(p_layer, msaa_3d != RS::VIEWPORT_MSAA_DISABLED);
|
||||
}
|
||||
|
||||
RID RenderSceneBuffersRD::_create_texture_bind_compat_98670(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples, const Size2i p_size, const uint32_t p_layers, const uint32_t p_mipmaps, bool p_unique) {
|
||||
return create_texture(p_context, p_texture_name, p_data_format, p_usage_bits, p_texture_samples, p_size, p_layers, p_mipmaps, p_unique, false);
|
||||
}
|
||||
|
||||
void RenderSceneBuffersRD::_bind_compatibility_methods() {
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_color_texture"), &RenderSceneBuffersRD::_get_color_texture_compat_80214);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_color_layer", "layer"), &RenderSceneBuffersRD::_get_color_layer_compat_80214);
|
||||
|
|
@ -61,6 +65,8 @@ void RenderSceneBuffersRD::_bind_compatibility_methods() {
|
|||
ClassDB::bind_compatibility_method(D_METHOD("get_depth_layer", "layer"), &RenderSceneBuffersRD::_get_depth_layer_compat_80214);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_velocity_texture"), &RenderSceneBuffersRD::_get_velocity_texture_compat_80214);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_velocity_layer", "layer"), &RenderSceneBuffersRD::_get_velocity_layer_compat_80214);
|
||||
|
||||
ClassDB::bind_compatibility_method(D_METHOD("create_texture", "context", "name", "data_format", "usage_bits", "texture_samples", "size", "layers", "mipmaps", "unique"), &RenderSceneBuffersRD::_create_texture_bind_compat_98670);
|
||||
}
|
||||
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
#include "render_scene_buffers_rd.h"
|
||||
#include "render_scene_buffers_rd.compat.inc"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "servers/rendering/renderer_rd/renderer_scene_render_rd.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
|
||||
|
||||
RenderSceneBuffersRD::RenderSceneBuffersRD() {
|
||||
|
|
@ -48,7 +46,7 @@ RenderSceneBuffersRD::~RenderSceneBuffersRD() {
|
|||
|
||||
void RenderSceneBuffersRD::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("has_texture", "context", "name"), &RenderSceneBuffersRD::has_texture);
|
||||
ClassDB::bind_method(D_METHOD("create_texture", "context", "name", "data_format", "usage_bits", "texture_samples", "size", "layers", "mipmaps", "unique"), &RenderSceneBuffersRD::create_texture);
|
||||
ClassDB::bind_method(D_METHOD("create_texture", "context", "name", "data_format", "usage_bits", "texture_samples", "size", "layers", "mipmaps", "unique", "discardable"), &RenderSceneBuffersRD::create_texture);
|
||||
ClassDB::bind_method(D_METHOD("create_texture_from_format", "context", "name", "format", "view", "unique"), &RenderSceneBuffersRD::_create_texture_from_format);
|
||||
ClassDB::bind_method(D_METHOD("create_texture_view", "context", "name", "view_name", "view"), &RenderSceneBuffersRD::_create_texture_view);
|
||||
ClassDB::bind_method(D_METHOD("get_texture", "context", "name"), &RenderSceneBuffersRD::get_texture);
|
||||
|
|
@ -104,7 +102,7 @@ void RenderSceneBuffersRD::free_named_texture(NamedTexture &p_named_texture) {
|
|||
void RenderSceneBuffersRD::update_samplers() {
|
||||
float computed_mipmap_bias = texture_mipmap_bias;
|
||||
|
||||
if (use_taa || (scaling_3d_mode == RS::VIEWPORT_SCALING_3D_MODE_FSR2)) {
|
||||
if (use_taa || (RS::scaling_3d_mode_type(scaling_3d_mode) == RS::VIEWPORT_SCALING_3D_TYPE_TEMPORAL)) {
|
||||
// Use negative mipmap LOD bias when TAA or FSR2 is enabled to compensate for loss of sharpness.
|
||||
// This restores sharpness in still images to be roughly at the same level as without TAA,
|
||||
// but moving scenes will still be blurrier.
|
||||
|
|
@ -119,7 +117,7 @@ void RenderSceneBuffersRD::update_samplers() {
|
|||
|
||||
RendererRD::MaterialStorage *material_storage = RendererRD::MaterialStorage::get_singleton();
|
||||
material_storage->samplers_rd_free(samplers);
|
||||
samplers = material_storage->samplers_rd_allocate(computed_mipmap_bias);
|
||||
samplers = material_storage->samplers_rd_allocate(computed_mipmap_bias, anisotropic_filtering_level);
|
||||
}
|
||||
|
||||
void RenderSceneBuffersRD::cleanup() {
|
||||
|
|
@ -141,6 +139,13 @@ void RenderSceneBuffersRD::cleanup() {
|
|||
weight_buffer.weight = RID();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef METAL_ENABLED
|
||||
if (mfx_spatial_context) {
|
||||
memdelete(mfx_spatial_context);
|
||||
mfx_spatial_context = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_config) {
|
||||
|
|
@ -157,6 +162,7 @@ void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_co
|
|||
|
||||
fsr_sharpness = p_config->get_fsr_sharpness();
|
||||
texture_mipmap_bias = p_config->get_texture_mipmap_bias();
|
||||
anisotropic_filtering_level = p_config->get_anisotropic_filtering_level();
|
||||
use_taa = p_config->get_use_taa();
|
||||
use_debanding = p_config->get_use_debanding();
|
||||
|
||||
|
|
@ -167,76 +173,30 @@ void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_co
|
|||
// cleanout any old buffers we had.
|
||||
cleanup();
|
||||
|
||||
// At least one of these is required to be supported.
|
||||
RenderingDeviceCommons::DataFormat preferred_format[2] = { RD::DATA_FORMAT_D24_UNORM_S8_UINT, RD::DATA_FORMAT_D32_SFLOAT_S8_UINT };
|
||||
if (can_be_storage) {
|
||||
// Prefer higher precision on desktop.
|
||||
preferred_format[0] = RD::DATA_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
preferred_format[1] = RD::DATA_FORMAT_D24_UNORM_S8_UINT;
|
||||
}
|
||||
// Create our color buffer.
|
||||
const bool resolve_target = msaa_3d != RS::VIEWPORT_MSAA_DISABLED;
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR, base_data_format, get_color_usage_bits(resolve_target, false, can_be_storage));
|
||||
|
||||
// create our 3D render buffers
|
||||
{
|
||||
// Create our color buffer(s)
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | (can_be_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0) | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
usage_bits |= RD::TEXTURE_USAGE_INPUT_ATTACHMENT_BIT; // only needed when using subpasses in the mobile renderer
|
||||
// TODO: Detect when it is safe to use RD::TEXTURE_USAGE_TRANSIENT_BIT for RB_TEX_DEPTH, RB_TEX_COLOR_MSAA and/or RB_TEX_DEPTH_MSAA.
|
||||
// (it means we cannot sample from it, we cannot copy from/to it) to save VRAM (and maybe performance too).
|
||||
|
||||
// our internal texture should have MSAA support if applicable
|
||||
if (msaa_3d != RS::VIEWPORT_MSAA_DISABLED) {
|
||||
usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT;
|
||||
}
|
||||
// Create our depth buffer.
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH, get_depth_format(resolve_target, false, can_be_storage), get_depth_usage_bits(resolve_target, false, can_be_storage));
|
||||
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR, base_data_format, usage_bits);
|
||||
}
|
||||
|
||||
// Create our depth buffer
|
||||
{
|
||||
// TODO Lazy create this in case we've got an external depth buffer
|
||||
|
||||
RD::DataFormat format;
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
|
||||
if (msaa_3d == RS::VIEWPORT_MSAA_DISABLED) {
|
||||
usage_bits |= RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
format = RD::get_singleton()->texture_is_format_supported_for_usage(preferred_format[0], usage_bits) ? preferred_format[0] : preferred_format[1];
|
||||
} else {
|
||||
format = RD::DATA_FORMAT_R32_SFLOAT;
|
||||
usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT | (can_be_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0);
|
||||
}
|
||||
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH, format, usage_bits);
|
||||
}
|
||||
|
||||
// Create our MSAA buffers
|
||||
// Create our MSAA buffers.
|
||||
if (msaa_3d == RS::VIEWPORT_MSAA_DISABLED) {
|
||||
texture_samples = RD::TEXTURE_SAMPLES_1;
|
||||
} else {
|
||||
RD::DataFormat format = base_data_format;
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
|
||||
const RD::TextureSamples ts[RS::VIEWPORT_MSAA_MAX] = {
|
||||
RD::TEXTURE_SAMPLES_1,
|
||||
RD::TEXTURE_SAMPLES_2,
|
||||
RD::TEXTURE_SAMPLES_4,
|
||||
RD::TEXTURE_SAMPLES_8,
|
||||
};
|
||||
|
||||
texture_samples = ts[msaa_3d];
|
||||
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR_MSAA, format, usage_bits, texture_samples);
|
||||
|
||||
usage_bits = RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
format = RD::get_singleton()->texture_is_format_supported_for_usage(preferred_format[0], usage_bits) ? preferred_format[0] : preferred_format[1];
|
||||
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH_MSAA, format, usage_bits, texture_samples);
|
||||
texture_samples = msaa_to_samples(msaa_3d);
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR_MSAA, base_data_format, get_color_usage_bits(false, true, can_be_storage), texture_samples, Size2i(), 0, 1, true, true);
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH_MSAA, get_depth_format(false, true, can_be_storage), get_depth_usage_bits(false, true, can_be_storage), texture_samples, Size2i(), 0, 1, true, true);
|
||||
}
|
||||
|
||||
// VRS (note, our vrs object will only be set if VRS is supported)
|
||||
RID vrs_texture;
|
||||
RS::ViewportVRSMode vrs_mode = texture_storage->render_target_get_vrs_mode(render_target);
|
||||
if (vrs && vrs_mode != RS::VIEWPORT_VRS_DISABLED) {
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_VRS_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
|
||||
vrs_texture = create_texture(RB_SCOPE_VRS, RB_TEXTURE, RD::DATA_FORMAT_R8_UINT, usage_bits, RD::TEXTURE_SAMPLES_1, vrs->get_vrs_texture_size(internal_size));
|
||||
vrs_texture = create_texture(RB_SCOPE_VRS, RB_TEXTURE, get_vrs_format(), get_vrs_usage_bits(), RD::TEXTURE_SAMPLES_1, vrs->get_vrs_texture_size(internal_size));
|
||||
}
|
||||
|
||||
// (re-)configure any named buffers
|
||||
|
|
@ -279,10 +239,32 @@ void RenderSceneBuffersRD::set_texture_mipmap_bias(float p_texture_mipmap_bias)
|
|||
update_samplers();
|
||||
}
|
||||
|
||||
void RenderSceneBuffersRD::set_anisotropic_filtering_level(RS::ViewportAnisotropicFiltering p_anisotropic_filtering_level) {
|
||||
anisotropic_filtering_level = p_anisotropic_filtering_level;
|
||||
|
||||
update_samplers();
|
||||
}
|
||||
|
||||
void RenderSceneBuffersRD::set_use_debanding(bool p_use_debanding) {
|
||||
use_debanding = p_use_debanding;
|
||||
}
|
||||
|
||||
#ifdef METAL_ENABLED
|
||||
void RenderSceneBuffersRD::ensure_mfx(RendererRD::MFXSpatialEffect *p_effect) {
|
||||
if (mfx_spatial_context) {
|
||||
return;
|
||||
}
|
||||
RendererRD::MFXSpatialEffect::CreateParams params = {
|
||||
.input_size = internal_size,
|
||||
.output_size = target_size,
|
||||
.input_format = base_data_format,
|
||||
.output_format = RD::DATA_FORMAT_R8G8B8A8_UNORM,
|
||||
};
|
||||
|
||||
mfx_spatial_context = p_effect->create_context(params);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Named textures
|
||||
|
||||
bool RenderSceneBuffersRD::has_texture(const StringName &p_context, const StringName &p_texture_name) const {
|
||||
|
|
@ -291,7 +273,7 @@ bool RenderSceneBuffersRD::has_texture(const StringName &p_context, const String
|
|||
return named_textures.has(key);
|
||||
}
|
||||
|
||||
RID RenderSceneBuffersRD::create_texture(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples, const Size2i p_size, const uint32_t p_layers, const uint32_t p_mipmaps, bool p_unique) {
|
||||
RID RenderSceneBuffersRD::create_texture(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples, const Size2i p_size, const uint32_t p_layers, const uint32_t p_mipmaps, bool p_unique, bool p_discardable) {
|
||||
// Keep some useful data, we use default values when these are 0.
|
||||
Size2i size = p_size == Size2i(0, 0) ? internal_size : p_size;
|
||||
uint32_t layers = p_layers == 0 ? view_count : p_layers;
|
||||
|
|
@ -311,6 +293,7 @@ RID RenderSceneBuffersRD::create_texture(const StringName &p_context, const Stri
|
|||
tf.mipmaps = mipmaps;
|
||||
tf.usage_bits = p_usage_bits;
|
||||
tf.samples = p_texture_samples;
|
||||
tf.is_discardable = p_discardable;
|
||||
|
||||
return create_texture_from_format(p_context, p_texture_name, tf, RD::TextureView(), p_unique);
|
||||
}
|
||||
|
|
@ -521,7 +504,7 @@ void RenderSceneBuffersRD::allocate_blur_textures() {
|
|||
}
|
||||
|
||||
Size2i blur_size = internal_size;
|
||||
if (scaling_3d_mode == RS::VIEWPORT_SCALING_3D_MODE_FSR2) {
|
||||
if (RS::scaling_3d_mode_type(scaling_3d_mode) == RS::VIEWPORT_SCALING_3D_TYPE_TEMPORAL) {
|
||||
// The blur texture should be as big as the target size when using an upscaler.
|
||||
blur_size = target_size;
|
||||
}
|
||||
|
|
@ -664,16 +647,12 @@ void RenderSceneBuffersRD::ensure_upscaled() {
|
|||
|
||||
void RenderSceneBuffersRD::ensure_velocity() {
|
||||
if (!has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY)) {
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
|
||||
const bool msaa = msaa_3d != RS::VIEWPORT_MSAA_DISABLED;
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY, get_velocity_format(), get_velocity_usage_bits(msaa, false, can_be_storage));
|
||||
|
||||
if (msaa_3d != RS::VIEWPORT_MSAA_DISABLED) {
|
||||
uint32_t msaa_usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT;
|
||||
usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT;
|
||||
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA, RD::DATA_FORMAT_R16G16_SFLOAT, msaa_usage_bits, texture_samples);
|
||||
if (msaa) {
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA, get_velocity_format(), get_velocity_usage_bits(false, msaa, can_be_storage), texture_samples);
|
||||
}
|
||||
|
||||
create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY, RD::DATA_FORMAT_R16G16_SFLOAT, usage_bits);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -724,3 +703,62 @@ RID RenderSceneBuffersRD::get_velocity_buffer(bool p_get_msaa, uint32_t p_layer)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t RenderSceneBuffersRD::get_color_usage_bits(bool p_resolve, bool p_msaa, bool p_storage) {
|
||||
DEV_ASSERT((!p_resolve && !p_msaa) || (p_resolve != p_msaa));
|
||||
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||
if (p_msaa) {
|
||||
usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT;
|
||||
} else if (p_resolve) {
|
||||
usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT | (p_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0);
|
||||
} else {
|
||||
usage_bits |= (p_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0);
|
||||
}
|
||||
|
||||
return usage_bits;
|
||||
}
|
||||
|
||||
RD::DataFormat RenderSceneBuffersRD::get_depth_format(bool p_resolve, bool p_msaa, bool p_storage) {
|
||||
if (p_resolve) {
|
||||
return RD::DATA_FORMAT_R32_SFLOAT;
|
||||
} else {
|
||||
const RenderingDeviceCommons::DataFormat preferred_formats[2] = {
|
||||
p_storage ? RD::DATA_FORMAT_D32_SFLOAT_S8_UINT : RD::DATA_FORMAT_D24_UNORM_S8_UINT,
|
||||
p_storage ? RD::DATA_FORMAT_D24_UNORM_S8_UINT : RD::DATA_FORMAT_D32_SFLOAT_S8_UINT
|
||||
};
|
||||
|
||||
return RD::get_singleton()->texture_is_format_supported_for_usage(preferred_formats[0], get_depth_usage_bits(p_resolve, p_msaa, p_storage)) ? preferred_formats[0] : preferred_formats[1];
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t RenderSceneBuffersRD::get_depth_usage_bits(bool p_resolve, bool p_msaa, bool p_storage) {
|
||||
DEV_ASSERT((!p_resolve && !p_msaa) || (p_resolve != p_msaa));
|
||||
|
||||
uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
if (p_msaa) {
|
||||
usage_bits |= RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT;
|
||||
} else if (p_resolve) {
|
||||
usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT | (p_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0);
|
||||
} else {
|
||||
usage_bits |= RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
}
|
||||
|
||||
return usage_bits;
|
||||
}
|
||||
|
||||
RD::DataFormat RenderSceneBuffersRD::get_velocity_format() {
|
||||
return RD::DATA_FORMAT_R16G16_SFLOAT;
|
||||
}
|
||||
|
||||
uint32_t RenderSceneBuffersRD::get_velocity_usage_bits(bool p_resolve, bool p_msaa, bool p_storage) {
|
||||
return get_color_usage_bits(p_resolve, p_msaa, p_storage);
|
||||
}
|
||||
|
||||
RD::DataFormat RenderSceneBuffersRD::get_vrs_format() {
|
||||
return RD::DATA_FORMAT_R8_UINT;
|
||||
}
|
||||
|
||||
uint32_t RenderSceneBuffersRD::get_vrs_usage_bits() {
|
||||
return RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_VRS_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@
|
|||
#ifndef RENDER_SCENE_BUFFERS_RD_H
|
||||
#define RENDER_SCENE_BUFFERS_RD_H
|
||||
|
||||
#include "../effects/fsr2.h"
|
||||
#ifdef METAL_ENABLED
|
||||
#include "../effects/metal_fx.h"
|
||||
#endif
|
||||
#include "../effects/vrs.h"
|
||||
#include "../framebuffer_cache_rd.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "material_storage.h"
|
||||
#include "render_buffer_custom_data_rd.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
#include "servers/rendering/rendering_device_binds.h"
|
||||
#include "servers/rendering/rendering_method.h"
|
||||
#include "servers/rendering/storage/render_scene_buffers.h"
|
||||
|
||||
#define RB_SCOPE_BUFFERS SNAME("render_buffers")
|
||||
|
|
@ -81,8 +81,13 @@ private:
|
|||
RS::ViewportScaling3DMode scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_OFF;
|
||||
float fsr_sharpness = 0.2f;
|
||||
float texture_mipmap_bias = 0.0f;
|
||||
RS::ViewportAnisotropicFiltering anisotropic_filtering_level = RS::VIEWPORT_ANISOTROPY_4X;
|
||||
|
||||
// Aliassing settings
|
||||
#ifdef METAL_ENABLED
|
||||
RendererRD::MFXSpatialContext *mfx_spatial_context = nullptr;
|
||||
#endif
|
||||
|
||||
// Aliasing settings
|
||||
RS::ViewportMSAA msaa_3d = RS::VIEWPORT_MSAA_DISABLED;
|
||||
RS::ViewportScreenSpaceAA screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED;
|
||||
bool use_taa = false;
|
||||
|
|
@ -128,7 +133,7 @@ private:
|
|||
h = hash_murmur3_one_32(p_val.layers, h);
|
||||
h = hash_murmur3_one_32(p_val.mipmap, h);
|
||||
h = hash_murmur3_one_32(p_val.mipmaps, h);
|
||||
h = hash_murmur3_one_32(p_val.texture_view.format_override);
|
||||
h = hash_murmur3_one_32(p_val.texture_view.format_override, h);
|
||||
h = hash_murmur3_one_32(p_val.texture_view.swizzle_r, h);
|
||||
h = hash_murmur3_one_32(p_val.texture_view.swizzle_g, h);
|
||||
h = hash_murmur3_one_32(p_val.texture_view.swizzle_b, h);
|
||||
|
|
@ -178,6 +183,7 @@ public:
|
|||
|
||||
// info from our renderer
|
||||
void set_can_be_storage(const bool p_can_be_storage) { can_be_storage = p_can_be_storage; }
|
||||
bool get_can_be_storage() const { return can_be_storage; }
|
||||
void set_max_cluster_elements(const uint32_t p_max_elements) { max_cluster_elements = p_max_elements; }
|
||||
uint32_t get_max_cluster_elements() { return max_cluster_elements; }
|
||||
void set_base_data_format(const RD::DataFormat p_base_data_format) { base_data_format = p_base_data_format; }
|
||||
|
|
@ -189,12 +195,18 @@ public:
|
|||
void configure_for_reflections(const Size2i p_reflection_size);
|
||||
virtual void set_fsr_sharpness(float p_fsr_sharpness) override;
|
||||
virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override;
|
||||
virtual void set_anisotropic_filtering_level(RS::ViewportAnisotropicFiltering p_anisotropic_filtering_level) override;
|
||||
virtual void set_use_debanding(bool p_use_debanding) override;
|
||||
|
||||
#ifdef METAL_ENABLED
|
||||
void ensure_mfx(RendererRD::MFXSpatialEffect *p_effect);
|
||||
_FORCE_INLINE_ RendererRD::MFXSpatialContext *get_mfx_spatial_context() const { return mfx_spatial_context; }
|
||||
#endif
|
||||
|
||||
// Named Textures
|
||||
|
||||
bool has_texture(const StringName &p_context, const StringName &p_texture_name) const;
|
||||
RID create_texture(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples = RD::TEXTURE_SAMPLES_1, const Size2i p_size = Size2i(0, 0), const uint32_t p_layers = 0, const uint32_t p_mipmaps = 1, bool p_unique = true);
|
||||
RID create_texture(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples = RD::TEXTURE_SAMPLES_1, const Size2i p_size = Size2i(0, 0), const uint32_t p_layers = 0, const uint32_t p_mipmaps = 1, bool p_unique = true, bool p_discardable = false);
|
||||
RID create_texture_from_format(const StringName &p_context, const StringName &p_texture_name, const RD::TextureFormat &p_texture_format, RD::TextureView p_view = RD::TextureView(), bool p_unique = true);
|
||||
RID create_texture_view(const StringName &p_context, const StringName &p_texture_name, const StringName &p_view_name, RD::TextureView p_view = RD::TextureView());
|
||||
RID get_texture(const StringName &p_context, const StringName &p_texture_name) const;
|
||||
|
|
@ -305,6 +317,30 @@ public:
|
|||
return samplers;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ static RD::TextureSamples msaa_to_samples(RS::ViewportMSAA p_msaa) {
|
||||
switch (p_msaa) {
|
||||
case RS::VIEWPORT_MSAA_DISABLED:
|
||||
return RD::TEXTURE_SAMPLES_1;
|
||||
case RS::VIEWPORT_MSAA_2X:
|
||||
return RD::TEXTURE_SAMPLES_2;
|
||||
case RS::VIEWPORT_MSAA_4X:
|
||||
return RD::TEXTURE_SAMPLES_4;
|
||||
case RS::VIEWPORT_MSAA_8X:
|
||||
return RD::TEXTURE_SAMPLES_8;
|
||||
default:
|
||||
DEV_ASSERT(false && "Unknown MSAA option.");
|
||||
return RD::TEXTURE_SAMPLES_1;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t get_color_usage_bits(bool p_resolve, bool p_msaa, bool p_storage);
|
||||
static RD::DataFormat get_depth_format(bool p_resolve, bool p_msaa, bool p_storage);
|
||||
static uint32_t get_depth_usage_bits(bool p_resolve, bool p_msaa, bool p_storage);
|
||||
static RD::DataFormat get_velocity_format();
|
||||
static uint32_t get_velocity_usage_bits(bool p_resolve, bool p_msaa, bool p_storage);
|
||||
static RD::DataFormat get_vrs_format();
|
||||
static uint32_t get_vrs_usage_bits();
|
||||
|
||||
private:
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Our classDB doesn't support calling our normal exposed functions
|
||||
|
|
@ -398,6 +434,8 @@ private:
|
|||
RID _get_velocity_texture_compat_80214();
|
||||
RID _get_velocity_layer_compat_80214(const uint32_t p_layer);
|
||||
|
||||
RID _create_texture_bind_compat_98670(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples, const Size2i p_size, const uint32_t p_layers, const uint32_t p_mipmaps, bool p_unique);
|
||||
|
||||
static void _bind_compatibility_methods();
|
||||
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
|
|
|||
|
|
@ -32,10 +32,6 @@
|
|||
#include "servers/rendering/renderer_rd/renderer_scene_render_rd.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/light_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
|
||||
#include "servers/rendering/rendering_server_default.h"
|
||||
|
||||
void RenderSceneDataRD::_bind_methods() {
|
||||
}
|
||||
|
||||
Transform3D RenderSceneDataRD::get_cam_transform() const {
|
||||
return cam_transform;
|
||||
|
|
@ -115,6 +111,7 @@ void RenderSceneDataRD::update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p
|
|||
|
||||
ubo.taa_jitter[0] = taa_jitter.x;
|
||||
ubo.taa_jitter[1] = taa_jitter.y;
|
||||
ubo.taa_frame_count = taa_frame_count;
|
||||
|
||||
ubo.z_far = z_far;
|
||||
ubo.z_near = z_near;
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@
|
|||
#ifndef RENDER_SCENE_DATA_RD_H
|
||||
#define RENDER_SCENE_DATA_RD_H
|
||||
|
||||
#include "render_scene_buffers_rd.h"
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
#include "servers/rendering/storage/render_scene_data.h"
|
||||
|
||||
// This is a container for data related to rendering a single frame of a viewport where we load this data into a UBO
|
||||
|
|
@ -48,8 +46,10 @@ public:
|
|||
Transform3D cam_transform;
|
||||
Projection cam_projection;
|
||||
Vector2 taa_jitter;
|
||||
float taa_frame_count = 0.0f;
|
||||
uint32_t camera_visible_layers;
|
||||
bool cam_orthogonal = false;
|
||||
bool cam_frustum = false;
|
||||
bool flip_y = false;
|
||||
|
||||
// For billboards to cast correct shadows.
|
||||
|
|
@ -95,8 +95,6 @@ public:
|
|||
virtual RID get_uniform_buffer() const override;
|
||||
|
||||
private:
|
||||
static void _bind_methods();
|
||||
|
||||
RID uniform_buffer; // loaded into this uniform buffer (supplied externally)
|
||||
|
||||
// This struct is loaded into Set 1 - Binding 0, populated at start of rendering a frame, must match with shader code
|
||||
|
|
@ -150,8 +148,8 @@ private:
|
|||
|
||||
float fog_height_density;
|
||||
float fog_depth_curve;
|
||||
float pad;
|
||||
float fog_depth_begin;
|
||||
float taa_frame_count; // Used to add break up samples over multiple frames. Value is an integer from 0 to taa_phase_count -1.
|
||||
|
||||
float fog_light_color[3];
|
||||
float fog_depth_end;
|
||||
|
|
|
|||
|
|
@ -40,25 +40,18 @@ using namespace RendererRD;
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// TextureStorage::CanvasTexture
|
||||
|
||||
void TextureStorage::CanvasTexture::clear_sets() {
|
||||
if (cleared_cache) {
|
||||
return;
|
||||
void TextureStorage::CanvasTexture::clear_cache() {
|
||||
info_cache[0] = CanvasTextureCache();
|
||||
info_cache[1] = CanvasTextureCache();
|
||||
if (invalidated_callback != nullptr) {
|
||||
invalidated_callback(false, invalidated_callback_userdata);
|
||||
}
|
||||
for (int i = 1; i < RS::CANVAS_ITEM_TEXTURE_FILTER_MAX; i++) {
|
||||
for (int j = 1; j < RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX; j++) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (RD::get_singleton()->uniform_set_is_valid(uniform_sets[i][j][k])) {
|
||||
RD::get_singleton()->free(uniform_sets[i][j][k]);
|
||||
uniform_sets[i][j][k] = RID();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cleared_cache = true;
|
||||
}
|
||||
|
||||
TextureStorage::CanvasTexture::~CanvasTexture() {
|
||||
clear_sets();
|
||||
if (invalidated_callback != nullptr) {
|
||||
invalidated_callback(true, invalidated_callback_userdata);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -185,9 +178,8 @@ TextureStorage::TextureStorage() {
|
|||
ptr[i] = Math::make_half_float(1.0f);
|
||||
}
|
||||
|
||||
Vector<Vector<uint8_t>> vpv;
|
||||
vpv.push_back(sv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_DEPTH] = RD::get_singleton()->texture_create(tf, RD::TextureView(), vpv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_DEPTH] = RD::get_singleton()->texture_create(tf, RD::TextureView());
|
||||
RD::get_singleton()->texture_update(default_rd_textures[DEFAULT_RD_TEXTURE_DEPTH], 0, sv);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
|
|
@ -460,9 +452,8 @@ TextureStorage::TextureStorage() {
|
|||
}
|
||||
|
||||
{
|
||||
Vector<Vector<uint8_t>> vsv;
|
||||
vsv.push_back(sv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vsv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH] = RD::get_singleton()->texture_create(tformat, RD::TextureView());
|
||||
RD::get_singleton()->texture_update(default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH], 0, sv);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -533,6 +524,32 @@ TextureStorage::TextureStorage() {
|
|||
rt_sdf.pipelines[i] = RD::get_singleton()->compute_pipeline_create(rt_sdf.shader.version_get_shader(rt_sdf.shader_version, i));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize texture placeholder data for the `texture_*_placeholder_initialize()` methods.
|
||||
|
||||
constexpr int placeholder_size = 4;
|
||||
texture_2d_placeholder = Image::create_empty(placeholder_size, placeholder_size, false, Image::FORMAT_RGBA8);
|
||||
// Draw a magenta/black checkerboard pattern.
|
||||
for (int i = 0; i < placeholder_size * placeholder_size; i++) {
|
||||
const int x = i % placeholder_size;
|
||||
const int y = i / placeholder_size;
|
||||
texture_2d_placeholder->set_pixel(x, y, (x + y) % 2 == 0 ? Color(1, 0, 1) : Color(0, 0, 0));
|
||||
}
|
||||
|
||||
texture_2d_array_placeholder.push_back(texture_2d_placeholder);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
cubemap_placeholder.push_back(texture_2d_placeholder);
|
||||
}
|
||||
|
||||
Ref<Image> texture_2d_placeholder_rotated;
|
||||
texture_2d_placeholder_rotated.instantiate();
|
||||
texture_2d_placeholder_rotated->copy_from(texture_2d_placeholder);
|
||||
texture_2d_placeholder_rotated->rotate_90(CLOCKWISE);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Alternate checkerboard pattern on odd layers (by using a copy that is rotated 90 degrees).
|
||||
texture_3d_placeholder.push_back(i % 2 == 0 ? texture_2d_placeholder : texture_2d_placeholder_rotated);
|
||||
}
|
||||
}
|
||||
|
||||
TextureStorage::~TextureStorage() {
|
||||
|
|
@ -579,10 +596,6 @@ bool TextureStorage::free(RID p_rid) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool TextureStorage::can_create_resources_async() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Canvas Texture API */
|
||||
|
||||
RID TextureStorage::canvas_texture_allocate() {
|
||||
|
|
@ -612,8 +625,7 @@ void TextureStorage::canvas_texture_set_channel(RID p_canvas_texture, RS::Canvas
|
|||
ct->specular = p_texture;
|
||||
} break;
|
||||
}
|
||||
|
||||
ct->clear_sets();
|
||||
ct->clear_cache();
|
||||
}
|
||||
|
||||
void TextureStorage::canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_specular_color, float p_shininess) {
|
||||
|
|
@ -624,7 +636,6 @@ void TextureStorage::canvas_texture_set_shading_parameters(RID p_canvas_texture,
|
|||
ct->specular_color.g = p_specular_color.g;
|
||||
ct->specular_color.b = p_specular_color.b;
|
||||
ct->specular_color.a = p_shininess;
|
||||
ct->clear_sets();
|
||||
}
|
||||
|
||||
void TextureStorage::canvas_texture_set_texture_filter(RID p_canvas_texture, RS::CanvasItemTextureFilter p_filter) {
|
||||
|
|
@ -632,7 +643,6 @@ void TextureStorage::canvas_texture_set_texture_filter(RID p_canvas_texture, RS:
|
|||
ERR_FAIL_NULL(ct);
|
||||
|
||||
ct->texture_filter = p_filter;
|
||||
ct->clear_sets();
|
||||
}
|
||||
|
||||
void TextureStorage::canvas_texture_set_texture_repeat(RID p_canvas_texture, RS::CanvasItemTextureRepeat p_repeat) {
|
||||
|
|
@ -640,17 +650,14 @@ void TextureStorage::canvas_texture_set_texture_repeat(RID p_canvas_texture, RS:
|
|||
ERR_FAIL_NULL(ct);
|
||||
|
||||
ct->texture_repeat = p_repeat;
|
||||
ct->clear_sets();
|
||||
}
|
||||
|
||||
bool TextureStorage::canvas_texture_get_uniform_set(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, RID p_base_shader, int p_base_set, bool p_use_srgb, RID &r_uniform_set, Size2i &r_size, Color &r_specular_shininess, bool &r_use_normal, bool &r_use_specular, bool p_texture_is_data) {
|
||||
TextureStorage::CanvasTextureInfo TextureStorage::canvas_texture_get_info(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, bool p_use_srgb, bool p_texture_is_data) {
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
|
||||
CanvasTexture *ct = nullptr;
|
||||
Texture *t = get_texture(p_texture);
|
||||
|
||||
// TODO once we have our texture storage split off we'll look into moving this code into canvas_texture
|
||||
|
||||
if (t) {
|
||||
//regular texture
|
||||
if (!t->canvas_texture) {
|
||||
|
|
@ -667,93 +674,81 @@ bool TextureStorage::canvas_texture_get_uniform_set(RID p_texture, RS::CanvasIte
|
|||
}
|
||||
|
||||
if (!ct) {
|
||||
return false; //invalid texture RID
|
||||
return CanvasTextureInfo(); //invalid texture RID
|
||||
}
|
||||
|
||||
RS::CanvasItemTextureFilter filter = ct->texture_filter != RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT ? ct->texture_filter : p_base_filter;
|
||||
ERR_FAIL_COND_V(filter == RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, false);
|
||||
ERR_FAIL_COND_V(filter == RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, CanvasTextureInfo());
|
||||
|
||||
RS::CanvasItemTextureRepeat repeat = ct->texture_repeat != RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT ? ct->texture_repeat : p_base_repeat;
|
||||
ERR_FAIL_COND_V(repeat == RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, false);
|
||||
ERR_FAIL_COND_V(repeat == RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, CanvasTextureInfo());
|
||||
|
||||
RID uniform_set = ct->uniform_sets[filter][repeat][int(p_use_srgb)];
|
||||
if (!RD::get_singleton()->uniform_set_is_valid(uniform_set)) {
|
||||
//create and update
|
||||
Vector<RD::Uniform> uniforms;
|
||||
CanvasTextureCache &ctc = ct->info_cache[int(p_use_srgb)];
|
||||
if (!RD::get_singleton()->texture_is_valid(ctc.diffuse) ||
|
||||
!RD::get_singleton()->texture_is_valid(ctc.normal) ||
|
||||
!RD::get_singleton()->texture_is_valid(ctc.specular)) {
|
||||
{ //diffuse
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
u.binding = 0;
|
||||
|
||||
t = get_texture(ct->diffuse);
|
||||
if (!t) {
|
||||
u.append_id(texture_rd_get_default(DEFAULT_RD_TEXTURE_WHITE));
|
||||
ctc.diffuse = texture_rd_get_default(DEFAULT_RD_TEXTURE_WHITE);
|
||||
ct->size_cache = Size2i(1, 1);
|
||||
} else {
|
||||
u.append_id(t->rd_texture_srgb.is_valid() && p_use_srgb && !p_texture_is_data ? t->rd_texture_srgb : t->rd_texture);
|
||||
ctc.diffuse = t->rd_texture_srgb.is_valid() && p_use_srgb && !p_texture_is_data ? t->rd_texture_srgb : t->rd_texture;
|
||||
ct->size_cache = Size2i(t->width_2d, t->height_2d);
|
||||
if (t->render_target) {
|
||||
t->render_target->was_used = true;
|
||||
}
|
||||
}
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
{ //normal
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
u.binding = 1;
|
||||
|
||||
t = get_texture(ct->normal_map);
|
||||
if (!t) {
|
||||
u.append_id(texture_rd_get_default(DEFAULT_RD_TEXTURE_NORMAL));
|
||||
ctc.normal = texture_rd_get_default(DEFAULT_RD_TEXTURE_NORMAL);
|
||||
ct->use_normal_cache = false;
|
||||
} else {
|
||||
u.append_id(t->rd_texture);
|
||||
ctc.normal = t->rd_texture;
|
||||
ct->use_normal_cache = true;
|
||||
if (t->render_target) {
|
||||
t->render_target->was_used = true;
|
||||
}
|
||||
}
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
{ //specular
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
u.binding = 2;
|
||||
|
||||
t = get_texture(ct->specular);
|
||||
if (!t) {
|
||||
u.append_id(texture_rd_get_default(DEFAULT_RD_TEXTURE_WHITE));
|
||||
ctc.specular = texture_rd_get_default(DEFAULT_RD_TEXTURE_WHITE);
|
||||
ct->use_specular_cache = false;
|
||||
} else {
|
||||
u.append_id(t->rd_texture);
|
||||
ctc.specular = t->rd_texture;
|
||||
ct->use_specular_cache = true;
|
||||
if (t->render_target) {
|
||||
t->render_target->was_used = true;
|
||||
}
|
||||
}
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
{ //sampler
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_SAMPLER;
|
||||
u.binding = 3;
|
||||
u.append_id(material_storage->sampler_rd_get_default(filter, repeat));
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniform_set = RD::get_singleton()->uniform_set_create(uniforms, p_base_shader, p_base_set);
|
||||
ct->uniform_sets[filter][repeat][int(p_use_srgb)] = uniform_set;
|
||||
ct->cleared_cache = false;
|
||||
}
|
||||
|
||||
r_uniform_set = uniform_set;
|
||||
r_size = ct->size_cache;
|
||||
r_specular_shininess = ct->specular_color;
|
||||
r_use_normal = ct->use_normal_cache;
|
||||
r_use_specular = ct->use_specular_cache;
|
||||
CanvasTextureInfo res;
|
||||
res.diffuse = ctc.diffuse;
|
||||
res.normal = ctc.normal;
|
||||
res.specular = ctc.specular;
|
||||
res.sampler = material_storage->sampler_rd_get_default(filter, repeat);
|
||||
res.size = ct->size_cache;
|
||||
res.specular_color = ct->specular_color;
|
||||
res.use_normal = ct->use_normal_cache;
|
||||
res.use_specular = ct->use_specular_cache;
|
||||
|
||||
return true;
|
||||
return res;
|
||||
}
|
||||
|
||||
void TextureStorage::canvas_texture_set_invalidation_callback(RID p_canvas_texture, InvalidationCallback p_callback, void *p_userdata) {
|
||||
CanvasTexture *ct = canvas_texture_owner.get_or_null(p_canvas_texture);
|
||||
if (!ct) {
|
||||
return;
|
||||
}
|
||||
|
||||
ct->invalidated_callback = p_callback;
|
||||
ct->invalidated_callback_userdata = p_userdata;
|
||||
}
|
||||
|
||||
/* Texture API */
|
||||
|
|
@ -1087,6 +1082,9 @@ void TextureStorage::texture_3d_initialize(RID p_texture, Image::Format p_format
|
|||
texture_owner.initialize_rid(p_texture, texture);
|
||||
}
|
||||
|
||||
void TextureStorage::texture_external_initialize(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) {
|
||||
}
|
||||
|
||||
void TextureStorage::texture_proxy_initialize(RID p_texture, RID p_base) {
|
||||
Texture *tex = texture_owner.get_or_null(p_base);
|
||||
ERR_FAIL_NULL(tex);
|
||||
|
|
@ -1108,6 +1106,195 @@ void TextureStorage::texture_proxy_initialize(RID p_texture, RID p_base) {
|
|||
tex->proxies.push_back(p_texture);
|
||||
}
|
||||
|
||||
// Note: We make some big assumptions about format and usage. If developers need more control,
|
||||
// they should use RD::texture_create_from_extension() instead.
|
||||
RID TextureStorage::texture_create_from_native_handle(RS::TextureType p_type, Image::Format p_format, uint64_t p_native_handle, int p_width, int p_height, int p_depth, int p_layers, RS::TextureLayeredType p_layered_type) {
|
||||
RD::TextureType type;
|
||||
switch (p_type) {
|
||||
case RS::TEXTURE_TYPE_2D:
|
||||
type = RD::TEXTURE_TYPE_2D;
|
||||
break;
|
||||
|
||||
case RS::TEXTURE_TYPE_3D:
|
||||
type = RD::TEXTURE_TYPE_3D;
|
||||
break;
|
||||
|
||||
case RS::TEXTURE_TYPE_LAYERED:
|
||||
if (p_layered_type == RS::TEXTURE_LAYERED_2D_ARRAY) {
|
||||
type = RD::TEXTURE_TYPE_2D_ARRAY;
|
||||
} else if (p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP) {
|
||||
type = RD::TEXTURE_TYPE_CUBE;
|
||||
} else if (p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP_ARRAY) {
|
||||
type = RD::TEXTURE_TYPE_CUBE_ARRAY;
|
||||
} else {
|
||||
// Arbitrary fallback.
|
||||
type = RD::TEXTURE_TYPE_2D_ARRAY;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Arbitrary fallback.
|
||||
type = RD::TEXTURE_TYPE_2D;
|
||||
}
|
||||
|
||||
// Only a rough conversion - see note above.
|
||||
RD::DataFormat format;
|
||||
switch (p_format) {
|
||||
case Image::FORMAT_L8:
|
||||
case Image::FORMAT_R8:
|
||||
format = RD::DATA_FORMAT_R8_UNORM;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_LA8:
|
||||
case Image::FORMAT_RG8:
|
||||
format = RD::DATA_FORMAT_R8G8_UNORM;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGB8:
|
||||
format = RD::DATA_FORMAT_R8G8B8_UNORM;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBA8:
|
||||
format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBA4444:
|
||||
format = RD::DATA_FORMAT_B4G4R4A4_UNORM_PACK16;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGB565:
|
||||
format = RD::DATA_FORMAT_B5G6R5_UNORM_PACK16;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RF:
|
||||
format = RD::DATA_FORMAT_R32_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGF:
|
||||
format = RD::DATA_FORMAT_R32G32_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBF:
|
||||
format = RD::DATA_FORMAT_R32G32B32_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBAF:
|
||||
format = RD::DATA_FORMAT_R32G32B32_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RH:
|
||||
format = RD::DATA_FORMAT_R16_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGH:
|
||||
format = RD::DATA_FORMAT_R16G16_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBH:
|
||||
format = RD::DATA_FORMAT_R16G16B16_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBAH:
|
||||
format = RD::DATA_FORMAT_R16G16B16A16_SFLOAT;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGBE9995:
|
||||
format = RD::DATA_FORMAT_E5B9G9R9_UFLOAT_PACK32;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_DXT1:
|
||||
format = RD::DATA_FORMAT_BC1_RGB_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_DXT3:
|
||||
format = RD::DATA_FORMAT_BC2_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_DXT5:
|
||||
format = RD::DATA_FORMAT_BC3_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGTC_R:
|
||||
format = RD::DATA_FORMAT_BC4_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_RGTC_RG:
|
||||
format = RD::DATA_FORMAT_BC5_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_BPTC_RGBA:
|
||||
format = RD::DATA_FORMAT_BC7_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_BPTC_RGBF:
|
||||
format = RD::DATA_FORMAT_BC6H_SFLOAT_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_BPTC_RGBFU:
|
||||
format = RD::DATA_FORMAT_BC6H_UFLOAT_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC:
|
||||
format = RD::DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_R11:
|
||||
format = RD::DATA_FORMAT_EAC_R11_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_R11S:
|
||||
format = RD::DATA_FORMAT_EAC_R11_SNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_RG11:
|
||||
format = RD::DATA_FORMAT_EAC_R11G11_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_RG11S:
|
||||
format = RD::DATA_FORMAT_EAC_R11G11_SNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_RGB8:
|
||||
format = RD::DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_RGBA8:
|
||||
format = RD::DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_RGB8A1:
|
||||
format = RD::DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ETC2_RA_AS_RG:
|
||||
format = RD::DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_DXT5_RA_AS_RG:
|
||||
format = RD::DATA_FORMAT_BC3_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ASTC_4x4:
|
||||
case Image::FORMAT_ASTC_4x4_HDR:
|
||||
format = RD::DATA_FORMAT_ASTC_4x4_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
case Image::FORMAT_ASTC_8x8:
|
||||
case Image::FORMAT_ASTC_8x8_HDR:
|
||||
format = RD::DATA_FORMAT_ASTC_8x8_UNORM_BLOCK;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Arbitrary fallback.
|
||||
format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
|
||||
// Assumed to be a color attachment - see note above.
|
||||
uint64_t usage_flags = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
|
||||
return RD::get_singleton()->texture_create_from_extension(type, format, RD::TEXTURE_SAMPLES_1, usage_flags, p_native_handle, p_width, p_height, p_depth, p_layers);
|
||||
}
|
||||
|
||||
void TextureStorage::_texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer, bool p_immediate) {
|
||||
ERR_FAIL_COND(p_image.is_null() || p_image->is_empty());
|
||||
|
||||
|
|
@ -1172,6 +1359,9 @@ void TextureStorage::texture_3d_update(RID p_texture, const Vector<Ref<Image>> &
|
|||
RD::get_singleton()->texture_update(tex->rd_texture, 0, all_data);
|
||||
}
|
||||
|
||||
void TextureStorage::texture_external_update(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) {
|
||||
}
|
||||
|
||||
void TextureStorage::texture_proxy_update(RID p_texture, RID p_proxy_to) {
|
||||
Texture *tex = texture_owner.get_or_null(p_texture);
|
||||
ERR_FAIL_NULL(tex);
|
||||
|
|
@ -1217,46 +1407,19 @@ void TextureStorage::texture_proxy_update(RID p_texture, RID p_proxy_to) {
|
|||
|
||||
//these two APIs can be used together or in combination with the others.
|
||||
void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) {
|
||||
//this could be better optimized to reuse an existing image , done this way
|
||||
//for now to get it working
|
||||
Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
|
||||
image->fill(Color(1, 0, 1, 1));
|
||||
|
||||
texture_2d_initialize(p_texture, image);
|
||||
texture_2d_initialize(p_texture, texture_2d_placeholder);
|
||||
}
|
||||
|
||||
void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RS::TextureLayeredType p_layered_type) {
|
||||
//this could be better optimized to reuse an existing image , done this way
|
||||
//for now to get it working
|
||||
Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
|
||||
image->fill(Color(1, 0, 1, 1));
|
||||
|
||||
Vector<Ref<Image>> images;
|
||||
if (p_layered_type == RS::TEXTURE_LAYERED_2D_ARRAY) {
|
||||
images.push_back(image);
|
||||
texture_2d_layered_initialize(p_texture, texture_2d_array_placeholder, p_layered_type);
|
||||
} else {
|
||||
//cube
|
||||
for (int i = 0; i < 6; i++) {
|
||||
images.push_back(image);
|
||||
}
|
||||
texture_2d_layered_initialize(p_texture, cubemap_placeholder, p_layered_type);
|
||||
}
|
||||
|
||||
texture_2d_layered_initialize(p_texture, images, p_layered_type);
|
||||
}
|
||||
|
||||
void TextureStorage::texture_3d_placeholder_initialize(RID p_texture) {
|
||||
//this could be better optimized to reuse an existing image , done this way
|
||||
//for now to get it working
|
||||
Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
|
||||
image->fill(Color(1, 0, 1, 1));
|
||||
|
||||
Vector<Ref<Image>> images;
|
||||
//cube
|
||||
for (int i = 0; i < 4; i++) {
|
||||
images.push_back(image);
|
||||
}
|
||||
|
||||
texture_3d_initialize(p_texture, Image::FORMAT_RGBA8, 4, 4, 4, false, images);
|
||||
texture_3d_initialize(p_texture, Image::FORMAT_RGBA8, 4, 4, 4, false, texture_3d_placeholder);
|
||||
}
|
||||
|
||||
Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const {
|
||||
|
|
@ -1299,7 +1462,11 @@ Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const {
|
|||
image = Image::create_from_data(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(image->is_empty(), Ref<Image>());
|
||||
if (image->is_empty()) {
|
||||
const String &path_str = tex->path.is_empty() ? "with no path" : vformat("with path '%s'", tex->path);
|
||||
ERR_FAIL_V_MSG(Ref<Image>(), vformat("Texture %s has no data.", path_str));
|
||||
}
|
||||
|
||||
if (tex->format != tex->validated_format) {
|
||||
image->convert(tex->format);
|
||||
}
|
||||
|
|
@ -1320,7 +1487,10 @@ Ref<Image> TextureStorage::texture_2d_layer_get(RID p_texture, int p_layer) cons
|
|||
Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, p_layer);
|
||||
ERR_FAIL_COND_V(data.is_empty(), Ref<Image>());
|
||||
Ref<Image> image = Image::create_from_data(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data);
|
||||
ERR_FAIL_COND_V(image->is_empty(), Ref<Image>());
|
||||
if (image->is_empty()) {
|
||||
const String &path_str = tex->path.is_empty() ? "with no path" : vformat("with path '%s'", tex->path);
|
||||
ERR_FAIL_V_MSG(Ref<Image>(), vformat("Texture %s has no data.", path_str));
|
||||
}
|
||||
if (tex->format != tex->validated_format) {
|
||||
image->convert(tex->format);
|
||||
}
|
||||
|
|
@ -1347,6 +1517,10 @@ Vector<Ref<Image>> TextureStorage::texture_3d_get(RID p_texture) const {
|
|||
|
||||
Ref<Image> img = Image::create_from_data(bs.size.width, bs.size.height, false, tex->validated_format, sub_region);
|
||||
ERR_FAIL_COND_V(img->is_empty(), Vector<Ref<Image>>());
|
||||
if (img->is_empty()) {
|
||||
const String &path_str = tex->path.is_empty() ? "with no path" : vformat("with path '%s'", tex->path);
|
||||
ERR_FAIL_V_MSG(Vector<Ref<Image>>(), vformat("Texture %s has no data.", path_str));
|
||||
}
|
||||
if (tex->format != tex->validated_format) {
|
||||
img->convert(tex->format);
|
||||
}
|
||||
|
|
@ -1470,8 +1644,24 @@ void TextureStorage::texture_debug_usage(List<RS::TextureInfo> *r_info) {
|
|||
tinfo.format = t->format;
|
||||
tinfo.width = t->width;
|
||||
tinfo.height = t->height;
|
||||
tinfo.depth = t->depth;
|
||||
tinfo.bytes = Image::get_image_data_size(t->width, t->height, t->format, t->mipmaps);
|
||||
tinfo.bytes = Image::get_image_data_size(t->width, t->height, t->format, t->mipmaps > 1);
|
||||
|
||||
switch (t->type) {
|
||||
case TextureType::TYPE_3D:
|
||||
tinfo.depth = t->depth;
|
||||
tinfo.bytes *= t->depth;
|
||||
break;
|
||||
|
||||
case TextureType::TYPE_LAYERED:
|
||||
tinfo.depth = t->layers;
|
||||
tinfo.bytes *= t->layers;
|
||||
break;
|
||||
|
||||
default:
|
||||
tinfo.depth = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
r_info->push_back(tinfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -1503,7 +1693,9 @@ void TextureStorage::texture_rd_initialize(RID p_texture, const RID &p_rd_textur
|
|||
ERR_FAIL_COND(tf.array_layers != 1);
|
||||
texture.type = TextureStorage::TYPE_2D;
|
||||
} break;
|
||||
case RD::TEXTURE_TYPE_2D_ARRAY: {
|
||||
case RD::TEXTURE_TYPE_2D_ARRAY:
|
||||
case RD::TEXTURE_TYPE_CUBE:
|
||||
case RD::TEXTURE_TYPE_CUBE_ARRAY: {
|
||||
// RenderingDevice doesn't distinguish between Array textures and Cube textures
|
||||
// this condition covers TextureArrays, TextureCube, and TextureCubeArray.
|
||||
ERR_FAIL_COND(tf.array_layers == 1);
|
||||
|
|
@ -2009,10 +2201,15 @@ Ref<Image> TextureStorage::_validate_texture_format(const Ref<Image> &p_image, T
|
|||
}
|
||||
} else {
|
||||
//not supported, reconvert
|
||||
r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
image->decompress();
|
||||
image->convert(Image::FORMAT_RGBA8);
|
||||
if (p_image->get_format() == Image::FORMAT_ASTC_4x4) {
|
||||
r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
image->convert(Image::FORMAT_RGBA8);
|
||||
} else {
|
||||
r_format.format = RD::DATA_FORMAT_R16G16B16A16_SFLOAT;
|
||||
image->convert(Image::FORMAT_RGBAH);
|
||||
}
|
||||
}
|
||||
r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R;
|
||||
r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G;
|
||||
|
|
@ -2029,10 +2226,15 @@ Ref<Image> TextureStorage::_validate_texture_format(const Ref<Image> &p_image, T
|
|||
}
|
||||
} else {
|
||||
//not supported, reconvert
|
||||
r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
image->decompress();
|
||||
image->convert(Image::FORMAT_RGBA8);
|
||||
if (p_image->get_format() == Image::FORMAT_ASTC_8x8) {
|
||||
r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
image->convert(Image::FORMAT_RGBA8);
|
||||
} else {
|
||||
r_format.format = RD::DATA_FORMAT_R16G16B16A16_SFLOAT;
|
||||
image->convert(Image::FORMAT_RGBAH);
|
||||
}
|
||||
}
|
||||
r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R;
|
||||
r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G;
|
||||
|
|
@ -2105,6 +2307,16 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B;
|
||||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A;
|
||||
} break;
|
||||
case RD::DATA_FORMAT_B8G8R8A8_UNORM:
|
||||
case RD::DATA_FORMAT_B8G8R8A8_SRGB: {
|
||||
r_format.image_format = Image::FORMAT_RGBA8;
|
||||
r_format.rd_format = RD::DATA_FORMAT_B8G8R8A8_UNORM;
|
||||
r_format.rd_format_srgb = RD::DATA_FORMAT_B8G8R8A8_SRGB;
|
||||
r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R;
|
||||
r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G;
|
||||
r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B;
|
||||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A;
|
||||
} break;
|
||||
case RD::DATA_FORMAT_B4G4R4A4_UNORM_PACK16: {
|
||||
r_format.image_format = Image::FORMAT_RGBA4444;
|
||||
r_format.rd_format = RD::DATA_FORMAT_B4G4R4A4_UNORM_PACK16;
|
||||
|
|
@ -2146,7 +2358,7 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_ONE;
|
||||
} break;
|
||||
case RD::DATA_FORMAT_R32G32B32A32_SFLOAT: {
|
||||
r_format.image_format = Image::FORMAT_RGBF;
|
||||
r_format.image_format = Image::FORMAT_RGBAF;
|
||||
r_format.rd_format = RD::DATA_FORMAT_R32G32B32A32_SFLOAT;
|
||||
r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R;
|
||||
r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G;
|
||||
|
|
@ -2319,7 +2531,6 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_ONE;
|
||||
|
||||
} break;
|
||||
/* already maps to FORMAT_ETC2_RGBA8
|
||||
case RD::DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
|
||||
case RD::DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: {
|
||||
r_format.image_format = Image::FORMAT_ETC2_RGBA8;
|
||||
|
|
@ -2330,7 +2541,6 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B;
|
||||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A;
|
||||
} break;
|
||||
*/
|
||||
case RD::DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
|
||||
case RD::DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: {
|
||||
r_format.image_format = Image::FORMAT_ETC2_RGB8A1;
|
||||
|
|
@ -2341,6 +2551,7 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B;
|
||||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A;
|
||||
} break;
|
||||
/* already maps to FORMAT_ETC2_RGBA8
|
||||
case RD::DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
|
||||
case RD::DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: {
|
||||
r_format.image_format = Image::FORMAT_ETC2_RA_AS_RG;
|
||||
|
|
@ -2350,7 +2561,7 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
r_format.swizzle_g = RD::TEXTURE_SWIZZLE_A;
|
||||
r_format.swizzle_b = RD::TEXTURE_SWIZZLE_ZERO;
|
||||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_ONE;
|
||||
} break;
|
||||
} break;*/
|
||||
/* already maps to FORMAT_DXT5
|
||||
case RD::DATA_FORMAT_BC3_UNORM_BLOCK:
|
||||
case RD::DATA_FORMAT_BC3_SRGB_BLOCK: {
|
||||
|
|
@ -2386,6 +2597,10 @@ void TextureStorage::_texture_format_from_rd(RD::DataFormat p_rd_format, Texture
|
|||
// Q: Do we do as we do below, just create the sRGB variant?
|
||||
r_format.image_format = Image::FORMAT_ASTC_8x8;
|
||||
r_format.rd_format = RD::DATA_FORMAT_ASTC_8x8_UNORM_BLOCK;
|
||||
r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R;
|
||||
r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G;
|
||||
r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B;
|
||||
r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A;
|
||||
} break;
|
||||
case RD::DATA_FORMAT_ASTC_8x8_SRGB_BLOCK: {
|
||||
r_format.image_format = Image::FORMAT_ASTC_8x8_HDR;
|
||||
|
|
@ -2719,7 +2934,7 @@ void TextureStorage::update_decal_atlas() {
|
|||
Vector<Color> cc;
|
||||
cc.push_back(clear_color);
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(mm.fb, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, cc);
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(mm.fb, RD::DRAW_CLEAR_ALL, cc);
|
||||
|
||||
for (const KeyValue<RID, DecalAtlas::Texture> &E : decal_atlas.textures) {
|
||||
DecalAtlas::Texture *t = decal_atlas.textures.getptr(E.key);
|
||||
|
|
@ -3067,13 +3282,13 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
|
|||
if (rt->size.width == 0 || rt->size.height == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
rt->color_format = render_target_get_color_format(rt->use_hdr, false);
|
||||
rt->color_format_srgb = render_target_get_color_format(rt->use_hdr, true);
|
||||
|
||||
if (rt->use_hdr) {
|
||||
rt->color_format = RendererSceneRenderRD::get_singleton()->_render_buffers_get_color_format();
|
||||
rt->color_format_srgb = rt->color_format;
|
||||
rt->image_format = rt->is_transparent ? Image::FORMAT_RGBAH : Image::FORMAT_RGBH;
|
||||
} else {
|
||||
rt->color_format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
rt->color_format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
rt->image_format = rt->is_transparent ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8;
|
||||
}
|
||||
|
||||
|
|
@ -3092,8 +3307,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
|
|||
rd_color_attachment_format.texture_type = RD::TEXTURE_TYPE_2D;
|
||||
}
|
||||
rd_color_attachment_format.samples = RD::TEXTURE_SAMPLES_1;
|
||||
rd_color_attachment_format.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT;
|
||||
rd_color_attachment_format.usage_bits |= RD::TEXTURE_USAGE_STORAGE_BIT; // FIXME we need this only when FSR is enabled
|
||||
rd_color_attachment_format.usage_bits = render_target_get_color_usage_bits(false);
|
||||
rd_color_attachment_format.shareable_formats.push_back(rt->color_format);
|
||||
rd_color_attachment_format.shareable_formats.push_back(rt->color_format_srgb);
|
||||
if (rt->msaa != RS::VIEWPORT_MSAA_DISABLED) {
|
||||
|
|
@ -3115,7 +3329,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
|
|||
RD::TEXTURE_SAMPLES_8,
|
||||
};
|
||||
rd_color_multisample_format.samples = texture_samples[rt->msaa];
|
||||
rd_color_multisample_format.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
rd_color_multisample_format.usage_bits = render_target_get_color_usage_bits(true);
|
||||
RD::TextureView rd_view_multisample;
|
||||
rd_color_multisample_format.is_resolve_buffer = false;
|
||||
rt->color_multisample = RD::get_singleton()->texture_create(rd_color_multisample_format, rd_view_multisample);
|
||||
|
|
@ -3262,7 +3476,7 @@ RID TextureStorage::render_target_get_texture(RID p_render_target) {
|
|||
return rt->texture;
|
||||
}
|
||||
|
||||
void TextureStorage::render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture) {
|
||||
void TextureStorage::render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) {
|
||||
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
|
||||
ERR_FAIL_NULL(rt);
|
||||
|
||||
|
|
@ -3330,6 +3544,20 @@ RID TextureStorage::render_target_get_override_velocity_slice(RID p_render_targe
|
|||
}
|
||||
}
|
||||
|
||||
void RendererRD::TextureStorage::render_target_set_render_region(RID p_render_target, const Rect2i &p_render_region) {
|
||||
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
|
||||
ERR_FAIL_NULL(rt);
|
||||
|
||||
rt->render_region = p_render_region;
|
||||
}
|
||||
|
||||
Rect2i RendererRD::TextureStorage::render_target_get_render_region(RID p_render_target) const {
|
||||
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
|
||||
ERR_FAIL_NULL_V(rt, Rect2i());
|
||||
|
||||
return rt->render_region;
|
||||
}
|
||||
|
||||
void TextureStorage::render_target_set_transparent(RID p_render_target, bool p_is_transparent) {
|
||||
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
|
||||
ERR_FAIL_NULL(rt);
|
||||
|
|
@ -3401,7 +3629,7 @@ void TextureStorage::render_target_do_msaa_resolve(RID p_render_target) {
|
|||
if (!rt->msaa_needs_resolve) {
|
||||
return;
|
||||
}
|
||||
RD::get_singleton()->draw_list_begin(rt->get_framebuffer(), RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_begin(rt->get_framebuffer());
|
||||
RD::get_singleton()->draw_list_end();
|
||||
rt->msaa_needs_resolve = false;
|
||||
}
|
||||
|
|
@ -3518,7 +3746,7 @@ void TextureStorage::render_target_do_clear_request(RID p_render_target) {
|
|||
}
|
||||
Vector<Color> clear_colors;
|
||||
clear_colors.push_back(rt->use_hdr ? rt->clear_color.srgb_to_linear() : rt->clear_color);
|
||||
RD::get_singleton()->draw_list_begin(rt->get_framebuffer(), RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, clear_colors);
|
||||
RD::get_singleton()->draw_list_begin(rt->get_framebuffer(), RD::DRAW_CLEAR_COLOR_0, clear_colors);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
rt->clear_requested = false;
|
||||
rt->msaa_needs_resolve = false;
|
||||
|
|
@ -4005,3 +4233,20 @@ RID TextureStorage::render_target_get_vrs_texture(RID p_render_target) const {
|
|||
|
||||
return rt->vrs_texture;
|
||||
}
|
||||
|
||||
RD::DataFormat TextureStorage::render_target_get_color_format(bool p_use_hdr, bool p_srgb) {
|
||||
if (p_use_hdr) {
|
||||
return RendererSceneRenderRD::get_singleton()->_render_buffers_get_color_format();
|
||||
} else {
|
||||
return p_srgb ? RD::DATA_FORMAT_R8G8B8A8_SRGB : RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t TextureStorage::render_target_get_color_usage_bits(bool p_msaa) {
|
||||
if (p_msaa) {
|
||||
return RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
} else {
|
||||
// FIXME: Storage bit should only be requested when FSR is required.
|
||||
return RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#ifndef TEXTURE_STORAGE_RD_H
|
||||
#define TEXTURE_STORAGE_RD_H
|
||||
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/paged_array.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h"
|
||||
|
|
@ -76,6 +75,23 @@ public:
|
|||
TYPE_3D
|
||||
};
|
||||
|
||||
struct CanvasTextureInfo {
|
||||
RID diffuse;
|
||||
RID normal;
|
||||
RID specular;
|
||||
RID sampler;
|
||||
Size2i size;
|
||||
Color specular_color;
|
||||
|
||||
bool use_normal = false;
|
||||
bool use_specular = false;
|
||||
|
||||
_FORCE_INLINE_ bool is_valid() const { return diffuse.is_valid(); }
|
||||
_FORCE_INLINE_ bool is_null() const { return diffuse.is_null(); }
|
||||
};
|
||||
|
||||
typedef void (*InvalidationCallback)(bool p_deleted, void *p_userdata);
|
||||
|
||||
private:
|
||||
friend class LightStorage;
|
||||
friend class MaterialStorage;
|
||||
|
|
@ -86,6 +102,12 @@ private:
|
|||
|
||||
/* Canvas Texture API */
|
||||
|
||||
struct CanvasTextureCache {
|
||||
RID diffuse;
|
||||
RID normal;
|
||||
RID specular;
|
||||
};
|
||||
|
||||
class CanvasTexture {
|
||||
public:
|
||||
RID diffuse;
|
||||
|
|
@ -96,14 +118,16 @@ private:
|
|||
|
||||
RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
|
||||
RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
|
||||
RID uniform_sets[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX][2];
|
||||
CanvasTextureCache info_cache[2];
|
||||
|
||||
InvalidationCallback invalidated_callback = nullptr;
|
||||
void *invalidated_callback_userdata = nullptr;
|
||||
|
||||
Size2i size_cache = Size2i(1, 1);
|
||||
bool use_normal_cache = false;
|
||||
bool use_specular_cache = false;
|
||||
bool cleared_cache = true;
|
||||
|
||||
void clear_sets();
|
||||
void clear_cache();
|
||||
~CanvasTexture();
|
||||
};
|
||||
|
||||
|
|
@ -174,7 +198,7 @@ private:
|
|||
|
||||
// Textures can be created from threads, so this RID_Owner is thread safe.
|
||||
mutable RID_Owner<Texture, true> texture_owner;
|
||||
Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); };
|
||||
Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); }
|
||||
|
||||
struct TextureToRDFormat {
|
||||
RD::DataFormat format;
|
||||
|
|
@ -369,6 +393,8 @@ private:
|
|||
RS::ViewportVRSUpdateMode vrs_update_mode = RS::VIEWPORT_VRS_UPDATE_ONCE;
|
||||
RID vrs_texture;
|
||||
|
||||
Rect2i render_region;
|
||||
|
||||
// overridden textures
|
||||
struct RTOverridden {
|
||||
RID color;
|
||||
|
|
@ -418,7 +444,7 @@ private:
|
|||
};
|
||||
|
||||
mutable RID_Owner<RenderTarget> render_target_owner;
|
||||
RenderTarget *get_render_target(RID p_rid) const { return render_target_owner.get_or_null(p_rid); };
|
||||
RenderTarget *get_render_target(RID p_rid) const { return render_target_owner.get_or_null(p_rid); }
|
||||
|
||||
void _clear_render_target(RenderTarget *rt);
|
||||
void _update_render_target(RenderTarget *rt);
|
||||
|
|
@ -465,7 +491,7 @@ public:
|
|||
|
||||
/* Canvas Texture API */
|
||||
|
||||
bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); };
|
||||
bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); }
|
||||
|
||||
virtual RID canvas_texture_allocate() override;
|
||||
virtual void canvas_texture_initialize(RID p_rid) override;
|
||||
|
|
@ -477,13 +503,12 @@ public:
|
|||
virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override;
|
||||
virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override;
|
||||
|
||||
bool canvas_texture_get_uniform_set(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, RID p_base_shader, int p_base_set, bool p_use_srgb, RID &r_uniform_set, Size2i &r_size, Color &r_specular_shininess, bool &r_use_normal, bool &r_use_specular, bool p_texture_is_data);
|
||||
CanvasTextureInfo canvas_texture_get_info(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, bool p_use_srgb, bool p_texture_is_data);
|
||||
void canvas_texture_set_invalidation_callback(RID p_canvas_texture, InvalidationCallback p_callback, void *p_userdata);
|
||||
|
||||
/* Texture API */
|
||||
|
||||
bool owns_texture(RID p_rid) const { return texture_owner.owns(p_rid); };
|
||||
|
||||
virtual bool can_create_resources_async() const override;
|
||||
bool owns_texture(RID p_rid) const { return texture_owner.owns(p_rid); }
|
||||
|
||||
virtual RID texture_allocate() override;
|
||||
virtual void texture_free(RID p_rid) override;
|
||||
|
|
@ -491,12 +516,21 @@ public:
|
|||
virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override;
|
||||
virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override;
|
||||
virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override;
|
||||
virtual void texture_external_initialize(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override;
|
||||
virtual void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent
|
||||
|
||||
virtual RID texture_create_from_native_handle(RS::TextureType p_type, Image::Format p_format, uint64_t p_native_handle, int p_width, int p_height, int p_depth, int p_layers = 1, RS::TextureLayeredType p_layered_type = RS::TEXTURE_LAYERED_2D_ARRAY) override;
|
||||
|
||||
virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override;
|
||||
virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override;
|
||||
virtual void texture_external_update(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override;
|
||||
virtual void texture_proxy_update(RID p_proxy, RID p_base) override;
|
||||
|
||||
Ref<Image> texture_2d_placeholder;
|
||||
Vector<Ref<Image>> texture_2d_array_placeholder;
|
||||
Vector<Ref<Image>> cubemap_placeholder;
|
||||
Vector<Ref<Image>> texture_3d_placeholder;
|
||||
|
||||
//these two APIs can be used together or in combination with the others.
|
||||
virtual void texture_2d_placeholder_initialize(RID p_texture) override;
|
||||
virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override;
|
||||
|
|
@ -563,7 +597,7 @@ public:
|
|||
|
||||
void update_decal_atlas();
|
||||
|
||||
bool owns_decal(RID p_rid) const { return decal_owner.owns(p_rid); };
|
||||
bool owns_decal(RID p_rid) const { return decal_owner.owns(p_rid); }
|
||||
|
||||
RID decal_atlas_get_texture() const;
|
||||
RID decal_atlas_get_texture_srgb() const;
|
||||
|
|
@ -703,7 +737,7 @@ public:
|
|||
|
||||
/* RENDER TARGET API */
|
||||
|
||||
bool owns_render_target(RID p_rid) const { return render_target_owner.owns(p_rid); };
|
||||
bool owns_render_target(RID p_rid) const { return render_target_owner.owns(p_rid); }
|
||||
|
||||
virtual RID render_target_create() override;
|
||||
virtual void render_target_free(RID p_rid) override;
|
||||
|
|
@ -752,15 +786,22 @@ public:
|
|||
virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override;
|
||||
virtual RID render_target_get_vrs_texture(RID p_render_target) const override;
|
||||
|
||||
virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture) override;
|
||||
virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) override;
|
||||
virtual RID render_target_get_override_color(RID p_render_target) const override;
|
||||
virtual RID render_target_get_override_depth(RID p_render_target) const override;
|
||||
RID render_target_get_override_depth_slice(RID p_render_target, const uint32_t p_layer) const;
|
||||
virtual RID render_target_get_override_velocity(RID p_render_target) const override;
|
||||
RID render_target_get_override_velocity_slice(RID p_render_target, const uint32_t p_layer) const;
|
||||
virtual RID render_target_get_override_velocity_depth(RID p_render_target) const override { return RID(); }
|
||||
|
||||
virtual void render_target_set_render_region(RID p_render_target, const Rect2i &p_render_region) override;
|
||||
virtual Rect2i render_target_get_render_region(RID p_render_target) const override;
|
||||
|
||||
virtual RID render_target_get_texture(RID p_render_target) override;
|
||||
|
||||
virtual void render_target_set_velocity_target_size(RID p_render_target, const Size2i &p_target_size) override {}
|
||||
virtual Size2i render_target_get_velocity_target_size(RID p_render_target) const override { return Size2i(0, 0); }
|
||||
|
||||
RID render_target_get_rd_framebuffer(RID p_render_target);
|
||||
RID render_target_get_rd_texture(RID p_render_target);
|
||||
RID render_target_get_rd_texture_slice(RID p_render_target, uint32_t p_layer);
|
||||
|
|
@ -773,6 +814,9 @@ public:
|
|||
|
||||
void render_target_set_framebuffer_uniform_set(RID p_render_target, RID p_uniform_set);
|
||||
void render_target_set_backbuffer_uniform_set(RID p_render_target, RID p_uniform_set);
|
||||
|
||||
static RD::DataFormat render_target_get_color_format(bool p_use_hdr, bool p_srgb);
|
||||
static uint32_t render_target_get_color_usage_bits(bool p_msaa);
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
|
|
|||
|
|
@ -329,3 +329,11 @@ Size2i Utilities::get_maximum_viewport_size() const {
|
|||
int max_y = device->limit_get(RenderingDevice::LIMIT_MAX_VIEWPORT_DIMENSIONS_Y);
|
||||
return Size2i(max_x, max_y);
|
||||
}
|
||||
|
||||
uint32_t Utilities::get_maximum_shader_varyings() const {
|
||||
return RenderingDevice::get_singleton()->limit_get(RenderingDevice::LIMIT_MAX_SHADER_VARYINGS);
|
||||
}
|
||||
|
||||
uint64_t Utilities::get_maximum_uniform_buffer_size() const {
|
||||
return RenderingDevice::get_singleton()->limit_get(RenderingDevice::LIMIT_MAX_UNIFORM_BUFFER_SIZE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ public:
|
|||
|
||||
/* VISIBILITY NOTIFIER */
|
||||
|
||||
VisibilityNotifier *get_visibility_notifier(RID p_rid) { return visibility_notifier_owner.get_or_null(p_rid); };
|
||||
bool owns_visibility_notifier(RID p_rid) const { return visibility_notifier_owner.owns(p_rid); };
|
||||
VisibilityNotifier *get_visibility_notifier(RID p_rid) { return visibility_notifier_owner.get_or_null(p_rid); }
|
||||
bool owns_visibility_notifier(RID p_rid) const { return visibility_notifier_owner.owns(p_rid); }
|
||||
|
||||
virtual RID visibility_notifier_allocate() override;
|
||||
virtual void visibility_notifier_initialize(RID p_notifier) override;
|
||||
|
|
@ -117,6 +117,8 @@ public:
|
|||
virtual String get_video_adapter_api_version() const override;
|
||||
|
||||
virtual Size2i get_maximum_viewport_size() const override;
|
||||
virtual uint32_t get_maximum_shader_varyings() const override;
|
||||
virtual uint64_t get_maximum_uniform_buffer_size() const override;
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue