是不是让你在properites里声明一下customUniform和param
弄明白了
你需要这样写:
uniform FragConstants {
float customUniform;
vec2 param;
};
声明了
还是一样
// Copyright © 2017-2018 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- vert: vs
frag: fs
blendState:
targets:- blend: true
rasterizerState:
cullMode: none
properties:
uSampler: {}
customUniform: { value: 0.5 }
projectionVector: {}
param : {}
}%
- blend: true
- vert: vs
CCProgram vs %{
precision lowp float;
#include
#include
in vec2 a_position;
in vec2 aTextureCoord;
in vec2 a_color;
uniform FragConstants {
vec2 projectionVector;
vec2 center = vec2(-1.0, 1.0);
}
out vec2 vTextureCoord;
out vec4 v_color;
void main(void) {
gl_Position = vec4( (a_position / projectionVector) + center , 0.0, 1.0);
vTextureCoord = aTextureCoord;
v_color = vec4(a_color.x, a_color.x, a_color.x, a_color.x);
}
}%
CCProgram fs %{
precision lowp float;
out vec2 vTextureCoord;
out vec4 v_color;
uniform FragConstants {
sampler2D uSampler;
float customUniform;
vec2 param;
};
void main(void) {
vec2 uvs = vTextureCoord.xy;
uvs.x = mod(uvs.x - param.y + customUniform * param.x, param.x) + param.y;
vec4 fg = texture2D(uSampler, uvs);
gl_FragColor = fg * v_color;
}
}%
error EFX2209: missing semicolon after UBO ‘FragConstants’ declaration
这个是slg 行军线的 shader
// Copyright © 2017-2018 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- vert: vs
frag: fs
blendState:
targets:- blend: true
rasterizerState:
cullMode: none
properties:
uSampler: {
type: sampler2D
}
customUniform: {
value: 0.5
}
projectionVector: {}
param : {
type: vec2
}
center : {
type: vec2
}
}%
- blend: true
- vert: vs
CCProgram vs %{
precision lowp float;
#include
#include
in vec2 a_position;
in vec2 aTextureCoord;
in vec2 a_color;
vec2 center = vec2(-1.0, 1.0);
out vec2 vTextureCoord;
out vec4 v_color;
void main(void) {
gl_Position = vec4( (a_position / cc_matProj) + center , 0.0, 1.0);
vTextureCoord = aTextureCoord;
v_color = vec4(a_color.x, a_color.x, a_color.x, a_color.x);
}
}%
CCProgram fs %{
precision lowp float;
out vec2 vTextureCoord;
out vec4 v_color;
uniform FragConstants {
sampler2D uSampler;
float customUniform;
vec2 param;
};
void main(void) {
vec2 uvs = vTextureCoord.xy;
uvs.x = mod(uvs.x - param.y + customUniform * param.x, param.x) + param.y;
vec4 fg = texture2D(uSampler, uvs);
gl_FragColor = fg * v_color;
}
}%
a.effect - fs - 6: error EFX2208: sampler uniforms must be declared outside blocks.
搞哭了
这提示不是很明显了么?
缺少分号
uniform FragConstants {
vec2 projectionVector;
vec2 center = vec2(-1.0, 1.0);
};
sampler不要放进去,其它的要放进去。
你要看下错误提示啊
// Copyright © 2017-2018 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- vert: vs
frag: fs
blendState:
targets:- blend: true
rasterizerState:
cullMode: none
properties:
uSampler: {
type: sampler2D
}
customUniform: {
value: 0
}
projectionVector: {}
param : {
type: vec2
}
}%
- blend: true
- vert: vs
CCProgram vs %{
precision lowp float;
#include
#include
in vec2 a_position;
in vec2 aTextureCoord;
in vec2 a_color;
vec2 center = vec2(-1.0, 1.0);
out vec2 vTextureCoord;
out vec4 v_color;
void main(void) {
gl_Position = vec4( (a_position / cc_matProj) + center , 0.0, 1.0);
vTextureCoord = aTextureCoord;
v_color = vec4(a_color.x, a_color.x, a_color.x, a_color.x);
}
}%
CCProgram fs %{
precision lowp float;
out vec2 vTextureCoord;
out vec4 v_color;
uniform sampler2D uSampler;
uniform FragConstants {
float customUniform;
vec2 param;
};
void main(void) {
vec2 uvs = vTextureCoord.xy;
uvs.x = mod(uvs.x - param.y + customUniform * param.x, param.x) + param.y;
vec4 fg = texture2D(uSampler, uvs);
gl_FragColor = fg * v_color;
}
}%
哎
为什么不直接用glsl 然后传个参数 好调试多了
萌新认真请教,请问写好后要怎么用TS调用这个函数?(在Update中改projectionVector)




