Hi @Davide i am wondering as i was looking into the source code in the pixi spine v8 repo under
Spine.ts
readonly _slotsObject: Record<string, { slot: Slot, container: Container, followAttachmentTimeline: boolean } | null>
Do you think it will work if i iterate over the slots which has the pixijs Container and apply my normal filter map there?
In my filter, i pass in the original texture (the atlas) so i can remap the vTextureCoord to the original texture coordinate to sample the normal map.
Im not sure if theres more things that goes on behind the hood, but do you think this would work?
precision mediump float;
in vec2 vTextureCoord;
uniform vec4 uInputSize;
uniform vec4 uOutputFrame;
uniform sampler2D uTexture;
uniform sampler2D uNormalTexture;
uniform vec3 uLight; // x, y, intensity
uniform float uAmbient;
void main(void)
{
// Sample the original texture using vTextureCoord
vec4 color = texture2D(uTexture, vTextureCoord);
if (color.a < 0.0001) {
discard;
}
if(uLight[2] > 0.0) {
// Sample the normal map (the UVs for uNormalTexture is not vTextureCoord, need to recalculate)
// See https://github.com/pixijs/pixijs/issues/6266
// See https://github.com/pixijs/pixijs/wiki/v5-Creating-filters#conversion-functions
vec4 normalColor = texture2D(uNormalTexture, vTextureCoord * uInputSize.xy / uOutputFrame.zw);
// Convert normal map color from [0,1] to [-1,1] range
vec3 normal = normalize(normalColor.rgb * 2.0 - 1.0);
// Create light direction vector
vec3 lightDir = normalize(vec3(uLight.xy, 1.0));
// Calculate dot product between normal and light direction
float lightIntensity = max(dot(normal, lightDir), 0.0);
// Apply light intensity and user-defined light strength
float finalLightIntensity = mix(uAmbient, 1.0, lightIntensity * uLight[2]);
// Apply lighting to color
color.rgb *= finalLightIntensity;
}
gl_FragColor = color;
}