解决 Effect 不生效的问题,因为Effect文件名不能用数字开头,重命名后解决了这个问题
This commit is contained in:
parent
4514bcf8b9
commit
f0f47ca9c4
@ -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 <cc-global>
|
|
||||||
#include <cc-local>
|
|
||||||
|
|
||||||
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 <alpha-test>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}%
|
|
@ -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": {}
|
|
||||||
}
|
|
119
assets/effects/SpriteEffectExample.effect
Normal file
119
assets/effects/SpriteEffectExample.effect
Normal file
@ -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 <cc-global>
|
||||||
|
#include <cc-local>
|
||||||
|
|
||||||
|
// 顶点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 <alpha-test>
|
||||||
|
|
||||||
|
// 接收来自上方顶点 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}%
|
17
assets/effects/SpriteEffectExample.effect.meta
Normal file
17
assets/effects/SpriteEffectExample.effect.meta
Normal file
@ -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": {}
|
||||||
|
}
|
13
assets/materials/SpriteEffectExample.mtl
Normal file
13
assets/materials/SpriteEffectExample.mtl
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"__type__": "cc.Material",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"_native": "",
|
||||||
|
"_effectAsset": {
|
||||||
|
"__uuid__": "8f277982-dc0a-4030-90cc-b336a928a372"
|
||||||
|
},
|
||||||
|
"_defines": {
|
||||||
|
"USE_TEXTURE": true
|
||||||
|
},
|
||||||
|
"_props": {}
|
||||||
|
}
|
6
assets/materials/SpriteEffectExample.mtl.meta
Normal file
6
assets/materials/SpriteEffectExample.mtl.meta
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.0.2",
|
||||||
|
"uuid": "ca058f99-941b-40f2-b208-d776de59abed",
|
||||||
|
"dataAsSubAsset": null,
|
||||||
|
"subMetas": {}
|
||||||
|
}
|
@ -177,7 +177,7 @@
|
|||||||
"array": [
|
"array": [
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
554.2562584220408,
|
324.7595264191645,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -398,7 +398,7 @@
|
|||||||
"ctor": "Float64Array",
|
"ctor": "Float64Array",
|
||||||
"array": [
|
"array": [
|
||||||
0,
|
0,
|
||||||
50,
|
111.898,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -432,7 +432,7 @@
|
|||||||
"_enabled": true,
|
"_enabled": true,
|
||||||
"_materials": [
|
"_materials": [
|
||||||
{
|
{
|
||||||
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
|
"__uuid__": "ca058f99-941b-40f2-b208-d776de59abed"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_srcBlendFactor": 770,
|
"_srcBlendFactor": 770,
|
||||||
@ -492,7 +492,7 @@
|
|||||||
"ctor": "Float64Array",
|
"ctor": "Float64Array",
|
||||||
"array": [
|
"array": [
|
||||||
0,
|
0,
|
||||||
-180,
|
-117.787,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
@ -9,5 +9,35 @@
|
|||||||
"packageName": "org.cocos2d.helloworld",
|
"packageName": "org.cocos2d.helloworld",
|
||||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||||
"title": "hello_world",
|
"title": "hello_world",
|
||||||
"webOrientation": "auto"
|
"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
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"width": 960,
|
"width": 960,
|
||||||
"height": 640
|
"height": 640
|
||||||
},
|
},
|
||||||
"last-module-event-record-time": 0,
|
"last-module-event-record-time": 1575989336079,
|
||||||
"assets-sort-type": "name",
|
"assets-sort-type": "name",
|
||||||
"facebook": {
|
"facebook": {
|
||||||
"enable": false,
|
"enable": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user