Skip to content

Commit 54f3490

Browse files
poweifengpixelflinger
authored andcommitted
Fix ssao precision issue around silhouettes
In the ssao pass, for silhouette pixels, ``` highp vec3 v = p - origin; ``` can be a "long" vector where the length cannot be captured with mediump on mobile. This means that ``` float vv = dot(v, v); float vn = dot(v, normal); ``` and other variables can overflow. This caused the silhouettes to be dark when ssao is turned on a PowerVR gpu. The fix is use highp for the relevant variables.
1 parent e0b2133 commit 54f3490

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

filament/src/materials/ssao/saoImpl.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ void computeAmbientOcclusionSAO(inout float occlusion, inout vec3 bentNormal,
7373

7474
// now we have the sample, compute AO
7575
highp vec3 v = p - origin; // sample vector
76-
float vv = dot(v, v); // squared distance
77-
float vn = dot(v, normal); // distance * cos(v, normal)
76+
highp float vv = dot(v, v); // squared distance
77+
highp float vn = dot(v, normal); // distance * cos(v, normal)
7878

7979
// discard samples that are outside of the radius, preventing distant geometry to
8080
// cast shadows -- there are many functions that work and choosing one is an artistic
8181
// decision.
82-
float w = sq(max(0.0, 1.0 - vv * materialParams.invRadiusSquared));
82+
// Need to be highp to avoid imprecision on certain hardware (e.g. PowerVR)
83+
highp float w = sq(max(0.0, 1.0 - vv * materialParams.invRadiusSquared));
8384

8485
// discard samples that are too close to the horizon to reduce shadows cast by geometry
8586
// not sufficently tessellated. The goal is to discard samples that form an angle 'beta'

0 commit comments

Comments
 (0)