Skip to content

Commit 38f8def

Browse files
committed
renderer: fix fog on GLSL 1.20
1 parent a700306 commit 38f8def

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/engine/renderer/VertexSpecification.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static const char* const attributeNames[] =
6262
"attr_Position2",
6363
"attr_QTangent2",
6464
"attr_FogSurface",
65-
"attr_FogPlanes", nullptr, nullptr, nullptr, nullptr,
65+
"attr_FogPlane0", "attr_FogPlane1", "attr_FogPlane2", "attr_FogPlane3", "attr_FogPlane4",
6666
};
6767

6868
enum

src/engine/renderer/glsl_source/fog_fp.glsl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ IN(flat) vec4 var_FogSurface;
3232

3333
#ifdef OUTSIDE_FOG
3434
#define NUM_PLANES 5
35-
IN(flat) vec4 var_FogPlanes[NUM_PLANES];
35+
36+
/* Not supported on GLSL 1.20:
37+
IN(flat) vec4 var_FogPlanes[NUM_PLANES]; */
38+
IN(flat) vec4 var_FogPlane0;
39+
IN(flat) vec4 var_FogPlane1;
40+
IN(flat) vec4 var_FogPlane2;
41+
IN(flat) vec4 var_FogPlane3;
42+
IN(flat) vec4 var_FogPlane4;
3643
#endif
3744

3845
uniform sampler2D u_DepthMap;
@@ -49,11 +56,19 @@ DECLARE_OUTPUT(vec4)
4956
// Trace against the inner sides of the fog brush
5057
float FogDistance(vec3 start, vec3 dir)
5158
{
59+
vec4 fogPlanes[NUM_PLANES];
60+
fogPlanes[0] = var_FogPlane0;
61+
fogPlanes[1] = var_FogPlane1;
62+
fogPlanes[2] = var_FogPlane2;
63+
fogPlanes[3] = var_FogPlane3;
64+
fogPlanes[4] = var_FogPlane4;
65+
5266
vec4 start4 = vec4(-start, 1.0);
5367
float minDist = 1.0e20;
5468
for (int i = 0; i < NUM_PLANES; i++)
5569
{
56-
float dist = dot(start4, var_FogPlanes[i]) / dot(dir, var_FogPlanes[i].xyz) ;
70+
float dist = dot(start4, fogPlanes[i]) / dot(dir, fogPlanes[i].xyz) ;
71+
5772
if (dist >= 0.0)
5873
{
5974
minDist = min(minDist, dist);

src/engine/renderer/glsl_source/fog_vp.glsl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ OUT(smooth) vec3 var_Position;
4141
OUT(flat) vec4 var_FogSurface;
4242

4343
#ifdef OUTSIDE_FOG
44-
#define NUM_PLANES 5
45-
IN vec4 attr_FogPlanes[NUM_PLANES];
46-
OUT(flat) vec4 var_FogPlanes[NUM_PLANES];
44+
/* Not supported on GLSL 1.20:
45+
IN(flat) attr_FogPlanes[NUM_PLANES]; */
46+
IN vec4 attr_FogPlane0;
47+
IN vec4 attr_FogPlane1;
48+
IN vec4 attr_FogPlane2;
49+
IN vec4 attr_FogPlane3;
50+
IN vec4 attr_FogPlane4;
51+
52+
/* Not supported on GLSL 1.20:
53+
OUT(flat) var_FogPlanes[NUM_PLANES]; */
54+
OUT(flat) vec4 var_FogPlane0;
55+
OUT(flat) vec4 var_FogPlane1;
56+
OUT(flat) vec4 var_FogPlane2;
57+
OUT(flat) vec4 var_FogPlane3;
58+
OUT(flat) vec4 var_FogPlane4;
4759
#endif
4860

4961
void main()
@@ -54,9 +66,10 @@ void main()
5466
var_FogSurface = attr_FogSurface;
5567

5668
#ifdef OUTSIDE_FOG
57-
for (int i = 0; i < NUM_PLANES; i++)
58-
{
59-
var_FogPlanes[i] = attr_FogPlanes[i];
60-
}
69+
var_FogPlane0 = attr_FogPlane0;
70+
var_FogPlane1 = attr_FogPlane1;
71+
var_FogPlane2 = attr_FogPlane2;
72+
var_FogPlane3 = attr_FogPlane3;
73+
var_FogPlane4 = attr_FogPlane4;
6174
#endif
6275
}

0 commit comments

Comments
 (0)