Do you maybe have an example shader that includes the original lighting? Or some links to resources? I'm new to shaders but willing to get into it.
This is my current AI generated shader:
const texture = useTexture({...})
const fragmentShader = `
uniform sampler2D uTextureBase;
uniform sampler2D uTextureSkin;
uniform sampler2D uNormalMap;
uniform sampler2D uAoMap;
uniform vec3 lightDirection;
varying vec2 vUv;
varying vec3 vViewPosition;
varying mat3 vTBN;
void main() {
vec4 baseColor = texture2D(uTextureBase, vUv);
vec4 overlayColor = texture2D(uTextureSkin, vUv);
float ao = texture2D(uAoMap, vUv).r;
vec3 color = mix(baseColor.rgb, overlayColor.rgb, overlayColor.a);
vec3 normalTex = texture2D(uNormalMap, vUv).rgb * 2.0 - 1.0;
vec3 normal = normalize(vTBN * normalTex);
float diff = max(dot(normal, normalize(lightDirection)), 0.3);
color *= diff * ao;
gl_FragColor = vec4(color, 1.0);
}
`
const vertexShader = `
varying vec2 vUv;
varying vec3 vViewPosition;
varying mat3 vTBN;
attribute vec4 tangent;
void main() {
vUv = uv;
vec3 pos = (modelViewMatrix * vec4(position, 1.0)).xyz;
vViewPosition = -pos;
vec3 n = normalize(normalMatrix * normal);
vec3 t = normalize(normalMatrix * tangent.xyz);
vec3 b = normalize(cross(n, t) * tangent.w);
vTBN = mat3(t, b, n);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`
const customPaintMaterial = new THREE.ShaderMaterial({
uniforms: {
uTextureBase: { value: texture.base },
uTextureSkin: { value: texture.skin },
uAoMap: { value: texture.ao },
uNormalMap: { value: texture.normalMap },
lightDirection: { value: new THREE.Vector3(0.5, 1.0, 0.3).normalize() },
},
vertexShader: vertexShader,
fragmentShader: fragmentShader,
lights: false,
})