Hello, so my issue is such, I have made a shader that causes a UV distortion in the fragment shader, to simulate “flame-like” effects at the edges.
There are two variants of these shaders, one where the distortion is dependent on cc_time[0] i.e the time elapsed in seconds when a game is running. The other variant is a elapsedTime i.e the time that I manually increase in the material inspector, to simulate time.
The elapsedTime time variant shows me this:
As expected it provides the flame effect
The cc_time[0] variant, shows me this:
This is the effect’s fragment shader code:
CCProgram sprite-fs %{
precision highp float;
#include <builtin/internal/embedded-alpha>
#include <builtin/internal/alpha-test>
#include <builtin/uniforms/cc-global>
in vec4 color;
in vec4 vertexPos;
uniform sampler2D maskTexture;
uniform sampler2D normalTexture;
uniform DistortionParameters {
float distortionSpeed;
float distortionScale;
float normalMapScale;
float edgeThickness;
float flameIntensity;
float elapsedTime;
};
#if USE_TEXTURE
in vec2 uv0;
#pragma builtin(local)
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
#endif
// Give random value function
float getRandom (vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))
* 43758.5453123);
}
vec2 getOriginalUV() {
return uv0;
}
vec4 getTextureVector(vec2 UV, sampler2D Texture) {
return texture(Texture, UV);
}
vec4 frag () {
vec2 newUV = getOriginalUV();
// Calculate the distance from the UV coordinates to the nearest edge
float distFromEdge = min(min(newUV.x, 1.0 - newUV.x), min(newUV.y, 1.0 - newUV.y));
// Calculate the flame distortion amount based on the distance from the edge
float distortionAmount = flameIntensity * (1.0 - smoothstep(0.0, edgeThickness, distFromEdge));
//This the cc_time[0] variant
float randomOffset = sin(newUV.x * 10.0 + newUV.y + cc_time[0] * 20.0 * distortionSpeed) * distortionAmount;
//This is the elapsed time variant
// float randomOffset = sin(newUV.x * 10.0 + newUV.y + elapsedTime * 20.0 * distortionSpeed) * distortionAmount;
// Distort UV
newUV += vec2(0.0 , randomOffset);
vec4 newTexture = getTextureVector(newUV, cc_spriteTexture);
vec4 o = vec4(newTexture);
o *= color;
ALPHA_TEST(o);
return o;
}
}%
I would like to know how I can make the cc_time[0] variant look like the elapsedTime variant. Am I doing something fundamentally wrong? Would appreciate the help, thanks