[add] first

This commit is contained in:
2023-02-22 09:50:51 +08:00
commit 6260e95bc8
9053 changed files with 4492644 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
// Effect Syntax Guide: https://docs.cocos.com/creator/manual/zh/shader/index.html
CCEffect %{
techniques:
- name: opaque
passes:
- vert: ghost-vertext-vs:vert # builtin header
frag: ghost-vertext-fs:frag
properties: &props
mainTexture: { value: white }
mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
direction: { value: [0, 0, 0, 1] }
- name: transparent
passes:
- vert: ghost-vertext-vs:vert # builtin header
frag: ghost-vertext-fs:frag
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendSrcAlpha: src_alpha
blendDstAlpha: one_minus_src_alpha
properties: *props
}%
CCProgram ghost-vertext-vs %{
precision highp float;
#include <legacy/input-standard>
#include <cc-global>
#include <legacy/local-batch>
out vec2 v_uv;
out float factor;
uniform GhostVertexDirection {
vec4 direction;
};
vec4 vert () {
v_uv = a_texCoord;
StandardVertInput In;
CCVertInput(In);
mat4 matWorld;
mat4 matWorldIT;
CCGetWorldMatrixFull(matWorld, matWorldIT);
vec3 worldNormal = normalize((matWorld * vec4(In.normal, 0.0)).xyz);
vec4 worldPostion = matWorld * In.position;
factor = max(0.0, dot(worldNormal, direction.xyz));
float noise = fract(sin(dot(v_uv.xy, vec2(12.9898, 78.233))) * 43758.5453);
worldPostion.xyz += direction.xyz * direction.w * noise * factor;
return cc_matViewProj * worldPostion;
}
}%
CCProgram ghost-vertext-fs %{
precision highp float;
#include <output>
in vec2 v_uv;
in float factor;
uniform sampler2D mainTexture;
uniform Constant {
vec4 mainColor;
};
vec4 frag () {
vec4 col = texture(mainTexture, v_uv);
col += factor * mainColor;
return col;
}
}%

View File

@@ -0,0 +1,11 @@
{
"ver": "1.6.2",
"importer": "effect",
"imported": true,
"uuid": "59f1e7f2-81a4-4e4f-b9c8-85a5d09ecccb",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,40 @@
{
"__type__": "cc.Material",
"_name": "",
"_objFlags": 0,
"_native": "",
"_effectAsset": {
"__uuid__": "59f1e7f2-81a4-4e4f-b9c8-85a5d09ecccb",
"__expectedType__": "cc.EffectAsset"
},
"_techIdx": "0",
"_defines": [
{}
],
"_states": [
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
}
],
"_props": [
{
"mainTexture": {
"__uuid__": "2ac32bd6-6733-4b0e-bc07-f4442958d334@6c48a",
"__expectedType__": "cc.Texture2D"
},
"mainColor": {
"__type__": "cc.Color",
"r": 72,
"g": 176,
"b": 235,
"a": 255
}
}
]
}

View File

@@ -0,0 +1,11 @@
{
"ver": "1.0.19",
"importer": "material",
"imported": true,
"uuid": "9490800a-e8cd-4707-bc70-7af2a34e3a39",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,107 @@
import { _decorator, Component, Material, SkinnedMeshRenderer, Vec3, Vec4, v4, v3, clamp01, EventKeyboard, KeyCode, input, Input } from 'cc';
const { ccclass, executeInEditMode } = _decorator;
@ccclass('SolderController')
export class SolderController extends Component {
private materials: Array<Material> = [];
private directionUniform = v4();
private direction: Vec3 = v3();
private currentPosition = v3(0, 0, 0);
private lastPosition = v3(0, 0, 0);
private t = 0;
private xAxis = 0;
private zAxis = 0;
private speed = 10;
start () {
this.currentPosition = this.node.position.clone();
this.lastPosition = this.currentPosition.clone();
let components = this.node.getComponentsInChildren(SkinnedMeshRenderer);
components.forEach(
(comp) => {
this.materials.push(comp.material);
}
);
input.on(
Input.EventType.KEY_DOWN,
this.onKeyDown,
this
);
input.on(
Input.EventType.KEY_UP,
this.onKeyUp,
this
);
}
update (dt: number) {
this.currentPosition.x += this.speed * dt * this.xAxis;
this.currentPosition.z += this.speed * dt * this.zAxis;
this.node.setPosition(this.currentPosition);
if (this.currentPosition.equals(this.lastPosition)) {
this.t = 0;
}
this.t += dt;
this.t = clamp01(this.t);
Vec3.lerp(this.lastPosition, this.lastPosition, this.currentPosition, this.t);
Vec3.subtract(this.direction, this.lastPosition, this.currentPosition);
this.materials.forEach(
(material: Material) => {
let handle = material.passes[0].getHandle("direction")
material.passes[0].getUniform(handle, this.directionUniform);
this.directionUniform.set(
this.direction.x,
this.direction.y,
this.direction.z,
this.directionUniform.w,
);
material.passes[0].setUniform(handle, this.directionUniform);
}
);
}
private onKeyDown (event: EventKeyboard) {
let code = event.keyCode;
switch (code) {
case KeyCode.KEY_A:
this.xAxis = -1;
break;
case KeyCode.KEY_D:
this.xAxis = 1;
break;
case KeyCode.KEY_W:
this.zAxis = -1;
break;
case KeyCode.KEY_S:
this.zAxis = 1;
break;
}
}
private onKeyUp (event: EventKeyboard) {
let code = event.keyCode;
switch (code) {
case KeyCode.KEY_A:
this.xAxis = 0;
break;
case KeyCode.KEY_D:
this.xAxis = 0;
break;
case KeyCode.KEY_W:
this.zAxis = 0;
break;
case KeyCode.KEY_S:
this.zAxis = 0;
break;
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "91dce71d-2f17-4b5f-8536-c0e48dc28366",
"files": [],
"subMetas": {},
"userData": {}
}