You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Optimize Mobile renderer by using FP16 explicitly.
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
|
||||
#VERSION_DEFINES
|
||||
|
||||
/* Include half precision types. */
|
||||
#include "../half_inc.glsl"
|
||||
|
||||
#include "scene_forward_clustered_inc.glsl"
|
||||
|
||||
#define SHADER_IS_SRGB false
|
||||
@@ -155,8 +158,8 @@ ivec2 multiview_uv(ivec2 uv) {
|
||||
#endif //USE_MULTIVIEW
|
||||
|
||||
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
|
||||
layout(location = 12) highp out vec4 diffuse_light_interp;
|
||||
layout(location = 13) highp out vec4 specular_light_interp;
|
||||
layout(location = 12) out vec4 diffuse_light_interp;
|
||||
layout(location = 13) out vec4 specular_light_interp;
|
||||
|
||||
#include "../scene_forward_vertex_lights_inc.glsl"
|
||||
|
||||
@@ -808,6 +811,9 @@ void main() {
|
||||
#define SHADER_IS_SRGB false
|
||||
#define SHADER_SPACE_FAR 0.0
|
||||
|
||||
/* Include half precision types. */
|
||||
#include "../half_inc.glsl"
|
||||
|
||||
#include "scene_forward_clustered_inc.glsl"
|
||||
|
||||
/* Varyings */
|
||||
@@ -929,8 +935,8 @@ ivec2 multiview_uv(ivec2 uv) {
|
||||
}
|
||||
#endif // !USE_MULTIVIEW
|
||||
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
|
||||
layout(location = 12) highp in vec4 diffuse_light_interp;
|
||||
layout(location = 13) highp in vec4 specular_light_interp;
|
||||
layout(location = 12) in vec4 diffuse_light_interp;
|
||||
layout(location = 13) in vec4 specular_light_interp;
|
||||
#endif
|
||||
//defines to keep compatibility with vertex
|
||||
|
||||
@@ -1127,14 +1133,14 @@ void fragment_shader(in SceneData scene_data) {
|
||||
vec3 vertex = vertex_interp;
|
||||
#ifdef USE_MULTIVIEW
|
||||
vec3 eye_offset = scene_data.eye_offset[ViewIndex].xyz;
|
||||
vec3 view = -normalize(vertex_interp - eye_offset);
|
||||
vec3 view_highp = -normalize(vertex_interp - eye_offset);
|
||||
|
||||
// UV in our combined frustum space is used for certain screen uv processes where it's
|
||||
// overkill to render separate left and right eye views
|
||||
vec2 combined_uv = (combined_projected.xy / combined_projected.w) * 0.5 + 0.5;
|
||||
#else
|
||||
vec3 eye_offset = vec3(0.0, 0.0, 0.0);
|
||||
vec3 view = -normalize(vertex_interp);
|
||||
vec3 view_highp = -normalize(vertex_interp);
|
||||
#endif
|
||||
vec3 albedo = vec3(1.0);
|
||||
vec3 backlight = vec3(0.0);
|
||||
@@ -1260,10 +1266,12 @@ void fragment_shader(in SceneData scene_data) {
|
||||
#ifdef LIGHT_VERTEX_USED
|
||||
vertex = light_vertex;
|
||||
#ifdef USE_MULTIVIEW
|
||||
view = -normalize(vertex - eye_offset);
|
||||
vec3 view = -normalize(vertex - eye_offset);
|
||||
#else
|
||||
view = -normalize(vertex);
|
||||
vec3 view = -normalize(vertex);
|
||||
#endif //USE_MULTIVIEW
|
||||
#else
|
||||
vec3 view = view_highp;
|
||||
#endif //LIGHT_VERTEX_USED
|
||||
|
||||
#ifdef NORMAL_USED
|
||||
@@ -2063,11 +2071,6 @@ void fragment_shader(in SceneData scene_data) {
|
||||
#endif // !AMBIENT_LIGHT_DISABLED
|
||||
#endif //GI !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED)
|
||||
|
||||
#if !defined(MODE_RENDER_DEPTH)
|
||||
//this saves some VGPRs
|
||||
uint orms = packUnorm4x8(vec4(ao, roughness, metallic, specular));
|
||||
#endif
|
||||
|
||||
// LIGHTING
|
||||
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED)
|
||||
|
||||
@@ -2455,7 +2458,7 @@ void fragment_shader(in SceneData scene_data) {
|
||||
#else
|
||||
directional_lights.data[i].color * directional_lights.data[i].energy * tint,
|
||||
#endif
|
||||
true, shadow, f0, orms, directional_lights.data[i].specular, albedo, alpha, screen_uv, energy_compensation,
|
||||
true, shadow, f0, roughness, metallic, directional_lights.data[i].specular, albedo, alpha, screen_uv, energy_compensation,
|
||||
#ifdef LIGHT_BACKLIGHT_USED
|
||||
backlight,
|
||||
#endif
|
||||
@@ -2519,7 +2522,7 @@ void fragment_shader(in SceneData scene_data) {
|
||||
continue; // Statically baked light and object uses lightmap, skip
|
||||
}
|
||||
|
||||
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv, energy_compensation,
|
||||
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, roughness, metallic, scene_data.taa_frame_count, albedo, alpha, screen_uv, energy_compensation,
|
||||
#ifdef LIGHT_BACKLIGHT_USED
|
||||
backlight,
|
||||
#endif
|
||||
@@ -2536,7 +2539,7 @@ void fragment_shader(in SceneData scene_data) {
|
||||
clearcoat, clearcoat_roughness, geo_normal,
|
||||
#endif // LIGHT_CLEARCOAT_USED
|
||||
#ifdef LIGHT_ANISOTROPY_USED
|
||||
tangent, binormal, anisotropy,
|
||||
binormal, tangent, anisotropy,
|
||||
#endif
|
||||
diffuse_light, direct_specular_light);
|
||||
}
|
||||
@@ -2580,7 +2583,7 @@ void fragment_shader(in SceneData scene_data) {
|
||||
continue; // Statically baked light and object uses lightmap, skip
|
||||
}
|
||||
|
||||
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv, energy_compensation,
|
||||
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, roughness, metallic, scene_data.taa_frame_count, albedo, alpha, screen_uv, energy_compensation,
|
||||
#ifdef LIGHT_BACKLIGHT_USED
|
||||
backlight,
|
||||
#endif
|
||||
@@ -2597,8 +2600,7 @@ void fragment_shader(in SceneData scene_data) {
|
||||
clearcoat, clearcoat_roughness, geo_normal,
|
||||
#endif // LIGHT_CLEARCOAT_USED
|
||||
#ifdef LIGHT_ANISOTROPY_USED
|
||||
tangent,
|
||||
binormal, anisotropy,
|
||||
binormal, tangent, anisotropy,
|
||||
#endif
|
||||
diffuse_light, direct_specular_light);
|
||||
}
|
||||
@@ -2775,12 +2777,10 @@ void fragment_shader(in SceneData scene_data) {
|
||||
diffuse_light *= albedo; // ambient must be multiplied by albedo at the end
|
||||
|
||||
// apply direct light AO
|
||||
ao = unpackUnorm4x8(orms).x;
|
||||
diffuse_light *= ao;
|
||||
direct_specular_light *= ao;
|
||||
|
||||
// apply metallic
|
||||
metallic = unpackUnorm4x8(orms).z;
|
||||
diffuse_light *= 1.0 - metallic;
|
||||
ambient_light *= 1.0 - metallic;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user