summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/math/camera_matrix.cpp6
-rw-r--r--core/math/camera_matrix.h2
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp55
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h4
-rw-r--r--main/main.cpp1
-rw-r--r--servers/register_server_types.cpp7
-rw-r--r--servers/register_server_types.h1
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp97
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h13
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp20
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_storage_rd.h15
-rw-r--r--servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp3
-rw-r--r--servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.h4
-rw-r--r--servers/visual/rasterizer_rd/shaders/scene_forward.glsl56
-rw-r--r--servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl16
-rw-r--r--servers/visual/visual_server_viewport.cpp3
-rw-r--r--servers/visual_server.cpp5
17 files changed, 201 insertions, 107 deletions
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 380bae871a..9018a78c57 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -485,6 +485,12 @@ void CameraMatrix::invert() {
}
}
+void CameraMatrix::flip_y() {
+ for (int i = 0; i < 4; i++) {
+ matrix[1][i] = -matrix[1][i];
+ }
+}
+
CameraMatrix::CameraMatrix() {
set_identity();
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 2eed6d25d6..a7a85fee8d 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -90,6 +90,8 @@ struct CameraMatrix {
int get_pixels_per_meter(int p_for_pixel_width) const;
operator Transform() const;
+ void flip_y();
+
CameraMatrix();
CameraMatrix(const Transform &p_transform);
~CameraMatrix();
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 82ab8d6c2f..93e1b09cfd 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -1036,6 +1036,18 @@ uint32_t RenderingDeviceVulkan::get_compressed_image_format_pixel_rshift(DataFor
return 0;
}
+bool RenderingDeviceVulkan::format_has_stencil(DataFormat p_format) {
+ switch (p_format) {
+ case DATA_FORMAT_S8_UINT:
+ case DATA_FORMAT_D16_UNORM_S8_UINT:
+ case DATA_FORMAT_D24_UNORM_S8_UINT:
+ case DATA_FORMAT_D32_SFLOAT_S8_UINT: {
+ return true;
+ }
+ }
+ return false;
+}
+
uint32_t RenderingDeviceVulkan::get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw, uint32_t *r_blockh, uint32_t *r_depth) {
ERR_FAIL_COND_V(p_mipmaps == 0, 0);
@@ -1699,7 +1711,12 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
//set bound and unbound layouts
if (p_format.usage_bits & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
- texture.aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT;
+
+ texture.read_aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT;
+ texture.barrier_aspect_mask = texture.read_aspect_mask;
+ if (format_has_stencil(p_format.format)) {
+ texture.barrier_aspect_mask |= VK_IMAGE_ASPECT_STENCIL_BIT;
+ }
if (p_format.usage_bits & TEXTURE_USAGE_SAMPLING_BIT) {
texture.unbound_layout = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
@@ -1710,7 +1727,9 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
} else if (p_format.usage_bits & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) {
- texture.aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
+ texture.read_aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
+ texture.barrier_aspect_mask = texture.read_aspect_mask;
+
if (p_format.usage_bits & TEXTURE_USAGE_SAMPLING_BIT) {
texture.unbound_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} else {
@@ -1718,7 +1737,9 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
}
texture.bound_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
} else {
- texture.aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
+ texture.read_aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
+ texture.barrier_aspect_mask = texture.read_aspect_mask;
+
texture.unbound_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
texture.bound_layout = VK_IMAGE_LAYOUT_UNDEFINED; //will never be bound
}
@@ -1794,7 +1815,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = texture.image;
- image_memory_barrier.subresourceRange.aspectMask = texture.aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = texture.barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = image_create_info.mipLevels;
image_memory_barrier.subresourceRange.baseArrayLayer = 0;
@@ -2053,7 +2074,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = texture->image;
- image_memory_barrier.subresourceRange.aspectMask = texture->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = texture->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = texture->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
@@ -2156,7 +2177,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
buffer_image_copy.bufferRowLength = 0; //tigthly packed
buffer_image_copy.bufferImageHeight = 0; //tigthly packed
- buffer_image_copy.imageSubresource.aspectMask = texture->aspect_mask;
+ buffer_image_copy.imageSubresource.aspectMask = texture->read_aspect_mask;
buffer_image_copy.imageSubresource.mipLevel = mm_i;
buffer_image_copy.imageSubresource.baseArrayLayer = p_layer;
buffer_image_copy.imageSubresource.layerCount = 1;
@@ -2191,7 +2212,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = texture->image;
- image_memory_barrier.subresourceRange.aspectMask = texture->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = texture->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = texture->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
@@ -2340,7 +2361,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = tex->image;
- image_memory_barrier.subresourceRange.aspectMask = tex->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = tex->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
@@ -2379,7 +2400,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3
get_image_format_required_size(tex->format, tex->width, tex->height, tex->depth, i + 1, &mm_width, &mm_height, &mm_depth);
VkImageCopy image_copy_region;
- image_copy_region.srcSubresource.aspectMask = tex->aspect_mask;
+ image_copy_region.srcSubresource.aspectMask = tex->read_aspect_mask;
image_copy_region.srcSubresource.baseArrayLayer = p_layer;
image_copy_region.srcSubresource.layerCount = 1;
image_copy_region.srcSubresource.mipLevel = i;
@@ -2416,7 +2437,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = tex->image;
- image_memory_barrier.subresourceRange.aspectMask = tex->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = tex->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
@@ -2528,7 +2549,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = src_tex->image;
- image_memory_barrier.subresourceRange.aspectMask = src_tex->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = p_src_mipmap;
image_memory_barrier.subresourceRange.levelCount = 1;
image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer;
@@ -2548,7 +2569,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = dst_tex->image;
- image_memory_barrier.subresourceRange.aspectMask = dst_tex->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = dst_tex->read_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = p_dst_mipmap;
image_memory_barrier.subresourceRange.levelCount = 1;
image_memory_barrier.subresourceRange.baseArrayLayer = p_dst_layer;
@@ -2562,7 +2583,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
{
VkImageCopy image_copy_region;
- image_copy_region.srcSubresource.aspectMask = src_tex->aspect_mask;
+ image_copy_region.srcSubresource.aspectMask = src_tex->read_aspect_mask;
image_copy_region.srcSubresource.baseArrayLayer = p_src_layer;
image_copy_region.srcSubresource.layerCount = 1;
image_copy_region.srcSubresource.mipLevel = p_src_mipmap;
@@ -2570,7 +2591,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_copy_region.srcOffset.y = p_from.y;
image_copy_region.srcOffset.z = p_from.z;
- image_copy_region.dstSubresource.aspectMask = src_tex->aspect_mask;
+ image_copy_region.dstSubresource.aspectMask = src_tex->barrier_aspect_mask;
image_copy_region.dstSubresource.baseArrayLayer = p_dst_layer;
image_copy_region.dstSubresource.layerCount = 1;
image_copy_region.dstSubresource.mipLevel = p_dst_mipmap;
@@ -2598,7 +2619,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = src_tex->image;
- image_memory_barrier.subresourceRange.aspectMask = src_tex->aspect_mask;
+ image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = p_src_mipmap;
image_memory_barrier.subresourceRange.levelCount = src_tex->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer;
@@ -3672,12 +3693,12 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages
Vector<SpvReflectInterfaceVariable *> input_vars;
input_vars.resize(iv_count);
- result = spvReflectEnumerateOutputVariables(&module, &iv_count, input_vars.ptrw());
+ result = spvReflectEnumerateInputVariables(&module, &iv_count, input_vars.ptrw());
ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(),
"Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed obtaining input variables.");
for (uint32_t j = 0; j < iv_count; j++) {
- if (input_vars[j]) {
+ if (input_vars[j] && input_vars[j]->decoration_flags == 0) { //regular input
vertex_input_mask |= (1 << uint32_t(input_vars[j]->location));
}
}
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index 2cd72fbac4..e2b43d9aeb 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -80,6 +80,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format);
static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = NULL, uint32_t *r_blockh = NULL, uint32_t *r_depth = NULL);
static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth);
+ static bool format_has_stencil(DataFormat p_format);
/***************************/
/**** ID INFRASTRUCTURE ****/
@@ -139,7 +140,8 @@ class RenderingDeviceVulkan : public RenderingDevice {
VkImageLayout bound_layout; //layout used when bound to framebuffer being drawn
VkImageLayout unbound_layout; //layout used otherwise
- uint32_t aspect_mask;
+ uint32_t read_aspect_mask;
+ uint32_t barrier_aspect_mask;
bool bound; //bound to framebffer
RID owner;
};
diff --git a/main/main.cpp b/main/main.cpp
index fff652edc8..02c90ce1ee 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1208,6 +1208,7 @@ error:
Error Main::setup2(Thread::ID p_main_tid_override) {
preregister_module_types();
+ preregister_server_types();
// Print engine name and version
print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp
index f25ef4ae84..25d122604a 100644
--- a/servers/register_server_types.cpp
+++ b/servers/register_server_types.cpp
@@ -109,6 +109,10 @@ static bool has_server_feature_callback(const String &p_feature) {
return false;
}
+void preregister_server_types() {
+ shader_types = memnew(ShaderTypes);
+}
+
void register_server_types() {
OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback);
@@ -120,8 +124,6 @@ void register_server_types() {
ClassDB::register_class<ARVRServer>();
ClassDB::register_class<CameraServer>();
- shader_types = memnew(ShaderTypes);
-
ClassDB::register_virtual_class<ARVRInterface>();
ClassDB::register_class<ARVRPositionalTracker>();
@@ -210,6 +212,7 @@ void unregister_server_types() {
}
void register_server_singletons() {
+
Engine::get_singleton()->add_singleton(Engine::Singleton("VisualServer", VisualServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
diff --git a/servers/register_server_types.h b/servers/register_server_types.h
index 0988f8cd94..7d1dad37af 100644
--- a/servers/register_server_types.h
+++ b/servers/register_server_types.h
@@ -31,6 +31,7 @@
#ifndef REGISTER_SERVER_TYPES_H
#define REGISTER_SERVER_TYPES_H
+void preregister_server_types();
void register_server_types();
void unregister_server_types();
diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp
index f63ceb9dfa..1eb0ab3d8d 100644
--- a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp
+++ b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp
@@ -92,7 +92,7 @@ void RasterizerSceneForwardRD::ShaderData::set_code(const String &p_code) {
ShaderCompilerRD::GeneratedCode gen_code;
int blend_mode = BLEND_MODE_MIX;
- int depth_test = DEPTH_TEST_ENABLED;
+ int depth_testi = DEPTH_TEST_ENABLED;
int cull = CULL_BACK;
uses_point_size = false;
@@ -127,7 +127,7 @@ void RasterizerSceneForwardRD::ShaderData::set_code(const String &p_code) {
actions.render_mode_values["depth_draw_opaque"] = Pair<int *, int>(&depth_drawi, DEPTH_DRAW_OPAQUE);
actions.render_mode_values["depth_draw_always"] = Pair<int *, int>(&depth_drawi, DEPTH_DRAW_ALWAYS);
- actions.render_mode_values["depth_test_disabled"] = Pair<int *, int>(&depth_test, DEPTH_TEST_DISABLED);
+ actions.render_mode_values["depth_test_disabled"] = Pair<int *, int>(&depth_testi, DEPTH_TEST_DISABLED);
actions.render_mode_values["cull_disabled"] = Pair<int *, int>(&cull, CULL_DISABLED);
actions.render_mode_values["cull_front"] = Pair<int *, int>(&cull, CULL_FRONT);
@@ -161,7 +161,7 @@ void RasterizerSceneForwardRD::ShaderData::set_code(const String &p_code) {
RasterizerSceneForwardRD *scene_singleton = (RasterizerSceneForwardRD *)RasterizerSceneForwardRD::singleton;
- Error err = scene_singleton->shader.compiler.compile(VS::SHADER_CANVAS_ITEM, code, &actions, path, gen_code);
+ Error err = scene_singleton->shader.compiler.compile(VS::SHADER_SPATIAL, code, &actions, path, gen_code);
ERR_FAIL_COND(err != OK);
@@ -170,6 +170,7 @@ void RasterizerSceneForwardRD::ShaderData::set_code(const String &p_code) {
}
depth_draw = DepthDraw(depth_drawi);
+ depth_test = DepthTest(depth_testi);
#if 0
print_line("**compiling shader:");
@@ -257,8 +258,6 @@ void RasterizerSceneForwardRD::ShaderData::set_code(const String &p_code) {
depth_stencil_state.enable_depth_write = depth_draw != DEPTH_DRAW_DISABLED ? true : false;
}
- bool first = true;
-
for (int i = 0; i < CULL_VARIANT_MAX; i++) {
RD::PolygonCullMode cull_mode_rd_table[3][CULL_VARIANT_MAX] = {
@@ -321,11 +320,6 @@ void RasterizerSceneForwardRD::ShaderData::set_code(const String &p_code) {
}
RID shader_variant = scene_singleton->shader.scene_shader.version_get_shader(version, k);
-
- if (first) {
- //should be the same for all, so..
- vertex_input_mask = RD::get_singleton()->shader_get_vertex_input_attribute_mask(shader_variant);
- }
pipelines[i][j][k].setup(shader_variant, primitive_rd, raster_state, RD::PipelineMultisampleState(), depth_stencil, blend_state, 0);
}
}
@@ -586,6 +580,7 @@ bool RasterizerSceneForwardRD::free(RID p_rid) {
void RasterizerSceneForwardRD::instance_create_custom_data(InstanceBase *p_instance) {
InstanceGeometryData *geom_data = memnew(InstanceGeometryData);
geom_data->ubo = RD::get_singleton()->uniform_buffer_create(sizeof(InstanceGeometryData::UBO));
+ p_instance->custom_data = geom_data;
}
void RasterizerSceneForwardRD::instance_free_custom_data(InstanceBase *p_instance) {
@@ -650,6 +645,10 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
RID prev_vertex_array_rd;
RID prev_index_array_rd;
+ RID prev_pipeline_rd;
+
+ PushConstant push_constant;
+ zeromem(&push_constant, sizeof(PushConstant));
for (int i = 0; i < p_element_count; i++) {
@@ -673,40 +672,25 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
//find primitive and vertex format
VS::PrimitiveType primitive;
- RD::VertexFormatID vertex_format;
- RID vertex_array_rd;
- RID index_array_rd;
- RID prev_pipeline_rd;
switch (e->instance->base_type) {
case VS::INSTANCE_MESH: {
- storage->mesh_get_arrays_primitive_and_format(e->instance->base, e->surface_index, shader->vertex_input_mask, primitive, vertex_array_rd, index_array_rd, vertex_format);
+ primitive = storage->mesh_surface_get_primitive(e->instance->base, e->surface_index);
} break;
case VS::INSTANCE_MULTIMESH: {
-
+ ERR_CONTINUE(true); //should be a bug
} break;
case VS::INSTANCE_IMMEDIATE: {
-
+ ERR_CONTINUE(true); //should be a bug
} break;
case VS::INSTANCE_PARTICLES: {
-
+ ERR_CONTINUE(true); //should be a bug
} break;
default: {
ERR_CONTINUE(true); //should be a bug
}
}
- if (prev_vertex_array_rd != vertex_array_rd) {
- RD::get_singleton()->draw_list_bind_vertex_array(draw_list, vertex_array_rd);
- prev_vertex_array_rd = vertex_array_rd;
- }
- if (prev_index_array_rd != index_array_rd) {
- if (index_array_rd.is_valid()) {
- RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array_rd);
- }
- prev_index_array_rd = index_array_rd;
- }
-
InstanceGeometryData *geom_data = (InstanceGeometryData *)e->instance->custom_data;
ShaderVersion shader_version;
@@ -726,7 +710,7 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
instance_uniform_set = geom_data->uniform_set_gi;
shader_version = SHADER_VERSION_VCT_COLOR_PASS;
} else {
- instance_uniform_set = geom_data->uniform_set_base;
+ instance_uniform_set = geom_data->uniform_set_gi;
shader_version = SHADER_VERSION_COLOR_PASS;
}
} break;
@@ -741,7 +725,7 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
instance_uniform_set = geom_data->uniform_set_gi;
shader_version = SHADER_VERSION_VCT_COLOR_PASS_WITH_SEPARATE_SPECULAR;
} else {
- instance_uniform_set = geom_data->uniform_set_base;
+ instance_uniform_set = geom_data->uniform_set_gi;
shader_version = SHADER_VERSION_COLOR_PASS_WITH_SEPARATE_SPECULAR;
}
} break;
@@ -767,6 +751,40 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
pipeline = &shader->pipelines[cull_variant][primitive][shader_version];
+ RD::VertexFormatID vertex_format;
+ RID vertex_array_rd;
+ RID index_array_rd;
+
+ switch (e->instance->base_type) {
+ case VS::INSTANCE_MESH: {
+ storage->mesh_surface_get_arrays_and_format(e->instance->base, e->surface_index, pipeline->get_vertex_input_mask(), vertex_array_rd, index_array_rd, vertex_format);
+ } break;
+ case VS::INSTANCE_MULTIMESH: {
+ ERR_CONTINUE(true); //should be a bug
+ } break;
+ case VS::INSTANCE_IMMEDIATE: {
+ ERR_CONTINUE(true); //should be a bug
+ } break;
+ case VS::INSTANCE_PARTICLES: {
+ ERR_CONTINUE(true); //should be a bug
+ } break;
+ default: {
+ ERR_CONTINUE(true); //should be a bug
+ }
+ }
+
+ if (prev_vertex_array_rd != vertex_array_rd) {
+ RD::get_singleton()->draw_list_bind_vertex_array(draw_list, vertex_array_rd);
+ prev_vertex_array_rd = vertex_array_rd;
+ }
+
+ if (prev_index_array_rd != index_array_rd) {
+ if (index_array_rd.is_valid()) {
+ RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array_rd);
+ }
+ prev_index_array_rd = index_array_rd;
+ }
+
RID pipeline_rd = pipeline->get_render_pipeline(vertex_format, framebuffer_format);
if (pipeline_rd != prev_pipeline_rd) {
@@ -787,6 +805,8 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, instance_uniform_set, 3);
+ RD::get_singleton()->draw_list_set_push_constant(draw_list, &push_constant, sizeof(PushConstant));
+
switch (e->instance->base_type) {
case VS::INSTANCE_MESH: {
RD::get_singleton()->draw_list_draw(draw_list, index_array_rd.is_valid());
@@ -810,9 +830,12 @@ void RasterizerSceneForwardRD::_render_list(RenderingDevice::DrawListID p_draw_l
void RasterizerSceneForwardRD::_setup_environment(RID p_environment, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform, bool p_no_fog) {
Transform sky_orientation;
+ CameraMatrix projection = p_cam_projection;
+ projection.flip_y();
+
//store camera into ubo
- store_camera(p_cam_projection, scene_state.ubo.projection_matrix);
- store_camera(p_cam_projection.inverse(), scene_state.ubo.inv_projection_matrix);
+ store_camera(projection, scene_state.ubo.projection_matrix);
+ store_camera(projection.inverse(), scene_state.ubo.inv_projection_matrix);
store_transform(p_cam_transform, scene_state.ubo.camera_matrix);
store_transform(p_cam_transform.affine_inverse(), scene_state.ubo.inv_camera_matrix);
@@ -1063,9 +1086,9 @@ void RasterizerSceneForwardRD::_fill_render_list(InstanceBase **p_cull_result, i
store_transform(inst->transform, ubo.transform);
store_transform_3x3(inst->transform.basis.inverse().transposed(), ubo.normal_transform);
ubo.flags = 0;
- ubo.pad[0];
- ubo.pad[1];
- ubo.pad[2];
+ ubo.pad[0] = 0;
+ ubo.pad[1] = 0;
+ ubo.pad[2] = 0;
RD::get_singleton()->buffer_update(geom_data->ubo, 0, sizeof(InstanceGeometryData::UBO), &ubo, true);
}
@@ -1723,6 +1746,7 @@ void RasterizerSceneForwardRD::_render_scene(RenderBufferData *p_buffer_data, co
RasterizerEffectsRD *effects = storage->get_effects();
effects->copy(render_buffer->color, storage->render_target_get_rd_framebuffer(render_buffer->render_target), Rect2());
+ storage->render_target_disable_clear_request(render_buffer->render_target);
#if 0
_post_process(env, p_cam_projection);
@@ -1793,6 +1817,7 @@ void RasterizerSceneForwardRD::set_time(double p_time) {
}
RasterizerSceneForwardRD::RasterizerSceneForwardRD(RasterizerStorageRD *p_storage) {
+ singleton = this;
storage = p_storage;
/* SHADER */
diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h
index e09e42b1f3..299cd178e1 100644
--- a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h
+++ b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h
@@ -194,6 +194,19 @@ class RasterizerSceneForwardRD : public RasterizerSceneRD {
bool using_vct_gi = false;
};
+ /* Push Constant */
+
+ struct PushConstant {
+ uint32_t reflection_probe_count;
+ uint32_t omni_light_count;
+ uint32_t spot_light_count;
+ uint32_t decal_count;
+ float reflection_probe_indices[4];
+ float omni_light_indices[4];
+ float spot_light_indices[4];
+ float decal_indices[4];
+ };
+
/* Framebuffer */
struct RenderBufferDataForward : public RenderBufferData {
diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp
index 5351af7c90..61f9a373a8 100644
--- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp
+++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp
@@ -1939,17 +1939,12 @@ void RasterizerStorageRD::_mesh_surface_generate_version_for_input_mask(Mesh::Su
for (int i = 0; i < VS::ARRAY_WEIGHTS; i++) {
- if (!(p_input_mask & (1 << i))) {
- continue; // Shader does not need this, skip it
- }
-
RD::VertexDescription vd;
RID buffer;
vd.location = i;
if (!(s->format & (1 << i))) {
- // Shader needs this, but it's not provided by this surface
- // Create a default attribue using the default buffers
+ // Not supplied by surface, use default value
buffer = mesh_default_rd_buffers[i];
switch (i) {
@@ -1986,7 +1981,7 @@ void RasterizerStorageRD::_mesh_surface_generate_version_for_input_mask(Mesh::Su
} break;
}
} else {
- //Shader needs this, and it's also provided
+ //Supplied, use it
vd.offset = stride;
vd.stride = 1; //mark that it needs a stride set
@@ -2072,6 +2067,10 @@ void RasterizerStorageRD::_mesh_surface_generate_version_for_input_mask(Mesh::Su
}
}
+ if (!(p_input_mask & (1 << i))) {
+ continue; // Shader does not need this, skip it
+ }
+
attributes.push_back(vd);
buffers.push_back(buffer);
}
@@ -2436,6 +2435,13 @@ void RasterizerStorageRD::base_update_dependency(RID p_base, RasterizerScene::In
}
}
+VS::InstanceType RasterizerStorageRD::get_base_type(RID p_rid) const {
+
+ if (mesh_owner.owns(p_rid)) {
+ return VS::INSTANCE_MESH;
+ }
+ return VS::INSTANCE_NONE;
+}
void RasterizerStorageRD::update_dirty_resources() {
_update_queued_materials();
}
diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.h b/servers/visual/rasterizer_rd/rasterizer_storage_rd.h
index 729e8b6556..dca270746b 100644
--- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.h
+++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.h
@@ -485,7 +485,15 @@ public:
return mesh->material_cache.ptr();
}
- _FORCE_INLINE_ void mesh_get_arrays_primitive_and_format(RID p_mesh, uint32_t p_surface_index, uint32_t p_input_mask, VS::PrimitiveType &r_primitive, RID &r_vertex_array_rd, RID &r_index_array_rd, RD::VertexFormatID &r_vertex_format) {
+ _FORCE_INLINE_ VS::PrimitiveType mesh_surface_get_primitive(RID p_mesh, uint32_t p_surface_index) {
+ Mesh *mesh = mesh_owner.getornull(p_mesh);
+ ERR_FAIL_COND_V(!mesh, VS::PRIMITIVE_MAX);
+ ERR_FAIL_INDEX_V(p_surface_index, mesh->surface_count, VS::PRIMITIVE_MAX);
+
+ return mesh->surfaces[p_surface_index]->primitive;
+ }
+
+ _FORCE_INLINE_ void mesh_surface_get_arrays_and_format(RID p_mesh, uint32_t p_surface_index, uint32_t p_input_mask, RID &r_vertex_array_rd, RID &r_index_array_rd, RD::VertexFormatID &r_vertex_format) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
ERR_FAIL_INDEX(p_surface_index, mesh->surface_count);
@@ -772,10 +780,7 @@ public:
Size2 render_target_get_size(RID p_render_target);
RID render_target_get_rd_framebuffer(RID p_render_target);
- VS::InstanceType get_base_type(RID p_rid) const {
-
- return VS::INSTANCE_NONE;
- }
+ VS::InstanceType get_base_type(RID p_rid) const;
bool free(RID p_rid);
diff --git a/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp b/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp
index b2cb6a1634..aef6f07b2f 100644
--- a/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp
+++ b/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp
@@ -65,6 +65,7 @@ void RenderPipelineVertexFormatCacheRD::setup(RID p_shader, RD::RenderPrimitive
ERR_FAIL_COND(p_shader.is_null());
_clear();
shader = p_shader;
+ input_mask = RD::get_singleton()->shader_get_vertex_input_attribute_mask(p_shader);
render_primitive = p_primitive;
rasterization_state = p_rasterization_state;
multisample_state = p_multisample;
@@ -82,11 +83,13 @@ void RenderPipelineVertexFormatCacheRD::update_shader(RID p_shader) {
void RenderPipelineVertexFormatCacheRD::clear() {
_clear();
shader = RID(); //clear shader
+ input_mask = 0;
}
RenderPipelineVertexFormatCacheRD::RenderPipelineVertexFormatCacheRD() {
version_count = 0;
versions = NULL;
+ input_mask = 0;
}
RenderPipelineVertexFormatCacheRD::~RenderPipelineVertexFormatCacheRD() {
diff --git a/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.h b/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.h
index 9faa466eae..2c3de2dbed 100644
--- a/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.h
+++ b/servers/visual/rasterizer_rd/render_pipeline_vertex_format_cache_rd.h
@@ -36,6 +36,7 @@
class RenderPipelineVertexFormatCacheRD {
RID shader;
+ uint32_t input_mask;
RD::FramebufferFormatID framebuffer_format;
RD::RenderPrimitive render_primitive;
@@ -75,6 +76,9 @@ public:
return _generate_version(p_vertex_format_id, p_framebuffer_format_id);
}
+ _FORCE_INLINE_ uint32_t get_vertex_input_mask() const {
+ return input_mask;
+ }
void clear();
RenderPipelineVertexFormatCacheRD();
~RenderPipelineVertexFormatCacheRD();
diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl
index c18fead23e..57fcd049b5 100644
--- a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl
+++ b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl
@@ -8,6 +8,9 @@
VERSION_DEFINES
/* clang-format on */
+#include "scene_forward_inc.glsl"
+
+
/* INPUT ATTRIBS */
layout(location = 0) in vec3 vertex_attrib;
@@ -33,25 +36,24 @@ layout(location = 6) in uvec4 bone_attrib; // always bound, even if unused
/* Varyings */
-out vec3 vertex_interp;
-out vec3 normal_interp;
+layout(location = 0) out vec3 vertex_interp;
+layout(location = 1) out vec3 normal_interp;
#if defined(COLOR_USED)
-out vec4 color_interp;
+layout(location = 2) out vec4 color_interp;
#endif
-#if defined(UV2_USED) || defined(USE_LIGHTMAP)
-out vec2 uv_interp;
+#if defined(UV_USED)
+layout(location = 3) out vec4 uv_interp;
#endif
-//uv2 may be used for lightmapping, so always pass.
-#if !defined(MODE_RENDER_DEPTH)
-out vec2 uv2_interp;
+#if defined(UV2_USED) || defined(USE_LIGHTMAP)
+layout(location = 4) out vec2 uv2_interp;
#endif
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
-out vec3 tangent_interp;
-out vec3 binormal_interp;
+layout(location = 5) out vec3 tangent_interp;
+layout(location = 6) out vec3 binormal_interp;
#endif
#ifdef USE_MATERIAL_UNIFORMS
@@ -152,7 +154,7 @@ VERTEX_SHADER_CODE
binormal = modelview_normal * binormal;
tangent = modelview_normal * tangent;
#endif
-#endif
+
//using world coordinates
#if !defined(SKIP_TRANSFORM_USED) && defined(VERTEX_WORLD_COORDS_USED)
@@ -184,7 +186,7 @@ VERTEX_SHADER_CODE
#endif //MODE_RENDER_DEPTH
#ifdef USE_OVERRIDE_POSITION
- gl_Position = position;
+ gl_Position = position;;
#else
gl_Position = projection_matrix * vec4(vertex_interp, 1.0);
#endif
@@ -201,29 +203,30 @@ VERTEX_SHADER_CODE
VERSION_DEFINES
/* clang-format on */
+#include "scene_forward_inc.glsl"
/* Varyings */
+layout(location = 0) in vec3 vertex_interp;
+layout(location = 1) in vec3 normal_interp;
+
#if defined(COLOR_USED)
-in vec4 color_interp;
+layout(location = 2) in vec4 color_interp;
#endif
#if defined(UV_USED)
-in vec2 uv_interp;
+layout(location = 3) in vec4 uv_interp;
#endif
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
-in vec2 uv2_interp;
+layout(location = 4) in vec2 uv2_interp;
#endif
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
-in vec3 tangent_interp;
-in vec3 binormal_interp;
+layout(location = 5) in vec3 tangent_interp;
+layout(location = 6) in vec3 binormal_interp;
#endif
-in highp vec3 vertex_interp;
-in vec3 normal_interp;
-
//defines to keep compatibility with vertex
#define world_matrix instance_data.transform;
@@ -583,11 +586,9 @@ void main() {
vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
#endif
-#if defined(SSS_USED)
float sss_strength = 0.0;
-#endif
-#define
+
{
/* clang-format off */
@@ -680,7 +681,7 @@ FRAGMENT_SHADER_CODE
const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
vec4 r = roughness * c0 + c1;
- float ndotv = clamp(dot(normal, eye_vec), 0.0, 1.0);
+ float ndotv = clamp(dot(normal, view), 0.0, 1.0);
float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
@@ -718,7 +719,7 @@ FRAGMENT_SHADER_CODE
//nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
#else
- specular_light *= reflection_multiplier;
+ specular_light *= scene_data.reflection_multiplier;
ambient_light *= albedo; //ambient must be multiplied by albedo at the end
#if defined(ENABLE_AO)
@@ -742,7 +743,7 @@ FRAGMENT_SHADER_CODE
#else
- diffuse_buffer = vec4(emission + diffuse_light + ambient_light, sss_strenght);
+ diffuse_buffer = vec4(emission + diffuse_light + ambient_light, sss_strength);
specular_buffer = vec4(specular_light, metallic);
#endif
@@ -752,7 +753,8 @@ FRAGMENT_SHADER_CODE
#ifdef USE_NO_SHADING
frag_color = vec4(albedo, alpha);
#else
- frag_color = vec4(emission + ambient_light + diffuse_light + specular_light, alpha);
+ //frag_color = vec4(emission + ambient_light + diffuse_light + specular_light, alpha);
+ frag_color = vec4(1.0);
#endif //USE_NO_SHADING
diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl
index 189371c2c0..c481ddf8f4 100644
--- a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl
+++ b/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl
@@ -4,9 +4,9 @@
/* Set 0 Scene data, screen and sources (changes the least) */
-layout(set=0,location=1) uniform texture2D depth_buffer;
-layout(set=0,location=2) uniform texture2D color_buffer;
-layout(set=0,location=3) uniform texture2D normal_buffer;
+layout(set=0,binding=1) uniform texture2D depth_buffer;
+layout(set=0,binding=2) uniform texture2D color_buffer;
+layout(set=0,binding=3) uniform texture2D normal_buffer;
layout(set=0,binding=4,std140) uniform SceneData {
@@ -105,19 +105,23 @@ layout(set = 1, binding = 1) uniform textureBuffer skeleton_bones;
layout(push_constant, binding = 0, std430) uniform DrawData {
//used in forward rendering, 16 bits indices, max 8
+ uint reflection_probe_count;
+ uint omni_light_count;
+ uint spot_light_count;
+ uint decal_count;
uvec4 reflection_probe_indices;
uvec4 omni_light_indices;
uvec4 spot_light_indices;
uvec4 decal_indices;
} draw_data;
-layout(set = 3 binding = 0, std140) uniform InstanceData {
+layout(set = 3, binding = 0, std140) uniform InstanceData {
mat4 transform;
mat3 normal_transform;
uint flags;
uint pad0;
- uint pad0;
- uint pad0;
+ uint pad1;
+ uint pad2;
} instance_data;
layout(set = 3, binding = 1) uniform textureBuffer multimesh_transforms;
diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp
index 0baf2032bc..5d2441be7b 100644
--- a/servers/visual/visual_server_viewport.cpp
+++ b/servers/visual/visual_server_viewport.cpp
@@ -63,6 +63,7 @@ static Transform2D _canvas_get_transform(VisualServerViewport::Viewport *p_viewp
}
void VisualServerViewport::_draw_3d(Viewport *p_viewport, ARVRInterface::Eyes p_eye) {
+
Ref<ARVRInterface> arvr_interface;
if (ARVRServer::get_singleton() != NULL) {
arvr_interface = ARVRServer::get_singleton()->get_primary_interface();
@@ -95,7 +96,7 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface::E
}
}
- bool can_draw_3d = !VSG::scene->camera_owner.owns(p_viewport->camera);
+ bool can_draw_3d = VSG::scene->camera_owner.owns(p_viewport->camera);
if (p_viewport->clear_mode != VS::VIEWPORT_CLEAR_NEVER) {
if (p_viewport->transparent_bg) {
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 60822f1746..7aa2160545 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -935,11 +935,6 @@ Error VisualServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surface_
elem_size *= sizeof(float);
}
- if (elem_size == 6) {
- //had to pad
- elem_size = 8;
- }
-
} break;
case VS::ARRAY_NORMAL: {