Skip to content

Commit 01bf7b3

Browse files
committed
Switch mobile shader to use default mediump precision.
1 parent 47bc374 commit 01bf7b3

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl

+35-29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#VERSION_DEFINES
66

7+
// Default to relaxed precision.
8+
precision mediump float;
9+
710
/* Include our forward mobile UBOs definitions etc. */
811
#include "scene_forward_mobile_inc.glsl"
912

@@ -13,51 +16,51 @@
1316
/* INPUT ATTRIBS */
1417

1518
// Always contains vertex position in XYZ, can contain tangent angle in W.
16-
layout(location = 0) in vec4 vertex_angle_attrib;
19+
layout(location = 0) in highp vec4 vertex_angle_attrib;
1720

1821
//only for pure render depth when normal is not used
1922

2023
#ifdef NORMAL_USED
2124
// Contains Normal/Axis in RG, can contain tangent in BA.
22-
layout(location = 1) in vec4 axis_tangent_attrib;
25+
layout(location = 1) in highp vec4 axis_tangent_attrib;
2326
#endif
2427

2528
// Location 2 is unused.
2629

2730
#if defined(COLOR_USED)
28-
layout(location = 3) in vec4 color_attrib;
31+
layout(location = 3) in highp vec4 color_attrib;
2932
#endif
3033

3134
#ifdef UV_USED
32-
layout(location = 4) in vec2 uv_attrib;
35+
layout(location = 4) in highp vec2 uv_attrib;
3336
#endif
3437

3538
#if defined(UV2_USED) || defined(USE_LIGHTMAP) || defined(MODE_RENDER_MATERIAL)
36-
layout(location = 5) in vec2 uv2_attrib;
39+
layout(location = 5) in highp vec2 uv2_attrib;
3740
#endif // MODE_RENDER_MATERIAL
3841

3942
#if defined(CUSTOM0_USED)
40-
layout(location = 6) in vec4 custom0_attrib;
43+
layout(location = 6) in highp vec4 custom0_attrib;
4144
#endif
4245

4346
#if defined(CUSTOM1_USED)
44-
layout(location = 7) in vec4 custom1_attrib;
47+
layout(location = 7) in highp vec4 custom1_attrib;
4548
#endif
4649

4750
#if defined(CUSTOM2_USED)
48-
layout(location = 8) in vec4 custom2_attrib;
51+
layout(location = 8) in highp vec4 custom2_attrib;
4952
#endif
5053

5154
#if defined(CUSTOM3_USED)
52-
layout(location = 9) in vec4 custom3_attrib;
55+
layout(location = 9) in highp vec4 custom3_attrib;
5356
#endif
5457

5558
#if defined(BONES_USED) || defined(USE_PARTICLE_TRAILS)
5659
layout(location = 10) in uvec4 bone_attrib;
5760
#endif
5861

5962
#if defined(WEIGHTS_USED) || defined(USE_PARTICLE_TRAILS)
60-
layout(location = 11) in vec4 weight_attrib;
63+
layout(location = 11) in highp vec4 weight_attrib;
6164
#endif
6265

6366
vec3 oct_to_vec3(vec2 e) {
@@ -79,31 +82,31 @@ void axis_angle_to_tbn(vec3 axis, float angle, out vec3 tangent, out vec3 binorm
7982

8083
/* Varyings */
8184

82-
layout(location = 0) highp out vec3 vertex_interp;
85+
layout(location = 0) out highp vec3 vertex_interp;
8386

8487
#ifdef NORMAL_USED
85-
layout(location = 1) mediump out vec3 normal_interp;
88+
layout(location = 1) out vec3 normal_interp;
8689
#endif
8790

8891
#if defined(COLOR_USED)
89-
layout(location = 2) mediump out vec4 color_interp;
92+
layout(location = 2) out vec4 color_interp;
9093
#endif
9194

9295
#ifdef UV_USED
93-
layout(location = 3) mediump out vec2 uv_interp;
96+
layout(location = 3) out vec2 uv_interp;
9497
#endif
9598

9699
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
97-
layout(location = 4) mediump out vec2 uv2_interp;
100+
layout(location = 4) out vec2 uv2_interp;
98101
#endif
99102

100103
#if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED)
101-
layout(location = 5) mediump out vec3 tangent_interp;
102-
layout(location = 6) mediump out vec3 binormal_interp;
104+
layout(location = 5) out vec3 tangent_interp;
105+
layout(location = 6) out vec3 binormal_interp;
103106
#endif
104107
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
105-
layout(location = 7) highp out vec4 diffuse_light_interp;
106-
layout(location = 8) highp out vec4 specular_light_interp;
108+
layout(location = 7) out highp vec4 diffuse_light_interp;
109+
layout(location = 8) out highp vec4 specular_light_interp;
107110

108111
#include "../scene_forward_vertex_lights_inc.glsl"
109112
#endif // !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
@@ -567,6 +570,9 @@ void main() {
567570

568571
#VERSION_DEFINES
569572

573+
// Default to relaxed precision.
574+
precision mediump float;
575+
570576
#define SHADER_IS_SRGB false
571577
#define SHADER_SPACE_FAR 0.0
572578

@@ -575,37 +581,37 @@ void main() {
575581

576582
/* Varyings */
577583

578-
layout(location = 0) highp in vec3 vertex_interp;
584+
layout(location = 0) in highp vec3 vertex_interp;
579585

580586
#ifdef NORMAL_USED
581-
layout(location = 1) mediump in vec3 normal_interp;
587+
layout(location = 1) in vec3 normal_interp;
582588
#endif
583589

584590
#if defined(COLOR_USED)
585-
layout(location = 2) mediump in vec4 color_interp;
591+
layout(location = 2) in vec4 color_interp;
586592
#endif
587593

588594
#ifdef UV_USED
589-
layout(location = 3) mediump in vec2 uv_interp;
595+
layout(location = 3) in vec2 uv_interp;
590596
#endif
591597

592598
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
593-
layout(location = 4) mediump in vec2 uv2_interp;
599+
layout(location = 4) in vec2 uv2_interp;
594600
#endif
595601

596602
#if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED)
597-
layout(location = 5) mediump in vec3 tangent_interp;
598-
layout(location = 6) mediump in vec3 binormal_interp;
603+
layout(location = 5) in vec3 tangent_interp;
604+
layout(location = 6) in vec3 binormal_interp;
599605
#endif
600606

601607
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
602-
layout(location = 7) highp in vec4 diffuse_light_interp;
603-
layout(location = 8) highp in vec4 specular_light_interp;
608+
layout(location = 7) in highp vec4 diffuse_light_interp;
609+
layout(location = 8) in highp vec4 specular_light_interp;
604610
#endif
605611

606612
#ifdef MODE_DUAL_PARABOLOID
607613

608-
layout(location = 9) highp in float dp_clip;
614+
layout(location = 9) in highp float dp_clip;
609615

610616
#endif
611617

servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile_inc.glsl

+3-3
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ struct InstanceData {
274274
uvec2 spot_lights; // 08 - 120
275275
uvec2 decals; // 08 - 128
276276

277-
vec4 compressed_aabb_position_pad; // 16 - 144 // Only .xyz is used. .w is padding.
278-
vec4 compressed_aabb_size_pad; // 16 - 160 // Only .xyz is used. .w is padding.
279-
vec4 uv_scale; // 16 - 176
277+
highp vec4 compressed_aabb_position_pad; // 16 - 144 // Only .xyz is used. .w is padding.
278+
highp vec4 compressed_aabb_size_pad; // 16 - 160 // Only .xyz is used. .w is padding.
279+
highp vec4 uv_scale; // 16 - 176
280280
};
281281

282282
layout(set = 1, binding = 1, std430) buffer restrict readonly InstanceDataBuffer {

servers/rendering/shader_compiler.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static String _interpstr(SL::DataInterpolation p_interp) {
137137
return "";
138138
}
139139

140-
static String _prestr(SL::DataPrecision p_pres, bool p_force_highp = false) {
140+
static String _prestr(SL::DataPrecision p_pres, bool p_force_highp) {
141141
switch (p_pres) {
142142
case SL::PRECISION_LOWP:
143143
return "lowp ";
@@ -366,7 +366,7 @@ void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const Str
366366
if (fnode->arguments[i].type == SL::TYPE_STRUCT) {
367367
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].struct_name) + " " + _mkid(fnode->arguments[i].name);
368368
} else {
369-
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
369+
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision, ShaderLanguage::is_float_type(fnode->arguments[i].type)) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
370370
}
371371
if (fnode->arguments[i].array_size > 0) {
372372
header += "[";
@@ -485,7 +485,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
485485
if (m->datatype == SL::TYPE_STRUCT) {
486486
struct_code += _mkid(m->struct_name);
487487
} else {
488-
struct_code += _prestr(m->precision);
488+
struct_code += _prestr(m->precision, ShaderLanguage::is_float_type(m->datatype));
489489
struct_code += _typestr(m->datatype);
490490
}
491491
struct_code += " ";
@@ -727,7 +727,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
727727
if (var_frag_to_light.size() > 0) {
728728
String gcode = "\n\nstruct {\n";
729729
for (const Pair<StringName, SL::ShaderNode::Varying> &E : var_frag_to_light) {
730-
gcode += "\t" + _prestr(E.second.precision) + _typestr(E.second.type) + " " + _mkid(E.first);
730+
gcode += "\t" + _prestr(E.second.precision, ShaderLanguage::is_float_type(E.second.type)) + _typestr(E.second.type) + " " + _mkid(E.first);
731731
if (E.second.array_size > 0) {
732732
gcode += "[";
733733
gcode += itos(E.second.array_size);
@@ -834,7 +834,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
834834
if (vdnode->datatype == SL::TYPE_STRUCT) {
835835
declaration += _mkid(vdnode->struct_name);
836836
} else {
837-
declaration += _prestr(vdnode->precision) + _typestr(vdnode->datatype);
837+
declaration += _prestr(vdnode->precision, ShaderLanguage::is_float_type(vdnode->datatype)) + _typestr(vdnode->datatype);
838838
}
839839
declaration += " ";
840840
for (int i = 0; i < vdnode->declarations.size(); i++) {

0 commit comments

Comments
 (0)