Is there any way to make image negative in Three.js

You can edit shader code with onBeforeCompile

material.onBeforeCompile=function(shader){
  shader.fragmentShader= shader.fragmentShader.replace('#include <roughnessmap_fragment>',
  //the line '#include <roughnessmap_fragment>' will replaced with text from THREE.ShaderChunk.roughnessmap_fragment
  //there is a line "vec4 texelRoughness = texture2D( roughnessMap, vUv );"
  //we need "invert" a value getting from texture: texelRoughness = 1. - texture2D( roughnessMap, vUv )
  THREE.ShaderChunk.roughnessmap_fragment.replace('texelRoughness =', 'texelRoughness = 1. -'))
}
1 Like