mirror of
https://gitee.com/ruanwujing/green-pack-cocos
synced 2025-10-09 16:46:17 +00:00
2渲3台球
This commit is contained in:
127
assets/resources/effects/billiards.effect
Normal file
127
assets/resources/effects/billiards.effect
Normal file
@@ -0,0 +1,127 @@
|
||||
// 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:
|
||||
b_matrix: { value:[
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 0]}
|
||||
light_pos: {value: [0.5, -0.5, 1, 1]}
|
||||
}%
|
||||
|
||||
CCProgram sprite-vs %{
|
||||
precision highp float;
|
||||
#include <builtin/uniforms/cc-global>
|
||||
#if USE_LOCAL
|
||||
#include <builtin/uniforms/cc-local>
|
||||
#endif
|
||||
#if SAMPLE_FROM_RT
|
||||
#include <common/common-define>
|
||||
#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 <builtin/internal/embedded-alpha>
|
||||
in vec4 color;
|
||||
in vec2 uv0;
|
||||
|
||||
uniform Constant {
|
||||
mat4x4 b_matrix;
|
||||
vec4 light_pos;
|
||||
};
|
||||
#pragma builtin(local)
|
||||
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
|
||||
|
||||
|
||||
vec4 frag () {
|
||||
vec2 uv = fract(uv0 * 4.0);
|
||||
vec2 id = floor(uv0 * 4.0);
|
||||
|
||||
vec2 xy = uv * 2.0 - 1.0;
|
||||
|
||||
float z = sqrt(1.0 - length(xy));
|
||||
|
||||
vec3 _p3d = vec3(xy, z);
|
||||
|
||||
vec4 p = b_matrix * vec4(_p3d, 1.0);
|
||||
vec3 p3d = p.xyz;
|
||||
|
||||
vec4 background = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 ballColor = color;
|
||||
#if USE_BELT
|
||||
// 上下两个白圈的中心店
|
||||
vec3 white1 = vec3(0.0, 1.0, 0.0);
|
||||
vec3 white2 = vec3(0.0, -1.0, 0.0);
|
||||
float whiteLen = 0.7;
|
||||
|
||||
vec3 dw1 = white1 - p3d;
|
||||
vec3 dw2 = white2 - p3d;
|
||||
float dw = min(dot(dw1, dw1), dot(dw2, dw2));
|
||||
ballColor = mix(ballColor, vec4(1.0, 1.0, 1.0, 1.0), smoothstep(0.0, -0.1, dw - whiteLen));
|
||||
#endif
|
||||
vec2 _xy = p3d.xy * 0.8 + 0.5;
|
||||
vec2 _uv = _xy * 0.25 + id * 0.25;
|
||||
vec4 numColor = CCSampleWithAlphaSeparated(cc_spriteTexture, _uv);
|
||||
|
||||
vec4 o = mix(ballColor, numColor, smoothstep(0., -0.1, length(_xy - 0.5) - 0.48) * step(0.0, p3d.z));
|
||||
o = mix(background, o, smoothstep(0.0, -0.1, length(xy) - 1.0));
|
||||
|
||||
#if USE_LIGHT
|
||||
vec3 lightDir = normalize(light_pos.xyz - _p3d.xyz);
|
||||
float d = dot(normalize(_p3d.xyz), lightDir);
|
||||
d = clamp(d, 0.0, 1.0);
|
||||
d = sqrt(d);
|
||||
float nol = 0.5 + 0.5 * d;
|
||||
o *= vec4(nol, nol, nol, 1.0);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
}%
|
11
assets/resources/effects/billiards.effect.meta
Normal file
11
assets/resources/effects/billiards.effect.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.7.1",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "852de7ce-1d24-4b8b-bfb1-b3e424877097",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -98,8 +98,13 @@ CCProgram sprite-fs %{
|
||||
vec2 uv_center = (id + 0.5) / vec2(columns, rows);
|
||||
|
||||
float exp = sizeExpand + 1.0;
|
||||
vec2 uv = (uv0 - uv_center) * vec2(columns, rows) * exp;
|
||||
o *= CCSampleWithAlphaSeparated(cc_spriteTexture, (uv0 - uv_center) * exp + uv_center);
|
||||
|
||||
vec2 uv = (uv0 - uv_center) * vec2(columns, rows) * exp;
|
||||
float dy = sin(uv0.y * 95.0) * 0.05;
|
||||
uv.x += dy;
|
||||
// float dx = sin(uv0.x * 95.0) * 0.05;
|
||||
// uv.y += dx;
|
||||
float d = sdBox(uv, vec2(0.5, 0.5));
|
||||
|
||||
float rad = radius;
|
||||
|
Reference in New Issue
Block a user