Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to turn off normal shading #7399

Merged
merged 12 commits into from
Mar 14, 2019
29 changes: 22 additions & 7 deletions Source/Scene/PointCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ define([
this._quantizedRange = 0.0;
this._octEncodedRange = 0.0;

this._pointCloudShading = defaultValue(options.shading, {
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
backFaceCulling : false,
normalShading : true
});

// Use per-point normals to hide back-facing points.
this.backFaceCulling = false;
this._backFaceCulling = false;
this._backFaceCulling = this.backFaceCulling;

// Whether to enable normal shading
this.normalShading = true;
this._normalShading = true;
this._normalShading = this.normalShading;

this._opaqueRenderState = undefined;
this._translucentRenderState = undefined;
Expand Down Expand Up @@ -244,6 +247,18 @@ define([
set : function(value) {
this._boundingSphere = BoundingSphere.clone(value);
}
},

backFaceCulling : {
get : function() {
return this._pointCloudShading.backFaceCulling;
}
},

normalShading : {
get : function() {
return this._pointCloudShading.normalShading;
}
}
});

Expand Down Expand Up @@ -1128,6 +1143,7 @@ define([
} else {
vs += ' vec3 normal = a_normal; \n';
}
vs += ' vec3 view_normal = czm_normal * normal; \n';
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
} else {
vs += ' vec3 normal = vec3(1.0); \n';
}
Expand All @@ -1154,8 +1170,7 @@ define([
vs += ' color = color * u_highlightColor; \n';

if (usesNormals && normalShading) {
vs += ' normal = czm_normal * normal; \n' +
' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, normal); \n' +
vs += ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, view_normal); \n' +
' diffuseStrength = max(diffuseStrength, 0.4); \n' + // Apply some ambient lighting
' color.xyz *= diffuseStrength; \n';
}
Expand All @@ -1164,7 +1179,7 @@ define([
' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n';

if (usesNormals && backFaceCulling) {
vs += ' float visible = step(-normal.z, 0.0); \n' +
vs += ' float visible = step(-view_normal.z, 0.0); \n' +
' gl_Position *= visible; \n' +
' gl_PointSize *= visible; \n';
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ define([
fragmentShaderLoaded : getFragmentShaderLoaded(this),
uniformMapLoaded : getUniformMapLoaded(this),
batchTableLoaded : getBatchTableLoaded(this),
pickIdLoaded : getPickIdLoaded(this)
pickIdLoaded : getPickIdLoaded(this),
shading : tileset.pointCloudShading
});
}

Expand Down
16 changes: 16 additions & 0 deletions Source/Scene/PointCloudShading.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ define([
* @default 1.0
*/
this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0);

/**
* Determines whether backfaces of points / mesh are hidden
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
*
* @type {boolean}
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
* @default false
*/
this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false);

/**
* Determines whether the tileset is lighted by the sun
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
*
* @type {boolean}
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
* @default true
*/
this.normalShading = defaultValue(pointCloudShading.normalShading, true);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/TimeDynamicPointCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ define([
cull : true,
fragmentShaderLoaded : getFragmentShaderLoaded,
uniformMapLoaded : getUniformMapLoaded(that),
pickIdLoaded : getPickIdLoaded
pickIdLoaded : getPickIdLoaded,
shading : that.shading
});
return frame.pointCloud.readyPromise;
}).otherwise(handleFrameFailure(that, uri));
Expand Down