Skip to content

Commit

Permalink
Merge pull request godotengine#51843 from reduz/fixes-to-mobile-rende…
Browse files Browse the repository at this point in the history
…rer-3

More fixes to mobile renderer
  • Loading branch information
akien-mga authored Aug 18, 2021
2 parents e1e0142 + 700f9d9 commit f6626a4
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 108 deletions.
10 changes: 5 additions & 5 deletions servers/rendering/renderer_rd/shader_compiler_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static String _interpstr(SL::DataInterpolation p_interp) {
return "";
}

static String _prestr(SL::DataPrecision p_pres) {
static String _prestr(SL::DataPrecision p_pres, bool p_force_highp = false) {
switch (p_pres) {
case SL::PRECISION_LOWP:
return "lowp ";
Expand All @@ -222,7 +222,7 @@ static String _prestr(SL::DataPrecision p_pres) {
case SL::PRECISION_HIGHP:
return "highp ";
case SL::PRECISION_DEFAULT:
return "";
return p_force_highp ? "highp " : "";
}
return "";
}
Expand Down Expand Up @@ -617,7 +617,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
//this is an integer to index the global table
ucode += _typestr(ShaderLanguage::TYPE_UINT);
} else {
ucode += _prestr(uniform.precision);
ucode += _prestr(uniform.precision, ShaderLanguage::is_float_type(uniform.type));
ucode += _typestr(uniform.type);
}

Expand Down Expand Up @@ -742,7 +742,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge

String vcode;
String interp_mode = _interpstr(varying.interpolation);
vcode += _prestr(varying.precision);
vcode += _prestr(varying.precision, ShaderLanguage::is_float_type(varying.type));
vcode += _typestr(varying.type);
vcode += " " + _mkid(varying_name);
if (varying.array_size > 0) {
Expand Down Expand Up @@ -777,7 +777,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
const SL::ShaderNode::Constant &cnode = pnode->vconstants[i];
String gcode;
gcode += "const ";
gcode += _prestr(cnode.precision);
gcode += _prestr(cnode.precision, ShaderLanguage::is_float_type(cnode.type));
if (cnode.type == SL::TYPE_STRUCT) {
gcode += _mkid(cnode.type_str);
} else {
Expand Down
28 changes: 14 additions & 14 deletions servers/rendering/renderer_rd/shaders/decal_data_inc.glsl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

struct DecalData {
mat4 xform; //to decal transform
vec3 inv_extents;
float albedo_mix;
vec4 albedo_rect;
vec4 normal_rect;
vec4 orm_rect;
vec4 emission_rect;
vec4 modulate;
float emission_energy;
highp mat4 xform; //to decal transform
highp vec3 inv_extents;
mediump float albedo_mix;
highp vec4 albedo_rect;
highp vec4 normal_rect;
highp vec4 orm_rect;
highp vec4 emission_rect;
highp vec4 modulate;
mediump float emission_energy;
uint mask;
float upper_fade;
float lower_fade;
mat3x4 normal_xform;
vec3 normal;
float normal_fade;
mediump float upper_fade;
mediump float lower_fade;
mediump mat3x4 normal_xform;
mediump vec3 normal;
mediump float normal_fade;
};
84 changes: 42 additions & 42 deletions servers/rendering/renderer_rd/shaders/light_data_inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@

struct LightData { //this structure needs to be as packed as possible
highp vec3 position;
float inv_radius;
highp float inv_radius;

vec3 direction;
float size;
mediump vec3 direction;
highp float size;

vec3 color;
float attenuation;
mediump vec3 color;
mediump float attenuation;

float cone_attenuation;
float cone_angle;
float specular_amount;
mediump float cone_attenuation;
mediump float cone_angle;
mediump float specular_amount;
bool shadow_enabled;

highp vec4 atlas_rect; // rect in the shadow atlas
highp mat4 shadow_matrix;
float shadow_bias;
float shadow_normal_bias;
float transmittance_bias;
float soft_shadow_size; // for spot, it's the size in uv coordinates of the light, for omni it's the span angle
float soft_shadow_scale; // scales the shadow kernel for blurrier shadows
highp float shadow_bias;
highp float shadow_normal_bias;
highp float transmittance_bias;
highp float soft_shadow_size; // for spot, it's the size in uv coordinates of the light, for omni it's the span angle
highp float soft_shadow_scale; // scales the shadow kernel for blurrier shadows
uint mask;
float shadow_volumetric_fog_fade;
mediump float shadow_volumetric_fog_fade;
uint bake_mode;
highp vec4 projector_rect; //projector rect in srgb decal atlas
};
Expand All @@ -35,53 +35,53 @@ struct LightData { //this structure needs to be as packed as possible
#define REFLECTION_AMBIENT_COLOR 2

struct ReflectionData {
vec3 box_extents;
float index;
vec3 box_offset;
highp vec3 box_extents;
mediump float index;
highp vec3 box_offset;
uint mask;
vec3 ambient; // ambient color
float intensity;
mediump vec3 ambient; // ambient color
mediump float intensity;
bool exterior;
bool box_project;
uint ambient_mode;
uint pad;
//0-8 is intensity,8-9 is ambient, mode
mat4 local_matrix; // up to here for spot and omni, rest is for directional
highp mat4 local_matrix; // up to here for spot and omni, rest is for directional
// notes: for ambientblend, use distance to edge to blend between already existing global environment
};

struct DirectionalLightData {
vec3 direction;
float energy;
vec3 color;
float size;
float specular;
mediump vec3 direction;
mediump float energy;
mediump vec3 color;
mediump float size;
mediump float specular;
uint mask;
float softshadow_angle;
float soft_shadow_scale;
highp float softshadow_angle;
highp float soft_shadow_scale;
bool blend_splits;
bool shadow_enabled;
float fade_from;
float fade_to;
highp float fade_from;
highp float fade_to;
uvec2 pad;
uint bake_mode;
float shadow_volumetric_fog_fade;
vec4 shadow_bias;
vec4 shadow_normal_bias;
vec4 shadow_transmittance_bias;
mediump float shadow_volumetric_fog_fade;
highp vec4 shadow_bias;
highp vec4 shadow_normal_bias;
highp vec4 shadow_transmittance_bias;
highp vec4 shadow_z_range;
highp vec4 shadow_range_begin;
vec4 shadow_split_offsets;
highp vec4 shadow_split_offsets;
highp mat4 shadow_matrix1;
highp mat4 shadow_matrix2;
highp mat4 shadow_matrix3;
highp mat4 shadow_matrix4;
vec4 shadow_color1;
vec4 shadow_color2;
vec4 shadow_color3;
vec4 shadow_color4;
vec2 uv_scale1;
vec2 uv_scale2;
vec2 uv_scale3;
vec2 uv_scale4;
mediump vec4 shadow_color1;
mediump vec4 shadow_color2;
mediump vec4 shadow_color3;
mediump vec4 shadow_color4;
highp vec2 uv_scale1;
highp vec2 uv_scale2;
highp vec2 uv_scale3;
highp vec2 uv_scale4;
};
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms

#ifdef MODE_DUAL_PARABOLOID

layout(location = 8) out float dp_clip;
layout(location = 8) out highp float dp_clip;

#endif

Expand Down Expand Up @@ -370,11 +370,6 @@ void main() {

#VERSION_DEFINES

//use medium precision for floats on mobile.

precision mediump float;
precision highp int;

/* Specialization Constants */

#if !defined(MODE_RENDER_DEPTH)
Expand Down Expand Up @@ -498,7 +493,7 @@ layout(location = 0) out vec4 diffuse_buffer; //diffuse (rgb) and roughness
layout(location = 1) out vec4 specular_buffer; //specular and SSS (subsurface scatter)
#else

layout(location = 0) out vec4 frag_color;
layout(location = 0) out mediump vec4 frag_color;
#endif // MODE_MULTIPLE_RENDER_TARGETS

#endif // RENDER DEPTH
Expand Down
80 changes: 40 additions & 40 deletions servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ directional_lights;
#define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2

struct Lightmap {
mat3 normal_xform;
mediump mat3 normal_xform;
};

layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps {
Expand All @@ -102,24 +102,24 @@ layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps {
lightmaps;

struct LightmapCapture {
vec4 sh[9];
mediump vec4 sh[9];
};

layout(set = 0, binding = 10, std140) restrict readonly buffer LightmapCaptures {
LightmapCapture data[];
}
lightmap_captures;

layout(set = 0, binding = 11) uniform texture2D decal_atlas;
layout(set = 0, binding = 12) uniform texture2D decal_atlas_srgb;
layout(set = 0, binding = 11) uniform mediump texture2D decal_atlas;
layout(set = 0, binding = 12) uniform mediump texture2D decal_atlas_srgb;

layout(set = 0, binding = 13, std430) restrict readonly buffer Decals {
DecalData data[];
}
decals;

layout(set = 0, binding = 14, std430) restrict readonly buffer GlobalVariableData {
vec4 data[];
highp vec4 data[];
}
global_variables;

Expand All @@ -135,56 +135,56 @@ layout(set = 1, binding = 0, std140) uniform SceneData {
highp mat4 projection_matrix_view[MAX_VIEWS];
highp mat4 inv_projection_matrix_view[MAX_VIEWS];

vec2 viewport_size;
vec2 screen_pixel_size;
highp vec2 viewport_size;
highp vec2 screen_pixel_size;

// Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
vec4 directional_penumbra_shadow_kernel[32];
vec4 directional_soft_shadow_kernel[32];
vec4 penumbra_shadow_kernel[32];
vec4 soft_shadow_kernel[32];
highp vec4 directional_penumbra_shadow_kernel[32];
highp vec4 directional_soft_shadow_kernel[32];
highp vec4 penumbra_shadow_kernel[32];
highp vec4 soft_shadow_kernel[32];

vec4 ambient_light_color_energy;
mediump vec4 ambient_light_color_energy;

float ambient_color_sky_mix;
mediump float ambient_color_sky_mix;
bool use_ambient_light;
bool use_ambient_cubemap;
bool use_reflection_cubemap;

mat3 radiance_inverse_xform;
mediump mat3 radiance_inverse_xform;

vec2 shadow_atlas_pixel_size;
vec2 directional_shadow_pixel_size;
highp vec2 shadow_atlas_pixel_size;
highp vec2 directional_shadow_pixel_size;

uint directional_light_count;
float dual_paraboloid_side;
float z_far;
float z_near;
mediump float dual_paraboloid_side;
highp float z_far;
highp float z_near;

bool ssao_enabled;
float ssao_light_affect;
float ssao_ao_affect;
mediump float ssao_light_affect;
mediump float ssao_ao_affect;
bool roughness_limiter_enabled;

float roughness_limiter_amount;
float roughness_limiter_limit;
mediump float roughness_limiter_amount;
mediump float roughness_limiter_limit;
uvec2 roughness_limiter_pad;

vec4 ao_color;
mediump vec4 ao_color;

bool fog_enabled;
float fog_density;
float fog_height;
float fog_height_density;
highp float fog_density;
highp float fog_height;
highp float fog_height_density;

vec3 fog_light_color;
float fog_sun_scatter;
mediump vec3 fog_light_color;
mediump float fog_sun_scatter;

float fog_aerial_perspective;
mediump float fog_aerial_perspective;
bool material_uv2_mode;

float time;
float reflection_multiplier; // one normally, zero when rendering reflections
highp float time;
mediump float reflection_multiplier; // one normally, zero when rendering reflections

bool pancake_shadows;
uint pad1;
Expand All @@ -195,30 +195,30 @@ scene_data;

#ifdef USE_RADIANCE_CUBEMAP_ARRAY

layout(set = 1, binding = 2) uniform textureCubeArray radiance_cubemap;
layout(set = 1, binding = 2) uniform mediump textureCubeArray radiance_cubemap;

#else

layout(set = 1, binding = 2) uniform textureCube radiance_cubemap;
layout(set = 1, binding = 2) uniform mediump textureCube radiance_cubemap;

#endif

layout(set = 1, binding = 3) uniform textureCubeArray reflection_atlas;
layout(set = 1, binding = 3) uniform mediump textureCubeArray reflection_atlas;

layout(set = 1, binding = 4) uniform texture2D shadow_atlas;
layout(set = 1, binding = 4) uniform highp texture2D shadow_atlas;

layout(set = 1, binding = 5) uniform texture2D directional_shadow_atlas;
layout(set = 1, binding = 5) uniform highp texture2D directional_shadow_atlas;

// this needs to change to providing just the lightmap we're using..
layout(set = 1, binding = 6) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES];

layout(set = 1, binding = 9) uniform texture2D depth_buffer;
layout(set = 1, binding = 10) uniform texture2D color_buffer;
layout(set = 1, binding = 9) uniform highp texture2D depth_buffer;
layout(set = 1, binding = 10) uniform mediump texture2D color_buffer;

/* Set 2 Skeleton & Instancing (can change per item) */

layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
vec4 data[];
highp vec4 data[];
}
transforms;

Expand Down
Loading

0 comments on commit f6626a4

Please sign in to comment.