【cocos2d-x 2.x 学习与应用总结】12: cocos2d-x预定义shader源码

【cocos2d-x 2.x 学习与应用总结】12: cocos2d-x预定义shader源码,第1张

概述前言 本文把cocos2d-x 2.x版本中预定义的所有shader源码贴出来,便于集中参考。作者的引擎版本是2.2.3. 下面以ccShaders.h中定义的片段着色器变量名作为标题,逐条列出。(为什么不用顶点着色器的变量名,因为有几个shader只有片段着色器变量名) ccPosition_uColor_frag ccShader_Position_uColor_vert.h attribut 前言

本文把cocos2d-x 2.x版本中预定义的所有shader源码贴出来,便于集中参考。作者的引擎版本是2.2.3.

下面以ccShaders.h中定义的片段着色器变量名作为标题,逐条列出。(为什么不用顶点着色器的变量名,因为有几个shader只有片段着色器变量名)

ccposition_ucolor_frag

ccShader_position_ucolor_vert.h

attribute vec4 a_position;                          uniform vec4 u_color;                               uniform float u_pointSize;                          #ifdef GL_ES varying lowp vec4 v_fragmentcolor;                  #else varying vec4 v_fragmentcolor;                       #endif voID main()                                         {                                                       gl_position = CC_MVPMatrix * a_position;            gl_PointSize = u_pointSize;                         v_fragmentcolor = u_color;                      }

ccShader_position_ucolor_frag.h

#ifdef GL_ES precision lowp float;                   #endif varying vec4 v_fragmentcolor;           voID main()                             {                                           gl_Fragcolor = v_fragmentcolor;     }
ccpositioncolor_frag

ccShader_positioncolor_vert.h

attribute vec4 a_position;                              attribute vec4 a_color;                                 #ifdef GL_ES varying lowp vec4 v_fragmentcolor;                      #else varying vec4 v_fragmentcolor;                           #endif voID main()                                             {                                                           gl_position = CC_MVPMatrix * a_position;                v_fragmentcolor = a_color;                          }

ccShader_positioncolor_frag.h

#ifdef GL_ES precision lowp float;                               #endif varying vec4 v_fragmentcolor;                       voID main()                                         {                                                       gl_Fragcolor = v_fragmentcolor;                 }
ccpositionTexture_frag

ccShader_positionTexture_vert.h

attribute vec4 a_position;                              attribute vec2 a_texCoord;                              #ifdef GL_ES varying mediump vec2 v_texCoord;                        #else varying vec2 v_texCoord;                                #endif voID main()                                             {                                                           gl_position = CC_MVPMatrix * a_position;                v_texCoord = a_texCoord;                            }

ccShader_positionTexture_frag.h

#ifdef GL_ES precision lowp float;                                                   #endif varying vec2 v_texCoord;                                                uniform sampler2D CC_Texture0;                                          voID main()                                                             {                                                                           gl_Fragcolor =  texture2D(CC_Texture0,v_texCoord);                 }
ccpositionTextureA8color_frag

ccShader_positionTextureA8color_vert.h

attribute vec4 a_position;                          attribute vec2 a_texCoord;                          attribute vec4 a_color;                             #ifdef GL_ES varying lowp vec4 v_fragmentcolor;                  varying mediump vec2 v_texCoord;                    #else varying vec4 v_fragmentcolor;                       varying vec2 v_texCoord;                            #endif voID main()                                         {                                                       gl_position = CC_MVPMatrix * a_position;            v_fragmentcolor = a_color;                          v_texCoord = a_texCoord;                        }

ccShader_positionTextureA8color_frag.h

#ifdef GL_ES precision lowp float;                               #endif varying vec4 v_fragmentcolor;                       varying vec2 v_texCoord;                            uniform sampler2D CC_Texture0;                      voID main()                                         {                                                       gl_Fragcolor = vec4( v_fragmentcolor.rgb,// RGB from uniform                          v_fragmentcolor.a * texture2D(CC_Texture0,v_texCoord).a   // A from texture & uniform                        );                           }
ccpositionTexturecolor_frag

ccShader_positionTexturecolor_vert.h

attribute vec4 a_position;                          attribute vec2 a_texCoord;                          attribute vec4 a_color;                             #ifdef GL_ES varying lowp vec4 v_fragmentcolor;                  varying mediump vec2 v_texCoord;                    #else varying vec4 v_fragmentcolor;                       varying vec2 v_texCoord;                            #endif voID main()                                         {                                                       gl_position = CC_MVPMatrix * a_position;            v_fragmentcolor = a_color;                          v_texCoord = a_texCoord;                        }

ccShader_positionTexturecolor_frag.h

#ifdef GL_ES precision lowp float;                       #endif varying vec4 v_fragmentcolor;               varying vec2 v_texCoord;                    uniform sampler2D CC_Texture0;              voID main()                                 {                                               gl_Fragcolor = v_fragmentcolor * texture2D(CC_Texture0,v_texCoord);}
ccpositionTexturecolorAlphaTest_frag

ccShader_positionTexturecolorAlphaTest_frag.h

#ifdef GL_ES precision lowp float;                                       #endif varying vec4 v_fragmentcolor;                               varying vec2 v_texCoord;                                    uniform sampler2D CC_Texture0;                              uniform float CC_Alpha_value;                               voID main()                                                 {                                                               vec4 texcolor = texture2D(CC_Texture0,v_texCoord);         // mimic: glAlphaFunc(GL_GREATER)     // pass if ( incoming_pixel >= CC_Alpha_value ) => fail if incoming_pixel < CC_Alpha_value    if ( texcolor.a <= CC_Alpha_value )                             discard;                                                gl_Fragcolor = texcolor * v_fragmentcolor;              }
ccpositionTexture_ucolor_frag

ccShader_positionTexture_ucolor_vert.h

attribute vec4 a_position;          attribute vec2 a_texCoord;          #ifdef GL_ES varying mediump vec2 v_texCoord;    #else varying vec2 v_texCoord;            #endif voID main()                         {                                       gl_position = CC_MVPMatrix * a_position;    v_texCoord = a_texCoord;        }

ccShader_positionTexture_ucolor_frag.h

#ifdef GL_ES precision lowp float;                   #endif uniform     vec4 u_color;               varying vec2 v_texCoord;                uniform sampler2D CC_Texture0;          voID main()                             {                                           gl_Fragcolor =  texture2D(CC_Texture0,v_texCoord) * u_color;}
ccExSwitchMask_frag

ccShaderEx_SwitchMask_frag.h

#ifdef GL_ES precision lowp float;                            #endif varying vec4        v_fragmentcolor;             varying vec2        v_texCoord;                  uniform sampler2D   u_texture;                   uniform sampler2D   u_mask;                      voID main()                                      {                                                    vec4 texcolor   = texture2D(u_texture,v_texCoord);                                          vec4 maskcolor  = texture2D(u_mask,v_texCoord);                                             vec4 finalcolor = vec4(texcolor.r,texcolor.g,texcolor.b,maskcolor.a * texcolor.a);        gl_Fragcolor    = v_fragmentcolor * finalcolor;                                          }
ccpositioncolorLengthTexture_frag

ccShader_positioncolorLengthTexture_vert.h

#ifdef GL_ES attribute mediump vec4 a_position;                                  attribute mediump vec2 a_texcoord;                                  attribute mediump vec4 a_color;                                     varying mediump vec4 v_color;                                       varying mediump vec2 v_texcoord;                                    #else attribute vec4 a_position;                                          attribute vec2 a_texcoord;                                          attribute vec4 a_color;                                             varying vec4 v_color;                                               varying vec2 v_texcoord;                                            #endif voID main()                                                         {                                                                       v_color = vec4(a_color.rgb * a_color.a,a_color.a);                 v_texcoord = a_texcoord;                                            gl_position = CC_MVPMatrix * a_position;                        }

ccShader_positioncolorLengthTexture_frag.h

#ifdef GL_ES // #extension GL_OES_standard_derivatives : enable varying mediump vec4 v_color;                                                                                               varying mediump vec2 v_texcoord;                                                                                            #else varying vec4 v_color;                                                                                                       varying vec2 v_texcoord;                                                                                                    #endif voID main()                                                                                                                 {                                                                                                                           // #if defined GL_OES_standard_derivatives     // gl_Fragcolor = v_color*smoothstep(0.0,length(fwIDth(v_texcoord)),1.0 - length(v_texcoord)); // #else     gl_Fragcolor = v_color*step(0.0,1.0 - length(v_texcoord));                                                             // #endif }

作者水平有限,对相关知识的理解和总结难免有错误,还望给予指正,非常感谢!

在这里也能看到这篇文章:github博客,CSDN博客,欢迎访问

总结

以上是内存溢出为你收集整理的【cocos2d-x 2.x 学习与应用总结】12: cocos2d-x预定义shader源码全部内容,希望文章能够帮你解决【cocos2d-x 2.x 学习与应用总结】12: cocos2d-x预定义shader源码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1076757.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存