mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-07 22:27:22 +08:00
完善置灰与还原shader
This commit is contained in:
@@ -62,14 +62,14 @@
|
||||
"__id__": 6
|
||||
},
|
||||
{
|
||||
"__id__": 9
|
||||
"__id__": 14
|
||||
}
|
||||
],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 15
|
||||
"__id__": 20
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -218,18 +218,77 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "cocos",
|
||||
"_name": "New Label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 7
|
||||
},
|
||||
{
|
||||
"__id__": 9
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
}
|
||||
],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 13
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "5ffGgeX61Lxou4QAjbfGSx",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 110,
|
||||
"height": 50
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": -15,
|
||||
"y": -146
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "cocos",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 7
|
||||
},
|
||||
{
|
||||
"__id__": 8
|
||||
}
|
||||
@@ -261,8 +320,8 @@
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 50
|
||||
"x": 15,
|
||||
"y": 196
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
@@ -276,7 +335,7 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
"__id__": 7
|
||||
},
|
||||
"_enabled": true,
|
||||
"_spriteFrame": {
|
||||
@@ -297,6 +356,156 @@
|
||||
"_dstBlendFactor": 771,
|
||||
"_atlas": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "New Label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 10
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "f94FJhf7VGXLQYnTdUpSgv",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 226,
|
||||
"g": 145,
|
||||
"b": 145,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 98,
|
||||
"height": 40
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 36
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 9
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
"_actualFontSize": 40,
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_N$string": "Label",
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "New Label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 12
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "b1aM/yecdDUbimGhq26C9w",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 37.5,
|
||||
"height": 50
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": -24
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 11
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
"_actualFontSize": 40,
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": {
|
||||
"__uuid__": "5896532f-0687-4bdc-b272-17ec1d896f52"
|
||||
},
|
||||
"_isSystemFontUsed": false,
|
||||
"_spacingX": 0,
|
||||
"_N$string": "2",
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0
|
||||
},
|
||||
{
|
||||
"__type__": "5f0d9rVh/9LgZTLV8+W+bku",
|
||||
"_name": "",
|
||||
@@ -305,7 +514,7 @@
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"isAllChildrenUse": false,
|
||||
"isAllChildrenUse": true,
|
||||
"isGray": false
|
||||
},
|
||||
{
|
||||
@@ -317,17 +526,17 @@
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 10
|
||||
"__id__": 15
|
||||
}
|
||||
],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 12
|
||||
"__id__": 17
|
||||
},
|
||||
{
|
||||
"__id__": 13
|
||||
"__id__": 18
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -372,14 +581,14 @@
|
||||
"_name": "Label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 9
|
||||
"__id__": 14
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 11
|
||||
"__id__": 16
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -424,7 +633,7 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 10
|
||||
"__id__": 15
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
@@ -446,7 +655,7 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 9
|
||||
"__id__": 14
|
||||
},
|
||||
"_enabled": true,
|
||||
"_spriteFrame": {
|
||||
@@ -472,7 +681,7 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 9
|
||||
"__id__": 14
|
||||
},
|
||||
"_enabled": true,
|
||||
"transition": 2,
|
||||
@@ -494,7 +703,7 @@
|
||||
"zoomScale": 1.2,
|
||||
"clickEvents": [
|
||||
{
|
||||
"__id__": 14
|
||||
"__id__": 19
|
||||
}
|
||||
],
|
||||
"_N$interactable": true,
|
||||
@@ -532,7 +741,7 @@
|
||||
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
|
||||
},
|
||||
"_N$target": {
|
||||
"__id__": 9
|
||||
"__id__": 14
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -26,7 +26,22 @@ const gray_frag = `
|
||||
}
|
||||
`;
|
||||
|
||||
const normal_frag = `
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
varying vec4 v_fragmentColor;
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = texture2D(CC_Texture0, v_texCoord);
|
||||
}
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
default_vert,
|
||||
gray_frag
|
||||
gray_frag,
|
||||
normal_frag
|
||||
};
|
||||
@@ -35,11 +35,34 @@ cc.Class({
|
||||
|
||||
},
|
||||
|
||||
//正常shader
|
||||
normalShader(){
|
||||
let program = new cc.GLProgram();
|
||||
if (cc.sys.isNative) {
|
||||
program.initWithString(Gray.default_vert, Gray.normal_frag);
|
||||
program.link();
|
||||
program.updateUniforms();
|
||||
} else {
|
||||
program.initWithVertexShaderByteArray(Gray.default_vert, Gray.normal_frag);
|
||||
program.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
|
||||
program.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
|
||||
program.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
|
||||
program.link();
|
||||
program.updateUniforms();
|
||||
}
|
||||
if (this.isAllChildrenUse) {
|
||||
this.setProgram(this.node._sgNode, program);
|
||||
} else {
|
||||
this.setProgram(this.node.getComponent(cc.Sprite)._sgNode, program);
|
||||
}
|
||||
},
|
||||
|
||||
setProgram(node, program) {
|
||||
if (cc.sys.isNative) {
|
||||
var glProgram_state = cc.GLProgramState.getOrCreateWithGLProgram(program);
|
||||
node.setGLProgramState(glProgram_state);
|
||||
} else {
|
||||
node.normalProgram=node.getShaderProgram();
|
||||
node.setShaderProgram(program);
|
||||
}
|
||||
|
||||
@@ -52,24 +75,9 @@ cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
// 恢复默认shader
|
||||
resetProgram(node) {
|
||||
node.getComponent(cc.Sprite)._sgNode.setState(0);
|
||||
var children = node.children;
|
||||
if (!children)
|
||||
return;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
this.resetProgram(children[i]);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
//恢复默认shader
|
||||
resetShader() {
|
||||
if (this.isAllChildrenUse) {
|
||||
this.resetProgram(this.node);
|
||||
} else {
|
||||
this.node.getComponent(cc.Sprite)._sgNode.setState(0);
|
||||
}
|
||||
this.normalShader(this.node);
|
||||
},
|
||||
|
||||
onEventClicked_setEffect() {
|
||||
|
||||
25
GrayShaderDemo_1.9/assets/Texture/pengold.fnt
Normal file
25
GrayShaderDemo_1.9/assets/Texture/pengold.fnt
Normal file
@@ -0,0 +1,25 @@
|
||||
info face="" size=32 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1
|
||||
common lineHeight=60 base=26 scaleW=128 scaleH=256 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
|
||||
page id=0 file="pengold.png"
|
||||
chars count=19
|
||||
char id=48 x=39 y=50 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="0"
|
||||
char id=49 x=70 y=50 width=22 height=49 xoffset=0 yoffset=11 xadvance=25 page=0 chnl=0 letter="1"
|
||||
char id=50 x=70 y=0 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="2"
|
||||
char id=51 x=64 y=100 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="3"
|
||||
char id=52 x=0 y=120 width=32 height=49 xoffset=0 yoffset=11 xadvance=35 page=0 chnl=0 letter="4"
|
||||
char id=53 x=33 y=120 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="5"
|
||||
char id=54 x=31 y=170 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="6"
|
||||
char id=55 x=62 y=170 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="7"
|
||||
char id=56 x=0 y=170 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="8"
|
||||
char id=57 x=39 y=0 width=30 height=49 xoffset=0 yoffset=11 xadvance=33 page=0 chnl=0 letter="9"
|
||||
char id=43 x=0 y=80 width=35 height=39 xoffset=0 yoffset=15 xadvance=38 page=0 chnl=0 letter="+"
|
||||
char id=45 x=27 y=220 width=21 height=16 xoffset=0 yoffset=27 xadvance=24 page=0 chnl=0 letter="-"
|
||||
char id=44 x=49 y=220 width=15 height=28 xoffset=0 yoffset=43 xadvance=18 page=0 chnl=0 letter=","
|
||||
char id=46 x=27 y=237 width=15 height=17 xoffset=0 yoffset=43 xadvance=18 page=0 chnl=0 letter="."
|
||||
char id=65509 x=0 y=220 width=26 height=35 xoffset=0 yoffset=23 xadvance=29 page=0 chnl=0 letter="¥"
|
||||
char id=20803 x=0 y=40 width=38 height=39 xoffset=0 yoffset=20 xadvance=41 page=0 chnl=0 letter="元"
|
||||
char id=19975 x=0 y=0 width=38 height=39 xoffset=0 yoffset=20 xadvance=41 page=0 chnl=0 letter="万"
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=0 letter=" "
|
||||
char id=9 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=160 page=0 chnl=0 letter=" "
|
||||
|
||||
kernings count=0
|
||||
7
GrayShaderDemo_1.9/assets/Texture/pengold.fnt.meta
Normal file
7
GrayShaderDemo_1.9/assets/Texture/pengold.fnt.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "2.1.0",
|
||||
"uuid": "5896532f-0687-4bdc-b272-17ec1d896f52",
|
||||
"textureUuid": "407e3c4d-0bba-4b8e-8ecf-0ef4d9473389",
|
||||
"fontSize": 32,
|
||||
"subMetas": {}
|
||||
}
|
||||
BIN
GrayShaderDemo_1.9/assets/Texture/pengold.png
Normal file
BIN
GrayShaderDemo_1.9/assets/Texture/pengold.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
30
GrayShaderDemo_1.9/assets/Texture/pengold.png.meta
Normal file
30
GrayShaderDemo_1.9/assets/Texture/pengold.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "407e3c4d-0bba-4b8e-8ecf-0ef4d9473389",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"pengold": {
|
||||
"ver": "1.0.3",
|
||||
"uuid": "cfe73646-e746-4a74-817c-d73e140b65f8",
|
||||
"rawTextureUuid": "407e3c4d-0bba-4b8e-8ecf-0ef4d9473389",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": -14,
|
||||
"offsetY": 0.5,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 100,
|
||||
"height": 255,
|
||||
"rawWidth": 128,
|
||||
"rawHeight": 256,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user