Skip to content

Commit

Permalink
Sun compute pass only happens when sun is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 5, 2015
1 parent fd12159 commit 9484bc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
7 changes: 3 additions & 4 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,10 @@ define([
executeCommand(skyAtmosphereCommand, scene, context, passState);
}

if (defined(sunComputeCommand)) {
sunComputeCommand.execute(scene._computeEngine);
}

if (sunVisible) {
if (defined(sunComputeCommand)) {
sunComputeCommand.execute(scene._computeEngine);
}
sunDrawCommand.execute(context, passState);
if (scene.sunBloom) {
var framebuffer;
Expand Down
22 changes: 10 additions & 12 deletions Source/Scene/Sun.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ define([
boundingVolume : new BoundingSphere(),
owner : this
});
this._computeCommand = new ComputeCommand({
persists : false,
owner : this
});
this._commands = {
drawCommand : undefined,
drawCommand : this._drawCommand,
computeCommand : undefined
};
this._boundingVolume = new BoundingSphere();
Expand Down Expand Up @@ -169,7 +165,6 @@ define([

var drawingBufferWidth = scene.drawingBufferWidth;
var drawingBufferHeight = scene.drawingBufferHeight;
var computeCommand;

if (!defined(this._texture) ||
drawingBufferWidth !== this._drawingBufferWidth ||
Expand Down Expand Up @@ -203,10 +198,15 @@ define([
}
};

computeCommand = this._computeCommand;
computeCommand.fragmentShaderSource = SunTextureFS;
computeCommand.outputTexture = this._texture;
computeCommand.uniformMap = uniformMap;
this._commands.computeCommand = new ComputeCommand({
fragmentShaderSource : SunTextureFS,
outputTexture : this._texture,
persists : false,
owner : this,
postExecute : function() {
that._commands.computeCommand = undefined;
}
});
}

var drawCommand = this._drawCommand;
Expand Down Expand Up @@ -308,8 +308,6 @@ define([
this._size = Math.ceil(Cartesian2.magnitude(Cartesian2.subtract(limbWC, positionWC, scratchCartesian4)));
this._size = 2.0 * this._size * (1.0 + 2.0 * this._glowLengthTS);

this._commands.drawCommand = drawCommand;
this._commands.computeCommand = computeCommand;
return this._commands;
};

Expand Down
8 changes: 4 additions & 4 deletions Specs/Renderer/ComputeCommandSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defineSuite([
}).toThrowDeveloperError();
});

it('renderer resources are destroyed if persists is set to false', function() {
it('renderer resources are preserved or destroyed based on the persists flag', function() {
var vertexShader = 'attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }';
var fragmentShader = 'void main() { gl_FragColor = vec4(1.0); }';
var shaderProgram = ShaderProgram.fromCache({
Expand Down Expand Up @@ -113,7 +113,7 @@ defineSuite([
outputTexture : outputTexture
});

// check that resources are not destroyed when persists is true
// check that resources are preserved when persists is true
computeCommand.persists = true;
scene.primitives.add(new CommandMockPrimitive(computeCommand));
scene.renderForSpecs();
Expand All @@ -124,8 +124,8 @@ defineSuite([
expect(vertexArray.isDestroyed()).toEqual(false);
expect(outputTexture.isDestroyed()).toEqual(false);

// check that resources are destroyed when persists is false
// except outputTexture which is not destroyed by the compute command
// check that resources are destroyed when persists is false, except
// outputTexture which is always preserved
computeCommand.persists = false;
scene.primitives.add(new CommandMockPrimitive(computeCommand));
scene.renderForSpecs();
Expand Down

0 comments on commit 9484bc0

Please sign in to comment.