2.4这样写
CCEffect %{
techniques:
- passes:
- vert: vs
frag: fs
rasterizerState:
cullMode: back
depthStencilState:
depthTest: true
depthWrite: true
properties:
tex: { value: white }
lod: { value: 1.0 }
}%
CCProgram vs %{
precision highp float;
#include <cc-global>
#include <cc-local>
in vec3 a_position;
#if USE_TEXTURE
in vec2 a_uv0;
out vec2 v_uv0;
#endif
void main () {
vec4 pos = vec4(a_position, 1.0);
pos = cc_matViewProj * cc_matWorld * pos;
#if USE_TEXTURE
v_uv0 = a_uv0;
#endif
gl_Position = pos;
}
}%
CCProgram fs %{
#extension GL_EXT_shader_texture_lod : enable
precision highp float;
#if USE_TEXTURE
in vec2 v_uv0;
uniform sampler2D tex;
uniform Lod {
float lod;
};
#endif
void main () {
vec4 o = vec4(1.0, 1.0, 1.0, 1.0);
#if USE_TEXTURE
#ifdef GL_EXT_shader_texture_lod
o = texture2DLodEXT(tex,v_uv0,lod);
#else
o = texture2D(tex,v_uv0);
#endif
#endif
gl_FragColor = o;
}
}%
3.0这样写
CCEffect %{
techniques:
- name: opaque
passes:
- vert: general-vs:vert # builtin header
frag: unlit-fs:frag
properties: &props
mainTexture: { value: white }
mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
roughness: { value: 1.0 }
- name: transparent
passes:
- vert: general-vs:vert # builtin header
frag: unlit-fs:frag
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendSrcAlpha: src_alpha
blendDstAlpha: one_minus_src_alpha
properties: *props
}%
CCProgram unlit-fs %{
#if __VERSION__ < 300
#extension GL_EXT_shader_texture_lod : enable
#endif
precision highp float;
#include <output>
#include <cc-fog>
in vec2 v_uv;
uniform sampler2D mainTexture;
in float factor_fog;
uniform Constant {
vec4 mainColor;
float roughness;
};
vec4 frag () {
#if __VERSION__ < 300
#ifdef GL_EXT_shader_texture_lod
vec4 color = texture2DLodEXT(mainTexture,v_uv, roughness);
#else
vec4 color = texture2D(mainTexture, v_uv);
#endif
#else
vec4 color = textureLod(mainTexture, v_uv, roughness);
#endif
vec4 col = mainColor * color;
col = CC_APPLY_FOG(col, factor_fog);
return CCFragOutput(col);
}
}%