123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
- CCEffect %{
- techniques:
- - passes:
- - vert: vs
- frag: fs
- blendState:
- targets:
- - blend: true
- rasterizerState:
- cullMode: none
- properties:
- texture: { value: white }
- alphaThreshold: { value: 0.5 }
- u_color: { value: [1,1,1,1], editor: {type: color} }
- u_rate: { value: 1 }
- }%
- CCProgram vs %{
- precision highp float;
- #include <cc-global>
- #include <cc-local>
- in vec3 a_position;
- in vec4 a_color;
- out vec4 v_light;
- #if USE_TINT
- in vec4 a_color0;
- out vec4 v_dark;
- #endif
- #if USE_TEXTURE
- in vec2 a_uv0;
- out vec2 v_uv0;
- #endif
- void main () {
- mat4 mvp;
-
- #if CC_USE_MODEL
- mvp = cc_matViewProj * cc_matWorld;
- #else
- mvp = cc_matViewProj;
- #endif
- #if USE_TEXTURE
- v_uv0 = a_uv0;
- #endif
- v_light = a_color;
- #if USE_TINT
- v_dark = a_color0;
- #endif
- gl_Position = mvp * vec4(a_position, 1);
- }
- }%
- CCProgram fs %{
- precision highp float;
-
- #include <alpha-test>
- #include <texture>
- in vec4 v_light;
- #if USE_TINT
- in vec4 v_dark;
- #endif
- #if USE_TEXTURE
- in vec2 v_uv0;
- uniform sampler2D texture;
- #endif
- uniform ARGS {
- vec4 u_color;
- float u_rate;
- };
- void main () {
- vec4 texColor = vec4(1.0);
- #if USE_TEXTURE
- CCTexture(texture, v_uv0, texColor);
- #endif
-
- vec4 finalColor;
- #if USE_TINT
- finalColor.a = v_light.a * texColor.a;
- finalColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
- #else
- finalColor = texColor * v_light;
- #endif
- ALPHA_TEST(finalColor);
- vec3 result = mix(u_color.rgb, finalColor.rgb, u_rate);
- gl_FragColor = vec4(result.rgb, finalColor.a);
- }
- }%
|