Playing with pipeline to display outline
This commit is contained in:
parent
f6f90eea32
commit
f7466994c5
8 changed files with 162 additions and 0 deletions
0
front/src/Phaser/Items/ActionableItem.ts
Normal file
0
front/src/Phaser/Items/ActionableItem.ts
Normal file
0
front/src/Phaser/Items/ActionableSprite.ts
Normal file
0
front/src/Phaser/Items/ActionableSprite.ts
Normal file
|
@ -3,6 +3,7 @@ import {GameScene, Textures} from "../Game/GameScene";
|
|||
import {MessageUserPositionInterface, PointInterface} from "../../Connection";
|
||||
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
||||
import {Character} from "../Entity/Character";
|
||||
import {OutlinePipeline} from "../Shaders/OutlinePipeline";
|
||||
|
||||
|
||||
export const hasMovedEventName = "hasMoved";
|
||||
|
@ -32,6 +33,10 @@ export class Player extends Character implements CurrentGamerInterface {
|
|||
|
||||
//the current player model should be push away by other players to prevent conflict
|
||||
this.setImmovable(false);
|
||||
|
||||
this.setPipeline(OutlinePipeline.KEY);
|
||||
this.pipeline.setFloat2('uTextureSize',
|
||||
this.texture.getSourceImage().width, this.texture.getSourceImage().height);
|
||||
}
|
||||
|
||||
moveUser(delta: number): void {
|
||||
|
|
61
front/src/Phaser/Shaders/OutlinePipeline.ts
Normal file
61
front/src/Phaser/Shaders/OutlinePipeline.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
export class OutlinePipeline extends Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline
|
||||
{
|
||||
|
||||
// the unique id of this pipeline
|
||||
public static readonly KEY = 'Outline';
|
||||
|
||||
/**
|
||||
* @param {Phaser.Game} game - the controller of the game instance
|
||||
*/
|
||||
constructor(game: Phaser.Game)
|
||||
{
|
||||
super({
|
||||
game: game,
|
||||
renderer: game.renderer,
|
||||
fragShader: `
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D uMainSampler;
|
||||
uniform vec2 uTextureSize;
|
||||
|
||||
varying vec2 outTexCoord;
|
||||
varying float outTintEffect;
|
||||
varying vec4 outTint;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 texture = texture2D(uMainSampler, outTexCoord);
|
||||
vec4 texel = vec4(outTint.rgb * outTint.a, outTint.a);
|
||||
vec4 color = texture;
|
||||
|
||||
if (outTintEffect == 0.0)
|
||||
{
|
||||
color = texture * texel;
|
||||
}
|
||||
else if (outTintEffect == 1.0)
|
||||
{
|
||||
color.rgb = mix(texture.rgb, outTint.rgb * outTint.a, texture.a);
|
||||
color.a = texture.a * texel.a;
|
||||
}
|
||||
else if (outTintEffect == 2.0)
|
||||
{
|
||||
color = texel;
|
||||
}
|
||||
|
||||
vec2 onePixel = vec2(1.0, 1.0) / uTextureSize;
|
||||
float upAlpha = texture2D(uMainSampler, outTexCoord + vec2(0.0, onePixel.y)).a;
|
||||
float leftAlpha = texture2D(uMainSampler, outTexCoord + vec2(-onePixel.x, 0.0)).a;
|
||||
float downAlpha = texture2D(uMainSampler, outTexCoord + vec2(0.0, -onePixel.y)).a;
|
||||
float rightAlpha = texture2D(uMainSampler, outTexCoord + vec2(onePixel.x, 0.0)).a;
|
||||
|
||||
if (texture.a == 0.0 && max(max(upAlpha, downAlpha), max(leftAlpha, rightAlpha)) == 1.0)
|
||||
{
|
||||
color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
`
|
||||
});
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ import {gameManager} from "./Phaser/Game/GameManager";
|
|||
import {SelectCharacterScene} from "./Phaser/Login/SelectCharacterScene";
|
||||
import {EnableCameraScene} from "./Phaser/Login/EnableCameraScene";
|
||||
import {FourOFourScene} from "./Phaser/Reconnecting/FourOFourScene";
|
||||
import WebGLRenderer = Phaser.Renderer.WebGL.WebGLRenderer;
|
||||
import {OutlinePipeline} from "./Phaser/Shaders/OutlinePipeline";
|
||||
|
||||
const config: GameConfig = {
|
||||
title: "Office game",
|
||||
|
@ -21,6 +23,13 @@ const config: GameConfig = {
|
|||
arcade: {
|
||||
debug: DEBUG_MODE
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
postBoot: game => {
|
||||
// FIXME: we should fore WebGL in the config.
|
||||
let renderer = game.renderer as WebGLRenderer;
|
||||
renderer.addPipeline(OutlinePipeline.KEY, new OutlinePipeline(game));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue