Add basic lighting to GLES3 renderer.

This includes all three light types and IBL, but does not include shadows or any form of GI
This commit is contained in:
clayjohn 2022-05-16 11:56:03 -07:00
parent 23207fcfdd
commit 9b61c855ef
18 changed files with 1548 additions and 539 deletions

View file

@ -1024,6 +1024,7 @@ MaterialData::~MaterialData() {
if (uniform_buffer) {
glDeleteBuffers(1, &uniform_buffer);
uniform_buffer = 0;
}
}
@ -1677,9 +1678,6 @@ ShaderCompiler::DefaultIdentifierActions actions;
//shaders.copy.initialize();
//shaders.copy_version = shaders.copy.version_create(); //TODO
//shaders.copy.version_bind_shader(shaders.copy_version, CopyShaderGLES3::MODE_COPY_SECTION);
//shaders.cubemap_filter.init();
//bool ggx_hq = GLOBAL_GET("rendering/quality/reflections/high_quality_ggx");
//shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::LOW_QUALITY, !ggx_hq);
}
MaterialStorage::~MaterialStorage() {
@ -3133,6 +3131,7 @@ GLES3::ShaderData *GLES3::_create_sky_shader_func() {
// Sky material
void SkyMaterialData::update_parameters(const HashMap<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) {
uniform_set_updated = true;
return update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size);
}

View file

@ -45,6 +45,7 @@
#include "drivers/gles3/shaders/copy.glsl.gen.h"
#include "../shaders/canvas.glsl.gen.h"
#include "../shaders/cubemap_filter.glsl.gen.h"
#include "../shaders/scene.glsl.gen.h"
#include "../shaders/sky.glsl.gen.h"
@ -56,6 +57,7 @@ struct Shaders {
CanvasShaderGLES3 canvas_shader;
SkyShaderGLES3 sky_shader;
SceneShaderGLES3 scene_shader;
CubemapFilterShaderGLES3 cubemap_filter_shader;
ShaderCompiler compiler_canvas;
ShaderCompiler compiler_scene;
@ -241,6 +243,7 @@ ShaderData *_create_sky_shader_func();
struct SkyMaterialData : public MaterialData {
SkyShaderData *shader_data = nullptr;
bool uniform_set_updated = false;
virtual void set_render_priority(int p_priority) {}
virtual void set_next_pass(RID p_pass) {}
@ -458,8 +461,6 @@ private:
SelfList<Material>::List material_update_list;
//static void _material_uniform_set_erased(void *p_material);
public:
static MaterialStorage *get_singleton();

View file

@ -570,24 +570,29 @@ void MeshStorage::mesh_clear(RID p_mesh) {
if (s.vertex_buffer != 0) {
glDeleteBuffers(1, &s.vertex_buffer);
s.vertex_buffer = 0;
}
if (s.version_count != 0) {
for (uint32_t j = 0; j < s.version_count; j++) {
glDeleteVertexArrays(1, &s.versions[j].vertex_array);
s.versions[j].vertex_array = 0;
}
}
if (s.attribute_buffer != 0) {
glDeleteBuffers(1, &s.attribute_buffer);
s.attribute_buffer = 0;
}
if (s.skin_buffer != 0) {
glDeleteBuffers(1, &s.skin_buffer);
s.skin_buffer = 0;
}
if (s.index_buffer != 0) {
glDeleteBuffers(1, &s.index_buffer);
s.index_buffer = 0;
}
memdelete(mesh->surfaces[i]);
}
@ -804,17 +809,20 @@ void MeshStorage::_mesh_instance_clear(MeshInstance *mi) {
if (mi->surfaces[i].version_count != 0) {
for (uint32_t j = 0; j < mi->surfaces[i].version_count; j++) {
glDeleteVertexArrays(1, &mi->surfaces[i].versions[j].vertex_array);
mi->surfaces[i].versions[j].vertex_array = 0;
}
memfree(mi->surfaces[i].versions);
}
if (mi->surfaces[i].vertex_buffer != 0) {
glDeleteBuffers(1, &mi->surfaces[i].vertex_buffer);
mi->surfaces[i].vertex_buffer = 0;
}
}
mi->surfaces.clear();
if (mi->blend_weights_buffer != 0) {
glDeleteBuffers(1, &mi->blend_weights_buffer);
mi->blend_weights_buffer = 0;
}
mi->blend_weights.clear();
mi->weights_dirty = false;

View file

@ -554,7 +554,7 @@ Ref<Image> TextureStorage::_get_gl_image_and_format(const Ref<Image> &p_image, I
} break;
*/
default: {
ERR_FAIL_V(Ref<Image>());
ERR_FAIL_V_MSG(Ref<Image>(), "Image Format: " + itos(p_format) + " is not supported by the OpenGL3 Renderer");
}
}
@ -968,7 +968,7 @@ void TextureStorage::texture_set_data(RID p_texture, const Ref<Image> &p_image,
Image::Format real_format;
Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), 0, real_format, format, internal_format, type, compressed, texture->resize_to_po2);
ERR_FAIL_COND(img.is_null());
if (texture->resize_to_po2) {
if (p_image->is_compressed()) {
ERR_PRINT("Texture '" + texture->path + "' is required to be a power of 2 because it uses either mipmaps or repeat, so it was decompressed. This will hurt performance and memory usage.");
@ -1325,6 +1325,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
rt->color_internal_format = rt->flags[RENDER_TARGET_TRANSPARENT] ? GL_RGBA8 : GL_RGB10_A2;
rt->color_format = GL_RGBA;
rt->color_type = rt->flags[RENDER_TARGET_TRANSPARENT] ? GL_BYTE : GL_UNSIGNED_INT_2_10_10_10_REV;
rt->image_format = Image::FORMAT_RGBA8;
glDisable(GL_SCISSOR_TEST);

View file

@ -249,7 +249,10 @@ struct Texture {
[[fallthrough]];
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: {
pmag = GL_NEAREST;
if (config->use_nearest_mip_filter) {
if (mipmaps <= 1) {
pmin = GL_NEAREST;
max_lod = 0;
} else if (config->use_nearest_mip_filter) {
pmin = GL_NEAREST_MIPMAP_NEAREST;
} else {
pmin = GL_NEAREST_MIPMAP_LINEAR;
@ -261,9 +264,11 @@ struct Texture {
[[fallthrough]];
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: {
pmag = GL_LINEAR;
if (config->use_nearest_mip_filter) {
if (mipmaps <= 1) {
pmin = GL_LINEAR;
max_lod = 0;
} else if (config->use_nearest_mip_filter) {
pmin = GL_LINEAR_MIPMAP_NEAREST;
} else {
pmin = GL_LINEAR_MIPMAP_LINEAR;
}