Skip to content

Commit

Permalink
Finish up vertex shading render mode including adding support for
Browse files Browse the repository at this point in the history
shadows, force_vertex_shading, and positional lights
  • Loading branch information
clayjohn committed Sep 20, 2024
1 parent 0dff4dc commit 0ba3978
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 768 deletions.
3 changes: 3 additions & 0 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4125,6 +4125,9 @@ RasterizerSceneGLES3::RasterizerSceneGLES3() {
global_defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(MAX_DIRECTIONAL_LIGHTS) + "\n";
global_defines += "\n#define MAX_FORWARD_LIGHTS " + itos(config->max_lights_per_object) + "u\n";
global_defines += "\n#define MAX_ROUGHNESS_LOD " + itos(sky_globals.roughness_layers - 1) + ".0\n";
if (config->force_vertex_shading) {
global_defines += "\n#define USE_VERTEX_LIGHTING\n";
}
material_storage->shaders.scene_shader.initialize(global_defines);
scene_globals.shader_default_version = material_storage->shaders.scene_shader.version_create();
material_storage->shaders.scene_shader.version_bind_shader(scene_globals.shader_default_version, SceneShaderGLES3::MODE_COLOR);
Expand Down
202 changes: 96 additions & 106 deletions drivers/gles3/shaders/scene.glsl

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions drivers/gles3/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,10 @@ MaterialStorage::MaterialStorage() {
actions.render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n";
actions.render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n";
actions.render_mode_defines["unshaded"] = "#define MODE_UNSHADED\n";
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";
if (!GLES3::Config::get_singleton()->force_vertex_shading) {
// If forcing vertex shading, this will be defined already.
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";
}
actions.render_mode_defines["fog_disabled"] = "#define FOG_DISABLED\n";

actions.default_filter = ShaderLanguage::FILTER_LINEAR_MIPMAP;
Expand Down Expand Up @@ -2860,7 +2863,6 @@ void SceneShaderData::set_code(const String &p_code) {
wireframe = false;

unshaded = false;
vertex_lighting = false;
uses_vertex = false;
uses_position = false;
uses_sss = false;
Expand Down Expand Up @@ -2923,11 +2925,6 @@ void SceneShaderData::set_code(const String &p_code) {
actions.render_mode_values["cull_back"] = Pair<int *, int>(&cull_modei, CULL_BACK);

actions.render_mode_flags["unshaded"] = &unshaded;
actions.render_mode_flags["vertex_lighting"] = &vertex_lighting;
bool force_vertex_lighting = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
if (force_vertex_lighting) {
actions.render_mode_flags["vertex_lighting"] = &force_vertex_lighting;
}
actions.render_mode_flags["wireframe"] = &wireframe;
actions.render_mode_flags["particle_trails"] = &uses_particle_trails;
actions.render_mode_flags["world_vertex_coords"] = &uses_world_coordinates;
Expand Down
1 change: 0 additions & 1 deletion drivers/gles3/storage/material_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ struct SceneShaderData : public ShaderData {
bool wireframe;

bool unshaded;
bool vertex_lighting;
bool uses_vertex;
bool uses_position;
bool uses_sss;
Expand Down
4 changes: 1 addition & 3 deletions scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void BaseMaterial3D::_update_shader() {
if (flags[FLAG_PARTICLE_TRAILS_MODE]) {
code += ", particle_trails";
}
if (shading_mode == SHADING_MODE_PER_VERTEX || force_vertex_shading) {
if (shading_mode == SHADING_MODE_PER_VERTEX) {
code += ", vertex_lighting";
}
if (flags[FLAG_DONT_RECEIVE_SHADOWS]) {
Expand Down Expand Up @@ -3434,8 +3434,6 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
current_key.invalid_key = 1;

_mark_initialized(callable_mp(this, &BaseMaterial3D::_queue_shader_change), callable_mp(this, &BaseMaterial3D::_update_shader));

force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
}

BaseMaterial3D::~BaseMaterial3D() {
Expand Down
2 changes: 0 additions & 2 deletions scene/resources/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,6 @@ class BaseMaterial3D : public Material {

Ref<Texture2D> textures[TEXTURE_MAX];

bool force_vertex_shading = false;

_FORCE_INLINE_ void _validate_feature(const String &text, Feature feature, PropertyInfo &property) const;

static HashMap<uint64_t, Ref<StandardMaterial3D>> materials_for_2d; //used by Sprite3D, Label3D and other stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4261,6 +4261,11 @@ RenderForwardClustered::RenderForwardClustered() {
defines += "\n#define SDFGI_OCT_SIZE " + itos(gi.sdfgi_get_lightprobe_octahedron_size()) + "\n";
defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(MAX_DIRECTIONAL_LIGHTS) + "\n";

bool force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
if (force_vertex_shading) {
defines += "\n#define USE_VERTEX_LIGHTING\n";
}

{
//lightmaps
scene_state.max_lightmaps = MAX_LIGHTMAPS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,13 @@ void SceneShaderForwardClustered::init(const String p_defines) {
actions.render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n";
actions.render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n";
actions.render_mode_defines["unshaded"] = "#define MODE_UNSHADED\n";
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";

bool force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
if (!force_vertex_shading) {
// If forcing vertex shading, this will be defined already.
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";
}

actions.render_mode_defines["debug_shadow_splits"] = "#define DEBUG_DRAW_PSSM_SPLITS\n";
actions.render_mode_defines["fog_disabled"] = "#define FOG_DISABLED\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,11 @@ RenderForwardMobile::RenderForwardMobile() {
// defines += "\n#define SDFGI_OCT_SIZE " + itos(gi.sdfgi_get_lightprobe_octahedron_size()) + "\n";
defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(MAX_DIRECTIONAL_LIGHTS) + "\n";

bool force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
if (force_vertex_shading) {
defines += "\n#define USE_VERTEX_LIGHTING\n";
}

{
//lightmaps
scene_state.max_lightmaps = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,13 @@ void SceneShaderForwardMobile::init(const String p_defines) {
actions.render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n";
actions.render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n";
actions.render_mode_defines["unshaded"] = "#define MODE_UNSHADED\n";
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";

bool force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
if (!force_vertex_shading) {
// If forcing vertex shading, this will be defined already.
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";
}

actions.render_mode_defines["debug_shadow_splits"] = "#define DEBUG_DRAW_PSSM_SPLITS\n";
actions.render_mode_defines["fog_disabled"] = "#define FOG_DISABLED\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,6 @@ RendererCanvasRenderRD::RendererCanvasRenderRD() {

actions.render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n";
actions.render_mode_defines["unshaded"] = "#define MODE_UNSHADED\n";
actions.render_mode_defines["vertex_lighting"] = "#define USE_VERTEX_LIGHTING\n";
actions.render_mode_defines["light_only"] = "#define MODE_LIGHT_ONLY\n";
actions.render_mode_defines["world_vertex_coords"] = "#define USE_WORLD_VERTEX_COORDS\n";

Expand Down
Loading

0 comments on commit 0ba3978

Please sign in to comment.