From 83c0be796113211ccdb906fd9b0e006e8d0c1953 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 16 Dec 2022 14:54:50 +0100 Subject: [PATCH] White sprite shader --- assets/Media/Materials/builtin-sprite.effect | 91 ------------------- .../Materials/builtin-sprite.effect.meta | 1 - assets/Media/Materials/white-sprite.effect | 5 +- .../{material.mtl => white-sprite.mtl} | 0 ...aterial.mtl.meta => white-sprite.mtl.meta} | 0 assets/Scripts/Game/Unit/Player/Player.ts | 11 ++- 6 files changed, 9 insertions(+), 99 deletions(-) delete mode 100644 assets/Media/Materials/builtin-sprite.effect delete mode 100644 assets/Media/Materials/builtin-sprite.effect.meta rename assets/Media/Materials/{material.mtl => white-sprite.mtl} (100%) rename assets/Media/Materials/{material.mtl.meta => white-sprite.mtl.meta} (100%) diff --git a/assets/Media/Materials/builtin-sprite.effect b/assets/Media/Materials/builtin-sprite.effect deleted file mode 100644 index 86e1d95..0000000 --- a/assets/Media/Materials/builtin-sprite.effect +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. -CCEffect %{ - techniques: - - passes: - - vert: sprite-vs:vert - frag: sprite-fs:frag - depthStencilState: - depthTest: false - depthWrite: false - blendState: - targets: - - blend: true - blendSrc: src_alpha - blendDst: one_minus_src_alpha - blendDstAlpha: one_minus_src_alpha - rasterizerState: - cullMode: none - properties: - alphaThreshold: { value: 0.5 } -}% - -CCProgram sprite-vs %{ - precision highp float; - #include - #if USE_LOCAL - #include - #endif - #if SAMPLE_FROM_RT - #include - #endif - in vec3 a_position; - in vec2 a_texCoord; - in vec4 a_color; - - out vec4 color; - out vec2 uv0; - - vec4 vert () { - vec4 pos = vec4(a_position, 1); - - #if USE_LOCAL - pos = cc_matWorld * pos; - #endif - - #if USE_PIXEL_ALIGNMENT - pos = cc_matView * pos; - pos.xyz = floor(pos.xyz); - pos = cc_matProj * pos; - #else - pos = cc_matViewProj * pos; - #endif - - uv0 = a_texCoord; - #if SAMPLE_FROM_RT - CC_HANDLE_RT_SAMPLE_FLIP(uv0); - #endif - color = a_color; - - return pos; - } -}% - -CCProgram sprite-fs %{ - precision highp float; - #include - #include - - in vec4 color; - - #if USE_TEXTURE - in vec2 uv0; - #pragma builtin(local) - layout(set = 2, binding = 11) uniform sampler2D cc_spriteTexture; - #endif - - vec4 frag () { - vec4 o = vec4(1, 1, 1, 1); - - #if USE_TEXTURE - o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0); - #if IS_GRAY - float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b; - o.r = o.g = o.b = gray; - #endif - #endif - - o *= color; - ALPHA_TEST(o); - return o; - } -}% diff --git a/assets/Media/Materials/builtin-sprite.effect.meta b/assets/Media/Materials/builtin-sprite.effect.meta deleted file mode 100644 index 01736b0..0000000 --- a/assets/Media/Materials/builtin-sprite.effect.meta +++ /dev/null @@ -1 +0,0 @@ -{"ver":"1.6.0","importer":"effect","imported":true,"uuid":"3c0cc5ba-c2cb-4948-a991-ea3b91b58798","files":[".json"],"subMetas":{},"userData":{"combinations":[{}]}} diff --git a/assets/Media/Materials/white-sprite.effect b/assets/Media/Materials/white-sprite.effect index 6523e3e..3e1a70c 100644 --- a/assets/Media/Materials/white-sprite.effect +++ b/assets/Media/Materials/white-sprite.effect @@ -54,7 +54,7 @@ CCProgram sprite-vs %{ #if SAMPLE_FROM_RT CC_HANDLE_RT_SAMPLE_FLIP(uv0); #endif - color = vec4(1, 1, 1, 1); + color = a_color; return pos; } @@ -80,8 +80,7 @@ CCProgram sprite-fs %{ o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0); #endif - - ALPHA_TEST(o); + o = vec4(1,1,1, o.a); return o; } }% diff --git a/assets/Media/Materials/material.mtl b/assets/Media/Materials/white-sprite.mtl similarity index 100% rename from assets/Media/Materials/material.mtl rename to assets/Media/Materials/white-sprite.mtl diff --git a/assets/Media/Materials/material.mtl.meta b/assets/Media/Materials/white-sprite.mtl.meta similarity index 100% rename from assets/Media/Materials/material.mtl.meta rename to assets/Media/Materials/white-sprite.mtl.meta diff --git a/assets/Scripts/Game/Unit/Player/Player.ts b/assets/Scripts/Game/Unit/Player/Player.ts index e39c487..e858f4d 100644 --- a/assets/Scripts/Game/Unit/Player/Player.ts +++ b/assets/Scripts/Game/Unit/Player/Player.ts @@ -1,4 +1,4 @@ -import { Animation, Node, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc"; +import { Animation, Node, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator, Details } from "cc"; import { IInput } from "../../Input/IInput"; import { UnitHealth } from "../UnitHealth"; import { UnitLevel } from "../UnitLevel"; @@ -57,6 +57,12 @@ export class Player extends Component { } public gameTick(deltaTime: number): void { + this.move(deltaTime); + this.weapon.gameTick(deltaTime); + this.regeneration.gameTick(deltaTime); + } + + private move(deltaTime: number): void { const movement: Vec2 = this.input.getAxis(); if (!movement.equals(Vec2.ZERO)) { movement.x *= deltaTime * this.speed; @@ -84,9 +90,6 @@ export class Player extends Component { this.animation.play("Idle"); } } - - this.weapon.gameTick(deltaTime); - this.regeneration.gameTick(deltaTime); } }