212 lines
4.9 KiB
Plaintext
212 lines
4.9 KiB
Plaintext
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
CCEffect %{
|
|
techniques:
|
|
- name: opaque
|
|
passes:
|
|
- vert: unlit-vs:vert
|
|
frag: unlit-fs:frag
|
|
properties: &props
|
|
maskTexture: { value: black }
|
|
noiseTexture: { value: black }
|
|
mainTexture: { value: grey }
|
|
textureMoveSpeed: { value: [0, 0] }
|
|
tilingOffset: { value: [1, 1, 0, 0] }
|
|
maskTilingOffset: { value: [1, 1, 0, 0] }
|
|
noiseStrength: { value: [1, 1] }
|
|
noiseMoveSpeed: { value: [0, 0] }
|
|
mainColor: { value: [1, 1, 1, 1], 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, editor: { visible: false } } # backward compability
|
|
migrations: &migs
|
|
properties:
|
|
mainColor: { formerlySerializedAs: color }
|
|
- name: transparent
|
|
passes:
|
|
- vert: unlit-vs:vert
|
|
frag: unlit-fs:frag
|
|
depthStencilState: &d1
|
|
depthTest: true
|
|
depthWrite: false
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: src_alpha
|
|
blendDst: one_minus_src_alpha
|
|
blendDstAlpha: one_minus_src_alpha
|
|
properties: *props
|
|
migrations: *migs
|
|
- name: add
|
|
passes:
|
|
- vert: unlit-vs:vert
|
|
frag: unlit-fs:frag
|
|
rasterizerState: &r1 { cullMode: none }
|
|
depthStencilState: *d1
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: src_alpha
|
|
blendDst: one
|
|
blendSrcAlpha: src_alpha
|
|
blendDstAlpha: one
|
|
properties: *props
|
|
migrations: *migs
|
|
- name: alpha-blend
|
|
passes:
|
|
- vert: unlit-vs:vert
|
|
frag: unlit-fs:frag
|
|
rasterizerState: *r1
|
|
depthStencilState: *d1
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: src_alpha
|
|
blendDst: one_minus_src_alpha
|
|
blendSrcAlpha: src_alpha
|
|
blendDstAlpha: one_minus_src_alpha
|
|
properties: *props
|
|
migrations: *migs
|
|
}%
|
|
|
|
CCProgram unlit-vs %{
|
|
precision highp float;
|
|
#include <legacy/input>
|
|
#include <builtin/uniforms/cc-global>
|
|
#include <legacy/local-batch>
|
|
|
|
#if USE_VERTEX_COLOR
|
|
in vec4 a_color;
|
|
out vec4 v_color;
|
|
#endif
|
|
|
|
out vec2 v_uv;
|
|
#if USE_TEXTURE
|
|
uniform TexCoords {
|
|
vec4 tilingOffset;
|
|
};
|
|
#endif
|
|
|
|
#if USE_MASK_COLOR
|
|
out vec2 v_uvM;
|
|
uniform TexMCoords {
|
|
vec4 maskTilingOffset;
|
|
};
|
|
#endif
|
|
|
|
vec4 vert () {
|
|
vec4 position;
|
|
CCVertInput(position);
|
|
|
|
mat4 matWorld;
|
|
CCGetWorldMatrix(matWorld);
|
|
vec2 uv = a_texCoord;
|
|
|
|
#if USE_TEXTURE
|
|
#if FLIP_UV
|
|
uv.y = 1.0 - v_uv.y;
|
|
#endif
|
|
#endif
|
|
|
|
#if USE_VERTEX_COLOR
|
|
v_color = a_color;
|
|
#endif
|
|
|
|
v_uv = uv * tilingOffset.xy + tilingOffset.zw;
|
|
#if USE_MASK_COLOR
|
|
v_uvM = uv * maskTilingOffset.xy + maskTilingOffset.zw;
|
|
#endif
|
|
|
|
vec4 outPos = cc_matProj * (cc_matView * matWorld) * position;
|
|
return outPos;
|
|
}
|
|
}%
|
|
|
|
CCProgram unlit-fs %{
|
|
precision mediump float;
|
|
#include <legacy/output>
|
|
|
|
in vec2 v_uv;
|
|
#if USE_TEXTURE
|
|
uniform sampler2D mainTexture;
|
|
#endif
|
|
|
|
#if USE_TEXTURE_MOVE
|
|
uniform ConstTextureMove{
|
|
vec2 textureMoveSpeed;
|
|
};
|
|
#endif
|
|
|
|
#if USE_NOISE_TEXTURE
|
|
uniform sampler2D noiseTexture;
|
|
uniform ConstNoiseTexture{
|
|
vec2 noiseStrength;
|
|
};
|
|
#endif
|
|
|
|
#if USE_NOISE_MOVE
|
|
uniform ConstNoiseMove{
|
|
vec2 noiseMoveSpeed;
|
|
};
|
|
#endif
|
|
|
|
uniform Constant {
|
|
vec4 mainColor;
|
|
vec4 colorScaleAndCutoff;
|
|
};
|
|
|
|
#if USE_VERTEX_COLOR
|
|
in vec4 v_color;
|
|
#endif
|
|
|
|
#if USE_MASK_COLOR
|
|
in vec2 v_uvM;
|
|
uniform sampler2D maskTexture;
|
|
#endif
|
|
|
|
#if USE_ALPHA_TEST
|
|
#pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])
|
|
#endif
|
|
|
|
|
|
vec4 frag () {
|
|
vec4 o = mainColor;
|
|
o.rgb *= colorScaleAndCutoff.xyz;
|
|
|
|
#if USE_VERTEX_COLOR
|
|
o *= v_color;
|
|
#endif
|
|
|
|
vec2 uv = v_uv;
|
|
#if USE_TEXTURE
|
|
#if USE_TEXTURE_MOVE
|
|
uv.x = uv.x + fract(cc_time.x * textureMoveSpeed.x);
|
|
uv.y = uv.y + fract(cc_time.x * textureMoveSpeed.y);
|
|
#endif
|
|
|
|
#if USE_NOISE_TEXTURE
|
|
vec2 noise_uv = v_uv;
|
|
#if USE_NOISE_MOVE
|
|
vec2 speed = vec2(cc_time.x * noiseMoveSpeed.x ,cc_time.x * noiseMoveSpeed.y);
|
|
noise_uv.xy = v_uv.xy + fract(speed.xy);
|
|
#endif
|
|
|
|
vec4 offset = texture(noiseTexture,noise_uv);
|
|
uv.x = uv.x + (offset.x - 0.5) * noiseStrength.x;
|
|
uv.y = uv.y + (offset.y - 0.5) * noiseStrength.y;
|
|
#endif
|
|
o *= texture(mainTexture, uv);
|
|
#endif
|
|
|
|
#if USE_MASK_COLOR
|
|
vec2 uv1 = v_uvM;
|
|
o *= texture(maskTexture, uv1);
|
|
#endif
|
|
|
|
#if USE_ALPHA_TEST
|
|
if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
|
|
#endif
|
|
|
|
return CCFragOutput(o);
|
|
}
|
|
}%
|