Hi everyone, I have seen a problem when I use custom shader code, on old device the game stop lauching and it log a lot of errors about shader compilation failed. This custom shader work fine for other devices. For now the old phone only work fine with built-in shaders. How can I fix this?
Device: OPPO a83, android 7.1.1
Cocos creator I am using: 3.5.1
too less info, you are supposed to provide more info of the shader, and the entire error messages.
Yeah, we need to know the end of the message, it should indicate which line causes the issue and the root reason, by the way, we have this device covered, so it should be working
Here is the log file:
1658735420227.zip (5.9 KB)
It just print the shader source code out.
Here is an example of my custom shader code, it just update image uv in realtime:
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- vert: sprite-vs:vert
frag: sprite-fs:frag
depthStencilState:
depthTest: false
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendDstAlpha: one_minus_src_alpha
rasterizerState:
cullMode: none
properties:
alphaThreshold: { value: 0.5 }
}%
CCProgram sprite-vs %{
precision highp float;
#include <cc-global>
#if USE_LOCAL
#include <cc-local>
#endif
in vec3 a_position;
in vec2 a_texCoord;
in vec4 a_color;
out vec4 color;
out vec2 uv0;
vec4 vert () {
vec4 pos = vec4(a_position, 1);
#if USE_LOCAL
pos = cc_matWorld * pos;
#endif
#if USE_PIXEL_ALIGNMENT
pos = cc_matView * pos;
pos.xyz = floor(pos.xyz);
pos = cc_matProj * pos;
#else
pos = cc_matViewProj * pos;
#endif
uv0 = a_texCoord;
color = a_color;
return pos;
}
}%
CCProgram sprite-fs %{
precision highp float;
#include <embedded-alpha>
#include <alpha-test>
#include <cc-global>
in vec4 color;
#if USE_TEXTURE
in vec2 uv0;
#pragma builtin(local)
layout(set = 2, binding = 10) uniform sampler2D cc_spriteTexture;
#endif
vec4 frag () {
vec2 uv = vec2(
uv0.x + (sin(cc_time.x * 0.5 + uv0.x * 10.0) - 0.5) * 0.01,
uv0.y + (sin(cc_time.x * 0.5 + uv0.y * 2.5) - 0.5) * 0.01
);
vec4 t_image = CCSampleWithAlphaSeparated(cc_spriteTexture, uv);
return t_image;
}
}%
I think it could be related to out of memory, and please use Android Studio logcat or Chrome devtools to capture logs, vconsole is not so helpful for rendering issues
Sadly the log from chrome devtools is the same as the one I showed above. I think I should find a way to debug it from preview mode on my phone.
Please check the memory of your phone, it could be 2GB to 4GB
Chrome could use a lot of memory under the hood, and it might causing the GL fail to compile the shader. That’s the main reason why it doesn’t work. You can try to build Android apk with GLES and if that works, then shaders are alright