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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <canvas id="app-canvas"/>
              
            
!

CSS

              
                canvas {
  display: block;
  position: absolute;
  transform: translate(-50%, -50%) scale(4);
  left: 50%;
  top: 50%;
  image-rendering: pixelated;
}
body {
  background: radial-gradient(ellipse at center, #353535 0%, #141414 100%);
}

              
            
!

JS

              
                const { Filter, Matrix, RenderTexture, Sprite, systems, Texture } = PIXI;

const vertex = `
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;

uniform mat3 projectionMatrix;
varying vec2 vTextureCoord;

uniform mat3 shadowMapMatrix;
varying vec2 vShadowMapCoord;

void main(void)
{
    gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);

    vTextureCoord = aTextureCoord;
    vShadowMapCoord = (shadowMapMatrix * vec3(aTextureCoord, 1.0)).xy;   
}`;

const fragment = `
precision highp float;

varying vec2 vTextureCoord;
uniform vec4 inputPixel;

varying vec2 vShadowMapCoord;
uniform sampler2D shadowMapTexture;

void main() {
  vec4 shadowColor = vec4(1, 0, 0, 1);

  vec2 displacementCoord = vShadowMapCoord;
  vec4 shadowMapColor = texture2D(shadowMapTexture, vShadowMapCoord);
  vec4 finalColor;
  vec4 translateColor;

  vec2 translate = vec2(1.0/80.0,-1.0/80.0);
  for(int i= 0; i < 10; i++) {
    displacementCoord -= translate;
    translateColor = texture2D(shadowMapTexture, displacementCoord);
    if (translateColor.x > 0.0 && shadowMapColor.x == 0.0) {
      finalColor = shadowColor;
      break;
    }
  }
	gl_FragColor = finalColor;
}`;

interface ShadowsHardUniforms {
  shadowMapTexture: Texture;
  shadowMapMatrix: Matrix;
}

class ShadowsHardFilter extends Filter {
  public uniforms: ShadowsHardUniforms;

  private _wallSprite: Sprite;
  private _shadowMapSprite: Sprite;
  private _matrix: Matrix;
  private _matrix2: Matrix;

  constructor(shadowMapSprite: Sprite) {
    super(vertex, fragment, undefined);
    this.uniforms.shadowMapTexture = shadowMapSprite.texture;
    this._shadowMapSprite = shadowMapSprite;
    this._matrix = new Matrix();
  }

  public apply(
    filterManager: systems.FilterSystem,
    input: RenderTexture,
    output: RenderTexture,
    clearMode: boolean
  ): void {
    this.uniforms.shadowMapMatrix = filterManager.calculateSpriteMatrix(
      this._matrix,
      this._shadowMapSprite
    );
    filterManager.applyFilter(this, input, output, clearMode);
  }
}

PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
const app = new PIXI.Application({
  width: 16 * 6,
  height: 16 * 6,
  transparent: true,
  view: document.getElementById("app-canvas") as HTMLCanvasElement
});
document.body.appendChild(app.view);

app.loader
  .add("b1", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/298669/test-01.png")
  .load((loader, resources) => {
    const tex = resources.b1.texture;
    const shadowMapSp = new Sprite(resources.b1.texture);
    console.log(tex.width);
    console.log(tex.height);
    const shadowsHardTex: RenderTexture = RenderTexture.create({
      width: tex.width,
      height: tex.height
    });
    const shadowsHardSp = new Sprite(shadowsHardTex);
    const filter = new ShadowsHardFilter(shadowMapSp);
    shadowsHardSp.alpha = 0.8;
    shadowsHardSp.filters = [filter];
    app.renderer.render(shadowsHardSp, shadowsHardTex, false);
    app.stage.addChild(shadowsHardSp);
    app.stage.addChild(shadowMapSp);
  });

              
            
!
999px

Console