Hi I am trying to generate the terrain and i have image as a texture to that terrain and i have issue regarding encoding, color space or i don’t know something that i am not aware of.
When i do sRGBEncoding the image comes sharp but very yellowish and dark whereas when i use default image is not enough sharp as sRGBEncoding.
my renderer:
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.gammaFactor = 2.4;
renderer.shadowMap.enabled = true;
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
and when i do
texture.encoding = THREE.sRGBEncoding;
full texture loading code:
loader.load(
"./resources/images/satellite.png",
function (texture) {
texture.needsUpdate = true;
texture.encoding = THREE.sRGBEncoding;
texture.generateMipmaps = false;
texture.magFilter = THREE.LinearFilter;
whereas with out texture.encoding defined which is by default
THREE.LinearEncoding
output is
for same lighting i.e
const ambientLight = new THREE.AmbientLight(0x808080); // soft white light
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.7);
dirLight.color.setHSL(0.1, 1, 0.95);
dirLight.position.set(1000, 5000, -29000);
dirLight.position.multiplyScalar(2);
scene.add(dirLight);
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 64;
dirLight.shadow.mapSize.height = 64;
const d = 500;
dirLight.shadow.camera.left = -d;
dirLight.shadow.camera.right = d;
dirLight.shadow.camera.top = d;
dirLight.shadow.camera.bottom = -d;
dirLight.shadow.camera.far = 3500;
dirLight.shadow.bias = -0.0001;
this is after making light soft
making soft lighting by setting light as:
const ambientLight = new THREE.AmbientLight(0x202020); // soft white light
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.5);
dirLight.color.setHSL(0.1, 1, 0.95);
dirLight.position.set(1000, 25000, -40000);
dirLight.position.multiplyScalar(2);
scene.add(dirLight);
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 64;
dirLight.shadow.mapSize.height = 64;
const d = 500;
dirLight.shadow.camera.left = -d;
dirLight.shadow.camera.right = d;
dirLight.shadow.camera.top = d;
dirLight.shadow.camera.bottom = -d;
dirLight.shadow.camera.far = 3500;
dirLight.shadow.bias = -0.0001;
the size of this mesh is: 205200x92800 and height of vertices ranging from 0 to 1000
I want the sharpness of the first mesh and illumination or lighting of second image and i believe that i am doing something wrong. The first image is very yellowish, can anyone please give me any kind of help.
PS: i am using custom shader with:
uniforms1 = {
diffuseTexture: { type: "t", value: texture },
heightScale: { type: "f", value: _scaleHeight },
};
uniforms1 = THREE.UniformsUtils.merge([
THREE.UniformsLib["lights"],
uniforms1,
]);
console.log(uniforms1);
_meshMaterial = new THREE.RawShaderMaterial({
uniforms: uniforms1,
vertexShader: terrainShader._VS,
fragmentShader: terrainShader._FS,
lights: true,
side: THREE.DoubleSide,
});
and this is my fragment shader:
const _FS = `#version 300 es
precision highp sampler2DArray;
precision highp float;
precision highp int;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform vec3 cameraPosition;
uniform sampler2D diffuseTexture;
struct DirectionalLight {
vec3 direction;
vec3 color;
};
uniform DirectionalLight directionalLights[NUM_DIR_LIGHTS];
uniform vec3 ambientLightColor;
vec3 addedLights;
vec3 _vNormalView ;
in vec3 vNormal;
in vec3 vNormalView;
in vec3 vPosition;
out vec4 out_FragColor;
vec3 blendNormal(vec3 normal){
vec3 blending = abs(normal);
blending = normalize(max(blending, 0.00001));
blending /= vec3(blending.x + blending.y + blending.z);
return blending;
}
vec3 triplanarMapping (sampler2D tex, vec3 normal, vec3 position) {
vec3 normalBlend = blendNormal(normal*normal);
vec3 xColor = texture(tex, position.yz).rgb;
vec3 yColor = texture(tex, position.xz).rgb;
vec3 zColor = texture(tex, position.xy).rgb;
// return normalBlend;
return (xColor * normalBlend.x + yColor * normalBlend.y + zColor * normalBlend.z);
}
void directionalLightEffect(){
for (int i = 0; i < NUM_DIR_LIGHTS; i++) {
vec3 dirVector = directionalLights[i].direction;
vec3 _lightDir = normalize(dirVector);
float lambertian = max(dot(_vNormalView, _lightDir), 0.0);
addedLights.rgb += directionalLights[i].color*lambertian;
}
}
void main(){
_vNormalView = normalize(vNormalView);
addedLights = ambientLightColor;
vec3 color = triplanarMapping(diffuseTexture, vNormal, vPosition);
directionalLightEffect();
out_FragColor = vec4(color.rgb *addedLights, 1.0);
}```