Regular expressions about material plugins

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!!!

cc @Evgeni_Popov

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:

1 Like