When using the plugin, it is known that defines does not meet my replacement requirements
So regular expressions were chosen, but it seems that they didn’t work
if (shaderType === "fragment") {
return {
CUSTOM_FRAGMENT_DEFINITIONS: `
precision highp float;
varying vec2 vUV;
float fadeDistance = 100.0; // fadeout distance
vec2 fadeCenter = vec2(0.0, 0.0); // fadeout center
`,
"!normalW\\s*=\\s*perturbNormal\\(\\s*TBN\\s*,\\s*texture\\(\\s*bumpSampler\\s*,\\s*vBumpUV\\s*\\+\\s*uvOffset\\s*\\)\\.xyz\\s*,\\s*vBumpInfos\\.y\\s*\\);": `
normalW = perturbNormal(TBN, texture(bumpSampler, vBumpUV + uvOffset).xyz, dist);
`,
"!vec3\\s*ambientOcclusionColorMap\\s*=\\s*texture\\(\\s*ambientSampler\\s*,\\s*vAmbientUV\\s*\\+\\s*uvOffset\\s*\\)\\.rgb\\s*;": `
float dist = distance(vUV, fadeCenter);
vec3 ambientOcclusionColorMap = texture(ambientSampler, vAmbientUV + uvOffset).rgb;
ambientOcclusionColorMap *= dist;
`,
};
}
I need the normal strength and ao strength to become weaker and weaker according to the distance from the center point
Where is the problem?
The plugin did not report an error, indicating that the replacement was unsuccessful.
Always thank you for helping me!!!
The best way to debug such problems is to use Spector and see what the code is.
In your case, I don’t see any occurence of perturbNormal
in the fragment code used to display the plane: you will have to use a bump texture in your material so that this code is used.
Same thing for the second regex, ambientOcclusionColorMap
doesn’t appear in the fragment code, you will have to use an occlusion map for your material before this code can be updated.
I’m very sorry that this is a wrong pg. I’m in a hurry to show my code in the pg. In my actual project, there are indeed bumpTexture and aoTexture
The previous pg has been improved!!
These two lines are the code that I want to replace with regular expressions
@Evgeni_Popov
It’s a bit unfortunate, but at the time the regex is applied on the code, texture
is still texture2D
:
#endif
#ifdef BUMP
#ifdef OBJECTSPACE_NORMALMAP
#define CUSTOM_FRAGMENT_BUMP_FRAGMENT
normalW = normalize(texture2D(bumpSampler, vBumpUV).xyz * 2.0 - 1.0);
normalW = normalize(mat3(normalMatrix) * normalW);
#elif !defined(DETAIL)
normalW = perturbNormal(TBN, texture2D(bumpSampler, vBumpUV + uvOffset).xyz, vBumpInfos.y);
#else
vec3 bumpNormal = texture2D(bumpSampler, vBumpUV + uvOffset).xyz * 2.0 - 1.0;
// Reference for normal blending: https://blog.selfshadow.com/publications/blending-in-detail/
#if DETAIL_NORMALBLENDMETHOD == 0 // whiteout
detailNormal.xy *= vDetailInfos.z;
vec3 blendedNormal = normalize(vec3(bumpNormal.xy + detailNormal.xy, bumpNormal.z * detailNormal.z));
#elif DETAIL_NORMALBLENDMETHOD == 1 // RNM
detailNormal.xy *= vDetailInfos.z;
bumpNormal += vec3(0.0, 0.0, 1.0);
detailNormal *= vec3(-1.0, -1.0, 1.0);
1 Like