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

Fix shadowed models in 2D #4382

Merged
merged 4 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Source/Scene/OIT.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ define([
var framebuffer = passState.framebuffer;
var length = commands.length;

var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;

passState.framebuffer = oit._adjustTranslucentFBO;
oit._adjustTranslucentCommand.execute(context, passState);
passState.framebuffer = oit._adjustAlphaFBO;
Expand All @@ -535,15 +537,15 @@ define([

for (j = 0; j < length; ++j) {
command = commands[j];
derivedCommand = command.derivedCommands.oit.translucentCommand;
derivedCommand = shadowsEnabled ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

passState.framebuffer = oit._alphaFBO;

for (j = 0; j < length; ++j) {
command = commands[j];
derivedCommand = command.derivedCommands.oit.alphaCommand;
derivedCommand = shadowsEnabled ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

Expand All @@ -555,6 +557,8 @@ define([
var framebuffer = passState.framebuffer;
var length = commands.length;

var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;

passState.framebuffer = oit._adjustTranslucentFBO;
oit._adjustTranslucentCommand.execute(context, passState);

Expand All @@ -563,7 +567,7 @@ define([

for (var j = 0; j < length; ++j) {
var command = commands[j];
var derivedCommand = command.derivedCommands.oit.translucentCommand;
var derivedCommand = shadowsEnabled ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

Expand Down
27 changes: 16 additions & 11 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,15 +1108,13 @@ define([
var lightShadowMaps = frameState.shadowHints.lightShadowMaps;
var lightShadowsEnabled = shadowsEnabled && (lightShadowMaps.length > 0);

// Update derived commands when any shadow maps become dirty
var shadowsDirty = false;
if (shadowsEnabled && (command.receiveShadows || command.castShadows)) {
// Update derived commands when any shadow maps become dirty
var lastDirtyTime = frameState.shadowHints.lastDirtyTime;
if (command.lastDirtyTime !== lastDirtyTime) {
command.lastDirtyTime = lastDirtyTime;
command.dirty = true;
shadowsDirty = true;
}
var lastDirtyTime = frameState.shadowHints.lastDirtyTime;
if (command.lastDirtyTime !== lastDirtyTime) {
command.lastDirtyTime = lastDirtyTime;
command.dirty = true;
shadowsDirty = true;
}

if (command.dirty) {
Expand All @@ -1131,7 +1129,8 @@ define([
var oit = scene._oit;
if (command.pass === Pass.TRANSLUCENT && defined(oit) && oit.isSupported()) {
if (lightShadowsEnabled && command.receiveShadows) {
derivedCommands.oit = oit.createDerivedCommands(command.derivedCommands.shadows.receiveCommand, context, derivedCommands.oit);
derivedCommands.oit = defined(derivedCommands.oit) ? derivedCommands.oit : {};
derivedCommands.oit.shadows = oit.createDerivedCommands(command.derivedCommands.shadows.receiveCommand, context, derivedCommands.oit.shadows);
} else {
derivedCommands.oit = oit.createDerivedCommands(command, context, derivedCommands.oit);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly I think this area can be

if (lightShadowsEnabled && command.receiceShadows) {
    create derivedCommands.oit.shadows
} else {
    create derivedCommands.oit
}

Expand Down Expand Up @@ -2144,8 +2143,14 @@ define([
var shadowMaps = frameState.shadowMaps;
var length = shadowMaps.length;

frameState.shadowHints.shadowsEnabled = (length > 0) && !frameState.passes.pick && (scene.mode === SceneMode.SCENE3D);
if (!frameState.shadowHints.shadowsEnabled) {
var shadowsEnabled = (length > 0) && !frameState.passes.pick && (scene.mode === SceneMode.SCENE3D);
if (shadowsEnabled !== frameState.shadowHints.shadowsEnabled) {
// Update derived commands when shadowsEnabled changes
++frameState.shadowHints.lastDirtyTime;
frameState.shadowHints.shadowsEnabled = shadowsEnabled;
}

if (!shadowsEnabled) {
return;
}

Expand Down