Can somebody help me verify is this is the value that makethe lightnign and the color of the mesh to change when i rotate camera around a random object?

i see on many shader there is a many reference for geometryViewDir, i mlooking for the variable that make a object change it color depending if the camera and the source of light are aligned or not , for example, if the light and the camera have the same direction , the color is x and when the camera and the source of light are opositte the color is y , i added a small video of it, three.js/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js at dev · mrdoob/three.js · GitHub

vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );

i have a big issue where depending if the camera is aligned or in oposite position of the source of light , the color changes which is very bad , i want to cancel it , i tried to do it by setting a normal to normal = vec3(0.0, 1.0, 0.0); but i still have the error

I think the thing you’re looking for may be an AmbientLight() ?

AmbientLight lights from all directions.. (and doesn’t produce shadows)

thanks you but i mean what i need is to make the current pipeline of shadow view agnostic for meshstandard material since i want to reuse since it has the shadow pipeline , so far i had made this tries

  • using mesh basic material i injected the shadow system from mesh stanard material but i cannot get the same color , tried to inject a few shader but didnt worked

  • i rollbacked to use mesh standard material and trying to find the part that make the color change when the camera rotate to disable it as the vieo shown, as you see the color of the grass changes when the camera is aligned or not aligned with the source of light , as far as a know it should be caused by a dot product somewhere but not sure which , i know is physical correct but dont like it to be applied on the grass , so far im able to get this

shader.fragmentShader = shader.fragmentShader.replace('#include <lights_fragment_begin>', grassBillboards_fragment_shader_lights_fragment_begin);
shader.fragmentShader = shader.fragmentShader.replace(
'#include <normal_fragment_begin>',
`
#include <normal_fragment_begin>
normal = vec3(0.0, 1.0, 0.0);
`
);
shader.fragmentShader = shader.fragmentShader.replace(
'#include <lights_physical_fragment>',
`
PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );
material.metalness = metalnessFactor;

vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );

material.roughness = max( roughnessFactor, 0.0525 );// 0.0525 corresponds to the base mip of a 256 cubemap.
material.roughness += geometryRoughness;
material.roughness = min( material.roughness, 1.0 );
material.specularColor = vec3( 0.04 );
material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
material.specularF90 = 1.0;
`

); where grassBillboards_fragment_shader_lights_fragment_begin is the same code as three.js/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js at dev · mrdoob/three.js · GitHub but with vec3 geometryViewDir = vec3( 0, 0, 1 ) : if i do vec3(0,0,-1) i get the same problem i have with (0,0,1) but inversed so the problem is asociated with geometryViewDir but not really, is more asocoiated to how geometryViewDir is later used in the function defined on three.js/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js at dev · mrdoob/three.js · GitHub for example RE_Direct_Physical method , i will try to keep checkign tomorrow after taking a break but if anyone have been able to disable the problem i described in the video please let me know if there is anythign easier than what im trying to do

if I understand correctly you may not even need a shader for this, you could maybe do something like…

objectToLightDirection = object.position to light.position normalised Vector3 direction

objectToCameraDirection = object.position to camera.position normalised Vector3 direction

angleDifference = objectToLightDirection.angleTo(objectToCameraDirection)

object.material.color.setHSL( (255/360) * (RadToDeg(angleDifference) + 180), 0.5, 0.5)

if you were to use a shader it still may be best to first figure out the angle to and from the objects color you want to manipulate.

Remove or disable all the lights in your scene. Make sure you’re not setting an environment map. Verify that your scene geometry renders entirely black from all directions.

Then add a single:

scene.add(new THREE.AmbientLight(‘white’))


Verify that the lighting is the same from all directions.

— What you DONT want to do, is try to break the lighting fragments you’re including in the custom shader. Those fragments will already correctly observe the lighting conditions set up in your scene, and if you only have a single AmbientLight.. the lighting should be uniform from all directions. If it isn’t, then there may be an issue somewhere else. (perhaps a stray environment map or light or something)

loved the idea , i merged your idea with older version of mine , make the grass beleive here is no directional light and still having them as mesh standard material so magically everythign work but there is no view dependence, grass work work ambient light only while other still work with the dirtectional light