From 9a7e3858cc5a8d069b139fa926408376a6efedd7 Mon Sep 17 00:00:00 2001 From: caizhitao Date: Wed, 11 Dec 2019 22:39:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ctExample.effect => sprite-example.effect} | 21 ++++- ...effect.meta => sprite-example.effect.meta} | 4 +- assets/effects/sprite-outline.effect | 82 +++++++++++++++++++ assets/effects/sprite-outline.effect.meta | 17 ++++ ...teEffectExample.mtl => sprite-example.mtl} | 0 ...ample.mtl.meta => sprite-example.mtl.meta} | 0 assets/materials/sprite-outline.mtl | 13 +++ assets/materials/sprite-outline.mtl.meta | 6 ++ 8 files changed, 137 insertions(+), 6 deletions(-) rename assets/effects/{SpriteEffectExample.effect => sprite-example.effect} (78%) rename assets/effects/{SpriteEffectExample.effect.meta => sprite-example.effect.meta} (96%) create mode 100644 assets/effects/sprite-outline.effect create mode 100644 assets/effects/sprite-outline.effect.meta rename assets/materials/{SpriteEffectExample.mtl => sprite-example.mtl} (100%) rename assets/materials/{SpriteEffectExample.mtl.meta => sprite-example.mtl.meta} (100%) create mode 100644 assets/materials/sprite-outline.mtl create mode 100644 assets/materials/sprite-outline.mtl.meta diff --git a/assets/effects/SpriteEffectExample.effect b/assets/effects/sprite-example.effect similarity index 78% rename from assets/effects/SpriteEffectExample.effect rename to assets/effects/sprite-example.effect index 9adf791..ef7a75a 100644 --- a/assets/effects/SpriteEffectExample.effect +++ b/assets/effects/sprite-example.effect @@ -1,15 +1,30 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +// YAML 格式的 CC Effect +// 此部分为声明流程控制清单 CCEffect %{ + # techniques 是一个数组 techniques: + # passes 是 techniques 数组的第0项 + # 同时 passes 也是一个数组,存放渲染管道描述的数组集合 - passes: - - vert: vs + + # passes 数组的第0项,完整的渲染流水线 + # vert 属性是指定顶点 Shader 片段的名字,如:这里的顶点 Shader 片段的名字为 vs + # 根据文档介绍还可以这样子指定片段的入口函数 vs:vert ,那么就代替main函数,vert才是入口函数 + - vert: vs + # frag 属性是指定片元 Shader 片段的名字,如:这里的片元 Shader 片段的名字为 fs + # 根据文档介绍还可以这样子指定片段的入口函数 fs:frag ,那么就代替main函数,frag才是入口函数 frag: fs + + # 混合模式开启 blendState: targets: - blend: true rasterizerState: cullMode: none + + # properties 列出可以在 Inspector 编辑器编辑的属性 properties: texture: { value: white } alphaThreshold: { value: 0.5 } @@ -112,8 +127,6 @@ CCProgram fs %{ // 使用discard会退出片段着色器,不执行后面的片段着色操作。片段也不会写入帧缓冲区。 ALPHA_TEST(o); - // gl_FragColor = o; - gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); - + gl_FragColor = o; } }% diff --git a/assets/effects/SpriteEffectExample.effect.meta b/assets/effects/sprite-example.effect.meta similarity index 96% rename from assets/effects/SpriteEffectExample.effect.meta rename to assets/effects/sprite-example.effect.meta index 9658fcf..a8d2556 100644 --- a/assets/effects/SpriteEffectExample.effect.meta +++ b/assets/effects/sprite-example.effect.meta @@ -5,11 +5,11 @@ { "glsl1": { "vert": "\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n\nattribute vec3 a_position;\n\nattribute vec4 a_color;\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\n\nattribute vec2 a_uv0;\n\nvarying vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n", - "frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\n\nvarying vec2 v_uv0;\n\nuniform sampler2D texture;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n\n}\n" + "frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\n\nvarying vec2 v_uv0;\n\nuniform sampler2D texture;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n}\n" }, "glsl3": { "vert": "\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n\n vec4 cc_screenSize;\n\n vec4 cc_screenScale;\n\n vec4 cc_nativeSize;\n\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n\n vec4 cc_exposure;\n\n vec4 cc_mainLitDir;\n\n vec4 cc_mainLitColor;\n\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n\nin vec3 a_position;\n\nin vec4 a_color;\n\nout vec4 v_color;\n\n#if USE_TEXTURE\n\nin vec2 a_uv0;\n\nout vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n", - "frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\n\nin vec2 v_uv0;\n\nuniform sampler2D texture;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n\n}\n" + "frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\n\nin vec2 v_uv0;\n\nuniform sampler2D texture;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n}\n" } } ], diff --git a/assets/effects/sprite-outline.effect b/assets/effects/sprite-outline.effect new file mode 100644 index 0000000..12e455a --- /dev/null +++ b/assets/effects/sprite-outline.effect @@ -0,0 +1,82 @@ +// 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 } +}% + + +CCProgram vs %{ + precision highp float; + + #include + #include + + in vec3 a_position; + in vec4 a_color; + out vec4 v_color; + + #if USE_TEXTURE + in vec2 a_uv0; + out vec2 v_uv0; + #endif + + void main () { + vec4 pos = vec4(a_position, 1); + + #if CC_USE_MODEL + pos = cc_matViewProj * cc_matWorld * pos; + #else + pos = cc_matViewProj * pos; + #endif + + #if USE_TEXTURE + v_uv0 = a_uv0; + #endif + + v_color = a_color; + + gl_Position = pos; + } +}% + + +CCProgram fs %{ + precision highp float; + + #include + + in vec4 v_color; + + #if USE_TEXTURE + in vec2 v_uv0; + uniform sampler2D texture; + #endif + + void main () { + vec4 o = vec4(1, 1, 1, 1); + + #if USE_TEXTURE + o *= texture(texture, v_uv0); + #if CC_USE_ALPHA_ATLAS_TEXTURE + o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r; + #endif + #endif + + o *= v_color; + + ALPHA_TEST(o); + + gl_FragColor = o; + } +}% diff --git a/assets/effects/sprite-outline.effect.meta b/assets/effects/sprite-outline.effect.meta new file mode 100644 index 0000000..de3674d --- /dev/null +++ b/assets/effects/sprite-outline.effect.meta @@ -0,0 +1,17 @@ +{ + "ver": "1.0.23", + "uuid": "559dcd1e-233b-4e1f-b1da-733c9232f06f", + "compiledShaders": [ + { + "glsl1": { + "vert": "\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nattribute vec2 a_uv0;\nvarying vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n", + "frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n}\n" + }, + "glsl3": { + "vert": "\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n\n vec4 cc_screenSize;\n\n vec4 cc_screenScale;\n\n vec4 cc_nativeSize;\n\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n\n vec4 cc_exposure;\n\n vec4 cc_mainLitDir;\n\n vec4 cc_mainLitColor;\n\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n\nin vec3 a_position;\nin vec4 a_color;\nout vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 a_uv0;\nout vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n", + "frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n}\n" + } + } + ], + "subMetas": {} +} \ No newline at end of file diff --git a/assets/materials/SpriteEffectExample.mtl b/assets/materials/sprite-example.mtl similarity index 100% rename from assets/materials/SpriteEffectExample.mtl rename to assets/materials/sprite-example.mtl diff --git a/assets/materials/SpriteEffectExample.mtl.meta b/assets/materials/sprite-example.mtl.meta similarity index 100% rename from assets/materials/SpriteEffectExample.mtl.meta rename to assets/materials/sprite-example.mtl.meta diff --git a/assets/materials/sprite-outline.mtl b/assets/materials/sprite-outline.mtl new file mode 100644 index 0000000..b0389b9 --- /dev/null +++ b/assets/materials/sprite-outline.mtl @@ -0,0 +1,13 @@ +{ + "__type__": "cc.Material", + "_name": "", + "_objFlags": 0, + "_native": "", + "_effectAsset": { + "__uuid__": "559dcd1e-233b-4e1f-b1da-733c9232f06f" + }, + "_defines": { + "USE_TEXTURE": true + }, + "_props": {} +} \ No newline at end of file diff --git a/assets/materials/sprite-outline.mtl.meta b/assets/materials/sprite-outline.mtl.meta new file mode 100644 index 0000000..9ce3939 --- /dev/null +++ b/assets/materials/sprite-outline.mtl.meta @@ -0,0 +1,6 @@ +{ + "ver": "1.0.2", + "uuid": "daf44951-2c80-4778-b99f-52cfc78ab053", + "dataAsSubAsset": null, + "subMetas": {} +} \ No newline at end of file