Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="renderer">
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                var lightUrl = 'https://i.imgur.com/6fKrOon.png';
var tiledmapUrl = 'https://i.imgur.com/jZkohZU.png';
var pixelUrl = 'https://i.imgur.com/4xQ3444.png';

var fragmentShader = [
'precision mediump float;',
'varying vec4 vColor;',
'varying vec2 vTextureCoord;',
'uniform sampler2D u_texture;',
'uniform vec4 ambientColor;',
'void main() {',
'    vec4 diffuseColor = texture2D(u_texture, vTextureCoord);',
'    vec3 ambient = ambientColor.rgb * ambientColor.a;',
'    vec3 final = vec3(vColor) * diffuseColor.rgb * ambient;',
'    gl_FragColor = vec4(final, diffuseColor.a);',
'}'
].join('\n');

var sphereLightFragment = [
'precision mediump float;',
'varying vec4 vColor;',
'varying vec2 vTextureCoord;',
'uniform sampler2D u_texture;',
'uniform sampler2D u_lightmap;',
'uniform vec2 resolution;',
'void main() {',
'    vec2 lighCoord = (gl_FragCoord.xy / resolution.xy);',
'    vec4 Light = texture2D(u_lightmap, lighCoord);',
'    gl_FragColor = vColor * Light;',
'}'
].join('\n');
function AmbiantLightFilter() {
  var foo;
  PIXI.AbstractFilter.call(
    this,
    null,
    fragmentShader,
    {
      ambientColor: {
        type: '4f', 
        value: new Float32Array([0.3, 0.3, 0.7, .9])
      }
    });
}

AmbiantLightFilter.prototype = Object.create(PIXI.AbstractFilter.prototype);
AmbiantLightFilter.prototype.constructor = AmbiantLightFilter;

function SphereLightFilter(lightmapTex) {
  this.lightmapTex = lightmapTex;
  PIXI.AbstractFilter.call(
    this,
    null,
    sphereLightFragment,
    {
      resolution: {
        type: '2f', 
        value: new Float32Array([0.3, 0.3])
      }
    });
  
  this.defaultFilter = new PIXI.AbstractFilter();
}

/*SphereLightFilter.prototype.applyFilter = function (renderer, input, output) {
  
}*/

SphereLightFilter.prototype = Object.create(PIXI.AbstractFilter.prototype);
SphereLightFilter.prototype.constructor = SphereLightFilter;


var img = new Image();
img.crossOrigin = "Anonymous";
img.src = lightUrl;
img.onload = function () {
// create an new instance of a pixi stage
var stage = new PIXI.Stage(0x66FF99);
 
// create a renderer instance.
var renderer = PIXI.autoDetectRenderer(400, 300);

var renderTexture = new PIXI.RenderTexture(renderer, 400, 300);

var lightBaseTexture = new PIXI.BaseTexture(img);
var lightTexture = new PIXI.Texture(lightBaseTexture);
var lightSprite = new PIXI.Sprite(lightTexture);
//lightSprite.anchor.x = 0.5;
//lightSprite.anchor.y = 0.5;
renderTexture.render(lightSprite);
  
var lightmapSprite = new PIXI.Sprite(renderTexture);
lightmapSprite.filters = null;
  
var tiledmapSprite = new PIXI.Sprite.fromImage(tiledmapUrl);
tiledmapSprite.filters = [new AmbiantLightFilter(), new SphereLightFilter(renderTexture)];
console.log(renderTexture);

stage.addChild(tiledmapSprite);
//stage.addChild(lightmapSprite);
// add the renderer view element to the DOM
document.body.appendChild(renderer.view);
 
requestAnimationFrame( animate );
 
function animate() {
 
  requestAnimationFrame( animate );

  // render the stage   
  renderer.render(stage);
}
  
};
              
            
!
999px

Console