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

Making ShadowMap constructor private #4890

Merged
merged 6 commits into from
Jan 25, 2017

Conversation

rahwang
Copy link
Contributor

@rahwang rahwang commented Jan 20, 2017

See #4010

@lilleyse
Copy link
Contributor

I'm not sure if this is possible to do, but can the constructor be private but ShadowMap still be visible in the documentation? Shadows have a few settings like darkness, maximumDistance, size, etc which would be nice to have in the documentation still.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 20, 2017

I'm not sure if this is possible to do, but can the constructor be private but ShadowMap still be visible in the documentation?

@internalConstructor - not sure how well supported it is now - see ModelMesh for an example.

Shadows have a few settings like darkness, maximumDistance, size, etc which would be nice to have in the documentation still.

How do users get to the shadow map object? Through the scene?

We could keep this class public with the private constructor and make any other members private as needed.

@lilleyse
Copy link
Contributor

viewer.shadowMap is the standard way, but its also accessible from scene.

@rahwang
Copy link
Contributor Author

rahwang commented Jan 20, 2017

How's this, @lilleyse ? Should normalOffset be visible since its mentioned?

@lilleyse
Copy link
Contributor

Looking at jsdoc documentation @internalConstructor isn't supported, and I can't find another way of doing this...

Whether the constructor can be hidden or not, I think its still a good idea to keep the parameters since they are helpful for anyone coding cesium.

Maybe we just need a note that it is not recommend to construct a ShadowMap directly since Cesium does not support multiple light sources.

I don't see a problem with instantiating with scene instead of context, and just get the context with scene.context. Passing in scene is starting to get more common now with height references (like Model). This will have breaking changes though here and in Cesium Pro. Technically I think this can all be done without sending in context or scene, but will require bigger changes.

Should normalOffset be visible since its mentioned?

Hm, I suppose there should be a setting for this since it is mentioned. The normal offset is controlled by setting _terrainBias, _primitiveBias, and _pointBias's normalOffset property.

@lilleyse
Copy link
Contributor

Oh so Cesium adds internalConstructor as a synonym for class in cesiumTags.js.

@lilleyse
Copy link
Contributor

lilleyse commented Jan 20, 2017

Overall adding that warning comment and using scene instead of context are what I would do for the time being. @pjcozzi what do you think about passing in scene?

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 21, 2017

Overall adding that warning comment and using scene instead of context are what I would do for the time being. @pjcozzi what do you think about passing in scene?

Yes, more precisely

  • Pass in scene, instead of context
  • Mark the constructor internalConstructor. Include the "warning comment" just like the example I pointed to in ModelMesh - this should point the reader to Viewer.shadowMap to get the object
  • @lilleyse please evaluate if any members of ShadowMap should now be marked @private

@lilleyse
Copy link
Contributor

@lilleyse please evaluate if any members of ShadowMap should now be marked @Private

All looks good.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 23, 2017

@rahwang any update here?

@rahwang
Copy link
Contributor Author

rahwang commented Jan 24, 2017

Changes made, @pjcozzi . Now using scene instead of context.

Copy link
Contributor

@lilleyse lilleyse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. With a few tweaks I tested that the new normalOffset setter works well.

@@ -107,37 +107,28 @@ define([

/**
* Creates a shadow map from the provided light camera.
* <p>
* Use {@link Viewer#shadowMap}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to remove the indentation for this line.

Expand on the description a bit. Maybe Use {@link Viewer#shadowMap} to get the scene's shadow map originating from the sun. In general do not construct directly.

* @param {Number} [options.maximumDistance=5000.0] The maximum distance used for generating cascaded shadows. Lower values improve shadow quality.
* @param {Number} [options.size=2048] The width and height, in pixels, of each shadow map.
* @param {Boolean} [options.softShadows=false] Whether percentage-closer-filtering is enabled for producing softer shadows.
* @param {Number} [options.darkness=0.3] The shadow darkness.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still nice to keep these parameter descriptions even if the shadow map isn't meant to be constructed directly.

*
* @exception {DeveloperError} Only one or four cascades are supported.
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Shadows.html|Cesium Sandcastle Shadows Demo}
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line.

@@ -149,6 +140,8 @@ define([

this._enabled = defaultValue(options.enabled, true);
this._softShadows = defaultValue(options.softShadows, false);
this._normalOffset = defaultValue(options.normalOffset, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the parameters are added back to the doc, include normalOffset.

@@ -149,6 +140,8 @@ define([

this._enabled = defaultValue(options.enabled, true);
this._softShadows = defaultValue(options.softShadows, false);
this._normalOffset = defaultValue(options.normalOffset, true);
this._normalOffsetScale = defaultValue(options.normalOffsetScale, 0.1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not expose this right now as an option or a getter/setter. The default values used before are tuned for the different bias modes.

},
set : function(value) {
this.dirty = this._normalOffset !== value;
this._normalOffset = value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setter should also set this._terrainBias.normalOffset, this._primitiveBias.normalOffset, and this._pointBias.normalOffset,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test for this. It should be fine to set normalOffset to false and expect the normalOffset to be false for all the bias modes. I don't think this requires any rendering as part of the test.

@lilleyse
Copy link
Contributor

Looks good!

@lilleyse lilleyse merged commit 356b295 into CesiumGS:master Jan 25, 2017
@rahwang rahwang deleted the make-shadowMap-constructor-private branch January 25, 2017 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants