Commit 7eab074d authored by haiyoucuv's avatar haiyoucuv

光幕粒子

parent 8005defc
This diff is collapsed.
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- name: opaque
passes:
- vert: unlit-vs:vert
frag: unlit-fs:frag
properties: &props
mainTexture: { value: grey }
particleTexture: { value: grey }
tilingOffset: { value: [1, 1, 0, 0] }
mainColor: { value: [1, 1, 1, 1], linear: true, editor: { type: color } }
colorScale: { value: [1, 1, 1], target: colorScaleAndCutoff.xyz }
alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
color: { target: mainColor, linear: true, editor: { visible: false } } # backward compability
migrations: &migs
properties:
mainColor: { formerlySerializedAs: color }
- &planar-shadow
vert: planar-shadow-vs:vert
frag: planar-shadow-fs:frag
phase: planar-shadow
propertyIndex: 0
depthStencilState:
depthTest: true
depthWrite: false
stencilTestFront: true
stencilFuncFront: not_equal
stencilPassOpFront: replace
stencilRef: 0x80 # only use the leftmost bit
stencilReadMask: 0x80
stencilWriteMask: 0x80
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendDstAlpha: one_minus_src_alpha
- &deferred-forward
vert: unlit-vs:vert
frag: unlit-fs:frag
phase: deferred-forward
propertyIndex: 0
- name: transparent
passes:
- vert: unlit-vs:vert
frag: unlit-fs:frag
depthStencilState: &d1
depthTest: true
depthWrite: false
blendState: &b1
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendDstAlpha: one_minus_src_alpha
properties: *props
migrations: *migs
- *planar-shadow
- &deferred-forward-transparent
vert: unlit-vs:vert
frag: unlit-fs:frag
phase: deferred-forward
propertyIndex: 0
migrations: *migs
depthStencilState: *d1
blendState: *b1
- name: add
passes:
- vert: unlit-vs:vert
frag: unlit-fs:frag
rasterizerState: &r1 { cullMode: none }
depthStencilState: *d1
blendState: &b2
targets:
- blend: true
blendSrc: src_alpha
blendDst: one
blendSrcAlpha: src_alpha
blendDstAlpha: one
properties: *props
migrations: *migs
- &deferred-forward-add
vert: unlit-vs:vert
frag: unlit-fs:frag
phase: deferred-forward
rasterizerState: *r1
depthStencilState: *d1
blendState: *b2
propertyIndex: 0
migrations: *migs
- name: alpha-blend
passes:
- vert: unlit-vs:vert
frag: unlit-fs:frag
rasterizerState: *r1
depthStencilState: *d1
blendState: &b3
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendSrcAlpha: src_alpha
blendDstAlpha: one_minus_src_alpha
properties: *props
migrations: *migs
- &deferred-forward-alpha-blend
vert: unlit-vs:vert
frag: unlit-fs:frag
phase: deferred-forward
rasterizerState: *r1
depthStencilState: *d1
blendState: *b3
propertyIndex: 0
migrations: *migs
}%
CCProgram unlit-vs %{
precision highp float;
#include <legacy/input>
#include <builtin/uniforms/cc-global>
#include <legacy/decode-base>
#include <legacy/local-batch>
#include <legacy/input>
#include <legacy/fog-vs>
#if USE_VERTEX_COLOR
in lowp vec4 a_color;
out lowp vec4 v_color;
#endif
#if USE_TEXTURE
out vec2 v_uv;
uniform TexCoords {
vec4 tilingOffset;
};
#endif
vec4 vert () {
vec4 position;
CCVertInput(position);
mat4 matWorld;
CCGetWorldMatrix(matWorld);
#if USE_TEXTURE
v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;
#if SAMPLE_FROM_RT
CC_HANDLE_RT_SAMPLE_FLIP(v_uv);
#endif
#endif
#if USE_VERTEX_COLOR
v_color = a_color;
#endif
CC_TRANSFER_FOG(matWorld * position);
return cc_matProj * (cc_matView * matWorld) * position;
}
}%
CCProgram unlit-fs %{
precision highp float;
#include <legacy/output-standard>
#include <legacy/fog-fs>
#include <builtin/uniforms/cc-global>
#if USE_ALPHA_TEST
#pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])
#endif
#if USE_TEXTURE
in vec2 v_uv;
uniform sampler2D mainTexture;
uniform sampler2D particleTexture;
#endif
uniform Constant {
vec4 mainColor;
vec4 colorScaleAndCutoff;
};
#if USE_VERTEX_COLOR
in lowp vec4 v_color;
#endif
vec4 frag () {
vec4 o = mainColor;
o.rgb *= colorScaleAndCutoff.xyz;
#if USE_VERTEX_COLOR
o.rgb *= SRGBToLinear(v_color.rgb);//use linear
o.a *= v_color.a;
#endif
#if USE_TEXTURE
vec4 texColor = texture(mainTexture, v_uv);
vec2 uv = v_uv;
uv.y += cc_time.x / 10.0;
vec4 particleColor = texture(particleTexture, uv);
texColor += particleColor;
texColor.rgb = SRGBToLinear(texColor.rgb);
o *= texColor;
#endif
#if USE_ALPHA_TEST
if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
#endif
CC_APPLY_FOG(o);
return CCFragOutput(o);
}
}%
CCProgram planar-shadow-vs %{
precision highp float;
#include <legacy/input>
#include <builtin/uniforms/cc-global>
#include <legacy/decode-base>
#include <legacy/local-batch>
#include <builtin/uniforms/cc-shadow>
#include <common/lighting/functions>
out float v_dist;
vec4 vert () {
vec4 position;
CCVertInput(position);
// World Space
mat4 matWorld, matWorldIT;
CCGetWorldMatrixFull(matWorld, matWorldIT);
vec3 worldPos = (matWorld * position).xyz;
vec4 shadowPos = CalculatePlanarShadowPos(worldPos, cc_cameraPos.xyz, cc_mainLitDir.xyz, cc_planarNDInfo);
position = CalculatePlanarShadowClipPos(shadowPos, cc_cameraPos.xyz, cc_matView, cc_matProj, cc_nearFar, cc_shadowWHPBInfo.w);
v_dist = shadowPos.w;
return position;
}
}%
CCProgram planar-shadow-fs %{
precision highp float;
#include <builtin/uniforms/cc-shadow>
#include <legacy/output>
in float v_dist;
vec4 frag () {
if(v_dist < 0.0)
discard;
return CCFragOutput(cc_shadowColor);
}
}%
{
"ver": "1.7.1",
"importer": "effect",
"imported": true,
"uuid": "2da8908c-0cfa-42b9-a096-d2a8c3077dfe",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
{
"__type__": "cc.Material",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"_effectAsset": {
"__uuid__": "2da8908c-0cfa-42b9-a096-d2a8c3077dfe",
"__expectedType__": "cc.EffectAsset"
},
"_techIdx": 2,
"_defines": [
{
"USE_INSTANCING": true,
"USE_TEXTURE": true
},
{}
],
"_states": [
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
},
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
}
],
"_props": [
{
"mainTexture": {
"__uuid__": "f6df98d9-6a78-4b37-819c-b85c91dd9046@6c48a",
"__expectedType__": "cc.Texture2D"
},
"particleTexture": {
"__uuid__": "27625008-7534-479b-be2b-3266f5eb51ef@6c48a",
"__expectedType__": "cc.Texture2D"
}
},
{}
]
}
\ No newline at end of file
{"ver":"1.0.21","importer":"material","imported":true,"uuid":"3c0aedbc-593b-4d89-9145-0714810d35d5","files":[".json"],"subMetas":{},"userData":{}}
{
"__type__": "cc.Material",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"_effectAsset": {
"__uuid__": "a3cd009f-0ab0-420d-9278-b9fdab939bbc",
"__expectedType__": "cc.EffectAsset"
},
"_techIdx": 2,
"_defines": [
{
"USE_INSTANCING": true,
"USE_TEXTURE": true
},
{}
],
"_states": [
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
},
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
}
],
"_props": [
{
"mainTexture": {
"__uuid__": "c5420122-73de-4379-bb8d-6e4fc74b14e1@6c48a",
"__expectedType__": "cc.Texture2D"
}
},
{}
]
}
\ No newline at end of file
{
"ver": "1.0.21",
"importer": "material",
"imported": true,
"uuid": "9518c0cb-641d-4f31-8e82-5da4ae3d507c",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
......@@ -594,6 +594,14 @@
"__id__": 13
},
"isInit": false,
"lightPrefab": {
"__uuid__": "9f30d580-4fa7-48b4-af7f-460d23e3c9e0",
"__expectedType__": "cc.Prefab"
},
"ringPrefab": {
"__uuid__": "92797147-1d66-471c-a539-78bceda0ebaf",
"__expectedType__": "cc.Prefab"
},
"_id": ""
},
{
......
[
{
"__type__": "cc.Prefab",
"_name": "光幕",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "光幕",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 5
},
{
"__id__": 7
}
],
"_prefab": {
"__id__": 9
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 4,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.MeshRenderer",
"_name": "Quad<ModelComponent>",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_materials": [
{
"__uuid__": "3c0aedbc-593b-4d89-9145-0714810d35d5",
"__expectedType__": "cc.Material"
}
],
"_visFlags": 0,
"bakeSettings": {
"__id__": 4
},
"_mesh": {
"__uuid__": "1263d74c-8167-4928-91a6-4e2672411f47@fc873",
"__expectedType__": "cc.Mesh"
},
"_shadowCastingMode": 0,
"_shadowReceivingMode": 1,
"_shadowBias": 0,
"_shadowNormalBias": 0,
"_reflectionProbeId": -1,
"_reflectionProbeBlendId": -1,
"_reflectionProbeBlendWeight": 0,
"_enabledGlobalStandardSkinObject": false,
"_enableMorph": true,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "1esW4ppkxLe5XPsWE+qAlV"
},
{
"__type__": "cc.ModelBakeSettings",
"texture": null,
"uvParam": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_bakeable": false,
"_castShadow": false,
"_receiveShadow": false,
"_recieveShadow": false,
"_lightmapSize": 64,
"_useLightProbe": false,
"_bakeToLightProbe": true,
"_reflectionProbeType": 0,
"_bakeToReflectionProbe": true
},
{
"__type__": "cc.RigidBody",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 6
},
"_group": 16,
"_type": 2,
"_mass": 1,
"_allowSleep": true,
"_linearDamping": 0.1,
"_angularDamping": 0.1,
"_useGravity": true,
"_linearFactor": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_angularFactor": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "adOM9abJ9K9r9tHOQOdFB/"
},
{
"__type__": "cc.BoxCollider",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 8
},
"_material": null,
"_isTrigger": true,
"_center": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -0.25
},
"_size": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "7foxUj5fJFh6p76ymjuNPN"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "51Y9gslglDXYKIJMxhL9pl",
"targetOverrides": null
}
]
\ No newline at end of file
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "9f30d580-4fa7-48b4-af7f-460d23e3c9e0",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "光幕"
}
}
[
{
"__type__": "cc.Prefab",
"_name": "圆环",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "圆环",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 5
},
{
"__id__": 7
}
],
"_prefab": {
"__id__": 9
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.MeshRenderer",
"_name": "Quad<ModelComponent>",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_materials": [
{
"__uuid__": "9518c0cb-641d-4f31-8e82-5da4ae3d507c",
"__expectedType__": "cc.Material"
}
],
"_visFlags": 0,
"bakeSettings": {
"__id__": 4
},
"_mesh": {
"__uuid__": "1263d74c-8167-4928-91a6-4e2672411f47@fc873",
"__expectedType__": "cc.Mesh"
},
"_shadowCastingMode": 0,
"_shadowReceivingMode": 1,
"_shadowBias": 0,
"_shadowNormalBias": 0,
"_reflectionProbeId": -1,
"_reflectionProbeBlendId": -1,
"_reflectionProbeBlendWeight": 0,
"_enabledGlobalStandardSkinObject": false,
"_enableMorph": true,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "03EPHmR75GcYq5CJ8OJb6h"
},
{
"__type__": "cc.ModelBakeSettings",
"texture": null,
"uvParam": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_bakeable": false,
"_castShadow": false,
"_receiveShadow": false,
"_recieveShadow": false,
"_lightmapSize": 64,
"_useLightProbe": false,
"_bakeToLightProbe": true,
"_reflectionProbeType": 0,
"_bakeToReflectionProbe": true
},
{
"__type__": "cc.RigidBody",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 6
},
"_group": 1,
"_type": 2,
"_mass": 1,
"_allowSleep": true,
"_linearDamping": 0.1,
"_angularDamping": 0.1,
"_useGravity": true,
"_linearFactor": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_angularFactor": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "44yph2cU1NXYAQITb6YGON"
},
{
"__type__": "cc.BoxCollider",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 8
},
"_material": null,
"_isTrigger": false,
"_center": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -0.25
},
"_size": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "38zENHn5FE9a5DFQtDZWIi"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "40QKTBsKxLooiCP4/ZePDg",
"instance": null,
"targetOverrides": null
}
]
\ No newline at end of file
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "92797147-1d66-471c-a539-78bceda0ebaf",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "圆环"
}
}
......@@ -2,7 +2,7 @@ import {
_decorator, Collider, CollisionEventType, ICollisionEvent,
Input,
input,
instantiate,
instantiate, ITriggerEvent, Label,
Node, ParticleSystem, PhysicsGroup, PhysicsSystem,
PointToPointConstraint,
Prefab,
......@@ -38,6 +38,19 @@ export class MainGame extends Scene {
@property(Node) crushNode: Node = null;
@property({type: Label, group: "UI"}) scoreLabel: Label = null;
_score: number = 0;
set score(value: number) {
this._score = value;
this.scoreLabel.string = value.toString();
}
get score() {
return this._score;
}
isTouch = false;
pNoise: ImprovedNoise = new ImprovedNoise();
......@@ -56,6 +69,11 @@ export class MainGame extends Scene {
this.player.getComponent(Collider)
.on("onCollisionEnter", this.onPlayerCollision, this);
this.player.getComponent(Collider)
.on('onTriggerEnter', this.onTriggerEnter, this);
this.wallArr[4] = this.initWall;
for (let i = 0; i <= 3; i++) {
this.wallArr[i] = this.createCube(4 - i);
......@@ -64,6 +82,7 @@ export class MainGame extends Scene {
for (let i = 5; i <= 10; i++) {
this.wallArr[i] = this.createCube();
}
}
async start() {
......@@ -75,15 +94,17 @@ export class MainGame extends Scene {
async gameOver(success) {
this.isOver = true;
await sleep(3);
}
onTriggerEnter(event: ITriggerEvent) {
console.log(event.type, event);
}
onPlayerCollision(event: ICollisionEvent) {
console.log(event)
if (this.isOver) return;
......@@ -156,18 +177,43 @@ export class MainGame extends Scene {
checkFrame = 0;
lastCreateZ: number = 0;
createRing: boolean = false;
createLight: boolean = false;
checkWall() {
this.checkFrame = 0;
const pPos = this.player.position;
const index = this.wallArr[0].position.z - Math.round(pPos.z);
const pz = Math.round(pPos.z);
const index = this.wallArr[0].position.z - pz;
// 因为z是负的,所以要上一次减这一次
const judgeZ = this.lastCreateZ - pz;
if (judgeZ >= 10) {
this.lastCreateZ = pz;
this.createLight = true;
} else if (judgeZ >= 10) {
this.lastCreateZ = pz;
this.createRing = true;
}
console.log(pz);
const createCount = index - 4;
for (let i = 0; i < createCount; i++) {
const wall = this.wallArr.shift();
wall.setPosition(0, Math.random(), this.wallArr[this.wallArr.length - 1].position.z - 1);
this.wallArr.push(wall);
}
if (this.createLight) {
this.createLight = false;
wall.getComponent(Wall).createLight();
} else if (this.createRing) {
this.createRing = false;
wall.getComponent(Wall).createRing();
}
}
}
update(dt: number) {
......
import { _decorator, Component, Node } from 'cc';
import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
const {ccclass, property} = _decorator;
......@@ -11,11 +11,16 @@ export class Wall extends Component {
@property isInit = false;
@property(Prefab) lightPrefab: Prefab = null;
@property(Prefab) ringPrefab: Prefab = null;
dH: number = 1;
start() {
if (!this.isInit) {
const dH = Math.random() * 2 + 2;
this.top.setPosition(0, dH / 2, 0);
this.bottom.setPosition(0, -dH / 2, 0);
this.dH = Math.random() * 2 + 2;
this.top.setPosition(0, this.dH / 2, 0);
this.bottom.setPosition(0, -this.dH / 2, 0);
}
}
......@@ -23,5 +28,14 @@ export class Wall extends Component {
return this.top.position.y + this.node.position.y;
}
createLight() {
const light = instantiate(this.lightPrefab);
this.node.addChild(light);
light.setScale(1, this.dH, 1);
}
createRing() {
}
}
......@@ -17,13 +17,18 @@
{
"index": 3,
"name": "Player"
},
{
"index": 4,
"name": "Prop"
}
],
"collisionMatrix": {
"0": 0,
"1": 0,
"2": 8,
"3": 4
"3": 20,
"4": 8
},
"maxSubSteps": 2,
"defaultMaterial": "ba21476f-2866-4f81-9c4d-6e359316e448"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment