My question was sent to the wrong place before, the link is as follows,
opened 10:13AM - 12 Aug 24 UTC
closed 10:23PM - 12 Aug 24 UTC
archived
discussion
topic:thirdparty
topic:shaders
topic:3d
### Tested versions
4.0.4 stable, 4.2stable
### System information
macO… S 14.4 (23E214) Godot 4.2, 4.0.4
### Issue description
```glsl
vec3 process_normal(vec3 dealColor, bool direction, float strength){
vec3 normal_out = dealColor;
normal_out = normalize(normal_out * 2.0 - 1.0); // 将归一化到-1到1区间
normal_out.x *= strength;
normal_out.y *= strength;
if (!direction){
normal_out.y *= -1.0;
}
normal_out = normalize(normal_out);
normal_out = (normal_out + 1.0) / 2.0;
return normal_out;
}
if (normal_enable && normal_enable1){
vec3 normalOut = vec3(1.0);
vec3 normal = texture(normal_map, UV).rgb;
vec3 normalVec = process_normal(normal,normal_direction,normal_strength);
normalOut = normalVec;
if (normal_enable1){
vec3 normal1 = texture(normal_map1, UV).rgb;
vec3 normalVec1 = process_normal(normal1,normal_direction1,normal_strength1);
if (blend_factor != EMPTY_BLEND_FACTOR && !normal_enable3){
normalOut = mix(normalVec,normalVec1,blend_factor);
}else{
normalOut = normalVec + normalVec1;
}
}
if (normal_enable2){
vec3 normal2 = texture(normal_map2, UV).rgb;
vec3 normalVec2 = process_normal(normal2,normal_direction2,normal_strength2);
if (blend_factor1 != EMPTY_BLEND_FACTOR && !normal_enable3){
normalOut = mix(normalOut,normalVec2,blend_factor1);
}else{
normalOut = normalOut + normalVec2;
}
}
if (normal_enable3){
vec3 normal3 = texture(normal_map3, UV).rgb;
vec3 normalVec3 = process_normal(normal3,normal_direction3,normal_strength3);
if (blend_factor != EMPTY_BLEND_FACTOR){
normalOut = mix(normalOut,normalVec3,blend_factor);
}else{
normalOut = normalOut + normalVec3;
}
}
// normalOut = normalize(normalOut);
// normalOut = (normalOut + 1.0) / 2.0;
NORMAL_MAP = normalOut;
}else if (normal_enable && !normal_enable1) {
vec3 normalOut = vec3(1.0);
normalOut = texture(normal_map, UV).rgb;
NORMAL_MAP = normalOut;
float normalStrength = normal_strength;
if (normalStrength > 8.0){
normalStrength = 8.0;
}
float depth = -normalStrength;
if (!normal_direction){
depth = normalStrength;
}
NORMAL_MAP_DEPTH = depth;
}
```
In pbr_material-shader.tres, referring to the effect of Blender, process the texture and intensity of normal to generate a vector, and then merge several vectors using mix or addition.
If there is only one normal texture and one normal intensity, I set the normal texture to NORMAL_ MAP and the normal intensity to NORMAL_ MAP_DEPTH, and the effect is similar to Blender.
If there are multiple normal textures and normal intensities, I process each normal texture and its normal intensity using the process_normal method to generate a normal vector. Then, I fuse several generated normal vectors and set them to NORMAL_MAP without setting NORMAL_MAP_DEPTH. In this case, modifying the intensity of each normal has no significant effect, which is inconsistent with the blender effect.
The following two images show the effect of three normals having an intensity of 1:
In the Godot app:
![image](https://github.com/user-attachments/assets/93d3d733-cf40-4b76-98a1-32fd7688a6cf)
In Blender:
![image](https://github.com/user-attachments/assets/0b93368f-020c-49b4-af0e-76e7b6ec8eca)
Their effects are very similar.
The following two images show the first and second with a normal intensity of 1, and the third with a normal intensity of 10:
In the Godot app:
![image](https://github.com/user-attachments/assets/be06a0eb-4499-4a7e-b9af-3553f22621c1)
In Blender:
![image](https://github.com/user-attachments/assets/15b25394-b902-4910-874d-fe777bd3000d)
Their differences are quite obvious.
Modifying the normal strength is invalid in the above algorithm.
### Steps to reproduce
![image](https://github.com/user-attachments/assets/23bb1d6a-0263-4681-b1d0-e0ea32b3c5ba)
In the node_3d_test.tscn scenario,modify the intensity of three normals in the graph.
### Minimal reproduction project (MRP)
[Test0520.zip](https://github.com/user-attachments/files/16580229/Test0520.zip)
If there is only one normal texture and one normal intensity, it is effective for me to directly set it to NORMAL_MAP and NORMAL_MAP_DEPTH.
But if there are three normal textures, each with a normal intensity, and the vectors are generated by calculation, then the three vectors are mixed in sequence according to the mixing factor, and finally set to the normal vectors, how should the code be written?
Can anyone give some advice?