Skip to content

Commit

Permalink
fix(material): prevent warnings about unused varyings (#38)
Browse files Browse the repository at this point in the history
Only declared varyings which are actually used.

Observed on Chrome on MacOS with AMD Radeon R9 M370X.
  • Loading branch information
rhuitl authored and Hugo Campos committed Apr 1, 2019
1 parent d3f5737 commit 1e74717
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 25 deletions.
42 changes: 30 additions & 12 deletions src/materials/shaders/pointcloud.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,31 @@ uniform float screenHeight;

uniform sampler2D depthMap;

varying vec3 vColor;
#ifndef color_type_point_index
varying vec3 vColor;

#if !defined(color_type_point_index)
varying float vOpacity;
#endif
varying float vLinearDepth;
varying float vLogDepth;
varying vec3 vViewPosition;
varying float vRadius;
varying vec3 vNormal;

#if defined(weighted_splats)
varying float vLinearDepth;
#endif

#if !defined(paraboloid_point_shape) && defined(use_edl)
varying float vLogDepth;
#endif

#if defined(color_type_phong) && (MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0) || defined(paraboloid_point_shape)
varying vec3 vViewPosition;
#endif

#if defined(weighted_splats) || defined(paraboloid_point_shape)
varying float vRadius;
#endif

#if defined(color_type_phong) && (MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0)
varying vec3 vNormal;
#endif

float specularStrength = 1.0;

Expand Down Expand Up @@ -65,13 +81,15 @@ void main() {
gl_FragColor = vec4(color, vOpacity);
#endif

vec3 normal = normalize( vNormal );
normal.z = abs(normal.z);
vec3 viewPosition = normalize( vViewPosition );

#if defined(color_type_phong)
#if MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0
vec3 normal = normalize( vNormal );
normal.z = abs(normal.z);

vec3 viewPosition = normalize( vViewPosition );
#endif

// code taken from three.js phong light fragment shader
// code taken from three.js phong light fragment shader

#if MAX_POINT_LIGHTS > 0

Expand Down
51 changes: 38 additions & 13 deletions src/materials/shaders/pointcloud.vert
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,33 @@ uniform sampler2D gradient;
uniform sampler2D classificationLUT;
uniform sampler2D depthMap;

#ifndef color_type_point_index
varying vec3 vColor;

#if !defined(color_type_point_index)
varying float vOpacity;
#endif
varying vec3 vColor;
varying float vLinearDepth;

varying vec3 vViewPosition;
varying float vRadius;
varying vec3 vNormal;
#if defined(weighted_splats)
varying float vLinearDepth;
#endif

#if defined use_edl
#if !defined(paraboloid_point_shape) && defined(use_edl)
varying float vLogDepth;
#endif

#if defined(color_type_phong) && (MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0) || defined(paraboloid_point_shape)
varying vec3 vViewPosition;
#endif

#if defined(weighted_splats) || defined(paraboloid_point_shape)
varying float vRadius;
#endif

#if defined(color_type_phong) && (MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0)
varying vec3 vNormal;
#endif


// ---------------------
// OCTREE
// ---------------------
Expand Down Expand Up @@ -359,12 +372,22 @@ vec3 getCompositeColor() {

void main() {
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
vViewPosition = mvPosition.xyz;

gl_Position = projectionMatrix * mvPosition;
vLinearDepth = gl_Position.w;
vNormal = normalize(normalMatrix * normal);

#if defined use_edl
#if defined(color_type_phong) && (MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0) || defined(paraboloid_point_shape)
vViewPosition = mvPosition.xyz;
#endif

#if defined weighted_splats
vLinearDepth = gl_Position.w;
#endif

#if defined(color_type_phong) && (MAX_POINT_LIGHTS > 0 || MAX_DIR_LIGHTS > 0)
vNormal = normalize(normalMatrix * normal);
#endif

#if !defined(paraboloid_point_shape) && defined(use_edl)
vLogDepth = log2(-mvPosition.z);
#endif

Expand All @@ -374,7 +397,7 @@ void main() {

float pointSize = 1.0;
float slope = tan(fov / 2.0);
float projFactor = -0.5 * screenHeight / (slope * vViewPosition.z);
float projFactor = -0.5 * screenHeight / (slope * mvPosition.z);

#if defined fixed_point_size
pointSize = size;
Expand All @@ -388,7 +411,9 @@ void main() {
pointSize = max(minSize, pointSize);
pointSize = min(maxSize, pointSize);

vRadius = pointSize / projFactor;
#if defined(weighted_splats) || defined(paraboloid_point_shape)
vRadius = pointSize / projFactor;
#endif

gl_PointSize = pointSize;

Expand Down

0 comments on commit 1e74717

Please sign in to comment.