Untitled
unknown
plain_text
a year ago
2.2 kB
7
Indexable
uniform sampler2D u_diffuseTexture;
uniform sampler2D u_maskTexture;
uniform sampler2D u_normalMap;
uniform vec3 u_color;
uniform vec3 u_lightDirection;
uniform vec3 u_ambientLight;
varying vec2 v_texCoord;
varying vec3 v_normal;
void main() {
vec2 flippedUV = vec2(v_texCoord.x, 1.0 - v_texCoord.y);
// Pobieranie kolorów z tekstur
vec4 diffuseColor = texture2D(u_diffuseTexture, flippedUV);
vec4 maskColor = texture2D(u_maskTexture, flippedUV);
vec3 normal = texture2D(u_normalMap, flippedUV).rgb;
// Stała wartość roughness
float roughness = 0.5;
// Normalizacja normal mapy z zakresu [0, 1] do [-1, 1]
normal = normalize(normal * 2.0 - 1.0);
// Obliczanie oświetlenia rozproszonego (diffuse)
vec3 lightDir = normalize(u_lightDirection);
float diff = max(dot(normal, lightDir), 0.0);
// Wpływ roughness na diffuse
vec3 ambient = u_ambientLight * diffuseColor.rgb;
vec3 diffuse = diff * diffuseColor.rgb * (1.0 - roughness); // Wpływ roughness na diffuse
vec3 colorWithMask = mix(diffuseColor.rgb, u_color, step(0.5, maskColor.b));
// Finalny kolor
vec3 finalColor = ambient + diffuse * colorWithMask;
gl_FragColor = vec4(finalColor, diffuseColor.a);
}
const diffuseTexture = new THREE.TextureLoader().load('path/to/your/diffuseTexture.png');
const maskTexture = new THREE.TextureLoader().load('path/to/your/maskTexture.png');
const normalTexture = new THREE.TextureLoader().load('path/to/your/normalMap.png');
const customShaderMaterial = new THREE.ShaderMaterial({
vertexShader: vertexShaderCode, // Zdefiniuj kod vertex shader
fragmentShader: fragmentShaderCode, // Zdefiniuj kod fragment shader
uniforms: {
u_diffuseTexture: { value: diffuseTexture },
u_maskTexture: { value: maskTexture },
u_normalMap: { value: normalTexture },
u_color: { value: new THREE.Color(1, 0, 0) }, // Kolor
u_lightDirection: { value: new THREE.Vector3(1, 1, 1).normalize() }, // Kierunek światła
u_ambientLight: { value: new THREE.Vector3(0.2, 0.2, 0.2) } // Światło otoczenia
}
});
Editor is loading...
Leave a Comment