Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////// DEFINITION ////////////////////
- pc.extend(pc, function () {
- /**
- * @name pc.MyEffect
- * @class Implements the MyEffect post processing effect
- * @constructor Creates new instance of MyEffect
- * @extends pc.PostEffect
- * @param {app.graphicsDevice} graphicsDevice The graphics device of the application
- * @param {width} width
- * @param {height} height
- */
- var MyEffect = function (graphicsDevice, width, height) {
- /*
- var width = graphicsDevice.width;
- var height = graphicsDevice.height;
- */
- // Shaders
- var attributes = {
- aPosition: pc.SEMANTIC_POSITION
- };
- var passThroughVert = [
- "attribute vec2 aPosition;",
- "",
- "varying vec2 vUv0;",
- "",
- "void main(void)",
- "{",
- " gl_Position = vec4(aPosition, 0.0, 1.0);",
- " vUv0 = (aPosition + 1.0) * 0.5;",
- "}"
- ].join("\n");
- var fragment1 = [
- "varying vec2 vUv0;",
- "",
- "uniform sampler2D inputTexture;",
- "",
- "void main(void)",
- "{",
- // Look up the original image color.
- " vec4 color = texture2D(inputTexture, vUv0);",
- " gl_FragColor = color;",
- "}"
- ].join("\n");
- var fragment2 = [
- "varying vec2 vUv0;",
- "",
- "uniform sampler2D inputTexture;",
- "",
- "void main(void)",
- "{",
- // Look up the original image color.
- " vec4 color = texture2D(inputTexture, vUv0);",
- " gl_FragColor = color;",
- "}"
- ].join("\n");
- this.shader1 = new pc.Shader(graphicsDevice, {
- attributes: attributes,
- vshader: passThroughVert,
- fshader: fragment1
- });
- this.shader2 = new pc.Shader(graphicsDevice, {
- attributes: attributes,
- vshader: passThroughVert,
- fshader: fragment2
- });
- // Render targets
- this.targets = [];
- for (var i = 0; i < 1; i++) {
- var colorBuffer = new pc.Texture(graphicsDevice, {
- format: pc.PIXELFORMAT_R8_G8_B8,
- width: width >> 1,
- height: height >> 1
- });
- colorBuffer.minFilter = pc.FILTER_LINEAR;
- colorBuffer.magFilter = pc.FILTER_LINEAR;
- colorBuffer.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
- colorBuffer.addressV = pc.ADDRESS_CLAMP_TO_EDGE;
- var target = new pc.RenderTarget(graphicsDevice, colorBuffer, { depth: false });
- this.targets.push(target);
- }
- };
- MyEffect.prototype = pc.extend(MyEffect.prototype, {
- // inputTarget is a RenderTarget
- // outputTarget is a RenderTarget
- render: function (inputTarget, outputTarget, rect) {
- var device = this.device;
- var scope = device.scope;
- // Pass 1: draw the scene into rendertarget 1
- scope.resolve("inputTexture").setValue(inputTarget.colorBuffer);
- pc.drawFullscreenQuad(device, this.targets[0], this.vertexBuffer, this.shader1);
- // Pass 2: draw the scene into rendertarget 2
- scope.resolve("inputTexture").setValue(this.targets[0].colorBuffer);
- pc.drawFullscreenQuad(device, outputTarget, this.vertexBuffer, this.shader2, rect);
- }
- });
- return {
- MyEffect: MyEffect
- };
- }());
- //////////////////// BLOOM SCRIPT DEFINITION ////////////////////
- var BloomScript = pc.createScript('BloomScript');
- // Initialize BloomScript, not to be confused with MyEffect
- BloomScript.prototype.initialize = function() {
- this.effect = new pc.MyEffect(this.app.graphicsDevice, 1000, 1000);
- // When attribute is changed in editor
- this.on('attr', function(name, value, prev) {
- this.effect[name] = value;
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement