From f0f47ca9c439bf432a0d29b1c542ee7a13cef8b4 Mon Sep 17 00:00:00 2001 From: caizhitao Date: Wed, 11 Dec 2019 15:31:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20Effect=20=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=9B=A0?= =?UTF-8?q?=E4=B8=BAEffect=E6=96=87=E4=BB=B6=E5=90=8D=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E7=94=A8=E6=95=B0=E5=AD=97=E5=BC=80=E5=A4=B4=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E5=90=8E=E8=A7=A3=E5=86=B3=E4=BA=86=E8=BF=99?= =?UTF-8?q?=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/effects/2d-sprite-demo.effect | 82 ------------ assets/effects/2d-sprite-demo.effect.meta | 17 --- assets/effects/SpriteEffectExample.effect | 119 ++++++++++++++++++ .../effects/SpriteEffectExample.effect.meta | 17 +++ assets/materials/SpriteEffectExample.mtl | 13 ++ assets/materials/SpriteEffectExample.mtl.meta | 6 + assets/scenes/MainScene.fire | 8 +- settings/builder.json | 34 ++++- settings/project.json | 2 +- 9 files changed, 192 insertions(+), 106 deletions(-) delete mode 100644 assets/effects/2d-sprite-demo.effect delete mode 100644 assets/effects/2d-sprite-demo.effect.meta create mode 100644 assets/effects/SpriteEffectExample.effect create mode 100644 assets/effects/SpriteEffectExample.effect.meta create mode 100644 assets/materials/SpriteEffectExample.mtl create mode 100644 assets/materials/SpriteEffectExample.mtl.meta diff --git a/assets/effects/2d-sprite-demo.effect b/assets/effects/2d-sprite-demo.effect deleted file mode 100644 index 12e455a..0000000 --- a/assets/effects/2d-sprite-demo.effect +++ /dev/null @@ -1,82 +0,0 @@ -// 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/2d-sprite-demo.effect.meta b/assets/effects/2d-sprite-demo.effect.meta deleted file mode 100644 index 6ee2dcc..0000000 --- a/assets/effects/2d-sprite-demo.effect.meta +++ /dev/null @@ -1,17 +0,0 @@ -{ - "ver": "1.0.23", - "uuid": "dcc7ac41-c3ef-4558-bcef-3ff44a72eafe", - "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/effects/SpriteEffectExample.effect b/assets/effects/SpriteEffectExample.effect new file mode 100644 index 0000000..9adf791 --- /dev/null +++ b/assets/effects/SpriteEffectExample.effect @@ -0,0 +1,119 @@ +// 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 } +}% + +// 顶点 Shader 片段 +CCProgram vs %{ + // 定义 float 类型的精度为高精度 + precision highp float; + + // CC 所有内置的 Shader 变量都必须要要通过 #include 引入该变量的头文件 + // 所有头文件都在 chunks 目录下 + // Mac: /Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/renderer/build/chunks + // 也可以通过 相对项目assets的相对路径 或者 绝对路径 引用头文件资源 + #include + #include + + // 顶点Shader 从渲染管道里面获取哪些数据 + // in 用在函数的参数中,表示这个参数是输入的,在函数中改变这个值,并不会影响对调用的函数产生副作用。(相当于C语言的传值),这个是函数参数默认的修饰符 + + // 顶点坐标 + in vec3 a_position; + + // 顶点颜色 + in vec4 a_color; + + // out 用在函数的参数中,表示该参数是输出参数,值是会改变的 + + // 顶点 Shader 片段最后会输出的颜色值 + // 在片元 Shader 片段中可以接收到这个参数名的值 + out vec4 v_color; + + // 定义了一个宏,如果使用了纹理那么执行这之间的代码 + #if USE_TEXTURE + + // 输入的纹理坐标 + in vec2 a_uv0; + + // 输出的纹理坐标 + // 在片元 Shader 片段中可以接收到这个参数名的值 + 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; + + // 这里引入了内置的chunks目录下的 alpha-test 头文件 + #include + + // 接收来自上方顶点 Shader 片段的输出参数 v_color + // 顶点的颜色 + in vec4 v_color; + + #if USE_TEXTURE + + // 接收来自上方顶点 Shader 片段的输出参数 v_uv0 + // 顶点的坐标 + in vec2 v_uv0; + + // uniform :一致变量。在着色器执行期间一致变量的值是不变的 + // 与const常量不同的是,这个值在编译时期是未知的是由着色器外部初始化的 + // 一致变量在顶点着色器和片段着色器之间是共享的。它也只能在全局范围进行声明。 + 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 头文件 + // 意思大概为,如果传入的参数vec4 类型的参数o的透明通道值小于传入来的 alphaThreshold 值时,会discard + // 使用discard会退出片段着色器,不执行后面的片段着色操作。片段也不会写入帧缓冲区。 + ALPHA_TEST(o); + + // gl_FragColor = o; + gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); + + } +}% diff --git a/assets/effects/SpriteEffectExample.effect.meta b/assets/effects/SpriteEffectExample.effect.meta new file mode 100644 index 0000000..9658fcf --- /dev/null +++ b/assets/effects/SpriteEffectExample.effect.meta @@ -0,0 +1,17 @@ +{ + "ver": "1.0.23", + "uuid": "8f277982-dc0a-4030-90cc-b336a928a372", + "compiledShaders": [ + { + "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" + }, + "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" + } + } + ], + "subMetas": {} +} \ No newline at end of file diff --git a/assets/materials/SpriteEffectExample.mtl b/assets/materials/SpriteEffectExample.mtl new file mode 100644 index 0000000..e004343 --- /dev/null +++ b/assets/materials/SpriteEffectExample.mtl @@ -0,0 +1,13 @@ +{ + "__type__": "cc.Material", + "_name": "", + "_objFlags": 0, + "_native": "", + "_effectAsset": { + "__uuid__": "8f277982-dc0a-4030-90cc-b336a928a372" + }, + "_defines": { + "USE_TEXTURE": true + }, + "_props": {} +} \ No newline at end of file diff --git a/assets/materials/SpriteEffectExample.mtl.meta b/assets/materials/SpriteEffectExample.mtl.meta new file mode 100644 index 0000000..c9f9fa5 --- /dev/null +++ b/assets/materials/SpriteEffectExample.mtl.meta @@ -0,0 +1,6 @@ +{ + "ver": "1.0.2", + "uuid": "ca058f99-941b-40f2-b208-d776de59abed", + "dataAsSubAsset": null, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/scenes/MainScene.fire b/assets/scenes/MainScene.fire index 87e9f4c..a0cc5e8 100755 --- a/assets/scenes/MainScene.fire +++ b/assets/scenes/MainScene.fire @@ -177,7 +177,7 @@ "array": [ 0, 0, - 554.2562584220408, + 324.7595264191645, 0, 0, 0, @@ -398,7 +398,7 @@ "ctor": "Float64Array", "array": [ 0, - 50, + 111.898, 0, 0, 0, @@ -432,7 +432,7 @@ "_enabled": true, "_materials": [ { - "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + "__uuid__": "ca058f99-941b-40f2-b208-d776de59abed" } ], "_srcBlendFactor": 770, @@ -492,7 +492,7 @@ "ctor": "Float64Array", "array": [ 0, - -180, + -117.787, 0, 0, 0, diff --git a/settings/builder.json b/settings/builder.json index 09f915c..a5436aa 100755 --- a/settings/builder.json +++ b/settings/builder.json @@ -9,5 +9,35 @@ "packageName": "org.cocos2d.helloworld", "startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49", "title": "hello_world", - "webOrientation": "auto" -} \ No newline at end of file + "webOrientation": "auto", + "includeSDKBox": false, + "inlineSpriteFrames": true, + "inlineSpriteFrames_native": true, + "mergeStartScene": false, + "optimizeHotUpdate": false, + "md5Cache": false, + "encryptJs": true, + "xxteaKey": "35d36f0a-c885-4d", + "zipCompressJs": true, + "fb-instant-games": {}, + "android": { + "packageName": "org.cocos2d.helloworld" + }, + "ios": { + "packageName": "org.cocos2d.helloworld" + }, + "mac": { + "packageName": "org.cocos2d.helloworld" + }, + "win32": {}, + "android-instant": { + "REMOTE_SERVER_ROOT": "", + "host": "", + "packageName": "org.cocos2d.helloworld", + "pathPattern": "", + "recordPath": "", + "scheme": "https", + "skipRecord": false + }, + "appBundle": false +} diff --git a/settings/project.json b/settings/project.json index 79babe1..65a0f90 100755 --- a/settings/project.json +++ b/settings/project.json @@ -20,7 +20,7 @@ "width": 960, "height": 640 }, - "last-module-event-record-time": 0, + "last-module-event-record-time": 1575989336079, "assets-sort-type": "name", "facebook": { "enable": false,