The problem of model texture sampling

https://www.babylonjs-playground.com/#4AJ16M#68
This is my scene PG and I am now using shaders to make the model transparent;But now I seem to be having a bit of a problem, and I find that my model textures are very messy in the scene,
image

  • If I want to do this with my model, what else should I do
    image

BABYLON.Effect.ShadersStore[“customVertexShader”]=“precision highp float;\r\n”+
“\r\n”+
“// Attributes\r\n”+
“attribute vec3 position;\r\n”+
“attribute vec3 normal;\r\n”+
“attribute vec2 uv;\r\n”+
“\r\n”+
“// Uniforms\r\n”+
“uniform mat4 worldViewProjection;\r\n”+
“uniform mat4 world;\r\n”+
“uniform float time;\r\n”+

    "varying vec3 vPositionW;\r\n"+
    "varying vec3 vNormalW;\r\n"+

    "\r\n"+
    "// Varying\r\n"+
    "varying vec2 vUV;\r\n"+
    "\r\n"+
    "void main(void) {\r\n"+
    "    vec3 v = position;\r\n"+
    "    v.y += uv.y * time;\r\n"+
    "    if(v.y > 1.0) \r\n"+
    "           {  \r\n"+
    "              int id = int(v.y) ; \r\n"+
    "              v.y -= float(id) ; \r\n"+
    "           } \r\n"+
    "    vec4 outPosition = worldViewProjection * vec4(position, 1.0);\r\n"+
    "    gl_Position = outPosition;\r\n"+

    "    vPositionW=vec3(world*vec4(position, 1.0));\r\n"+
    "    vNormalW = normalize(vec3(world * vec4(normal, 0.0)));\r\n"+
    "    \r\n"+
    "    //vUV = uv;\r\n"+
    "    vUV = vec2(uv[0], v.y);\r\n"+
    "\r\n"+
    "}\r\n";

BABYLON.Effect.ShadersStore["customFragmentShader"]=    "precision highp float;\r\n"+
    "\r\n"+
        "// Varying\r\n"+
        "varying vec2 vUV;\r\n"+
        "varying vec3 vPositionW;\r\n"+
        "varying vec3 vNormalW;\r\n"+
        "\r\n"+
        "uniform sampler2D albedoMap;\r\n"+
        "uniform vec3 cameraPosition;\r\n"+
        "\r\n"+

        "void main(void) {\r\n"+
        "\r\n"+
        "    vec3 color=vec3(1,1,1);\r\n"+
        "    vec3 albedo = texture2D(albedoMap, vUV).rgb;\r\n"+
        "    float alpha=albedo.b;\r\n"+
        "    vec4 baseColor=vec4(1,1,1,1);\r\n"+
        "    vec4 fresnelHDR=vec4(0.0,0.262,0.74,0.321);\r\n"+

        "    vec3 viewDirectionW = normalize(cameraPosition - vPositionW);\r\n"+
        "    float fresnelTerm = dot(viewDirectionW, vNormalW);\r\n"+
        "    fresnelTerm = clamp(1.0 - fresnelTerm, 0., 1.);\r\n"+

        "\r\n"+
        "//compute FersnelColor\r\n"+
        "    vec4 fersnelEffect=vec4(fresnelTerm*color,1.);\r\n"+
        "    vec4 fersnelColor=vec4(fresnelHDR*fersnelEffect);\r\n"+
        "    vec4 oneMinColor = vec4(vec3(1, 1, 1) - albedo, 1.0); \r\n" +
        "    vec4 midColor = oneMinColor * baseColor;\r\n"+
        "    vec4 emissionColor=vec4(fersnelColor+midColor);\r\n"+
        " \r\n"+
        "   \r\n"+
        "   gl_FragColor = vec4(emissionColor[0],emissionColor[1],emissionColor[2],alpha); \r\n"+
        "  //gl_FragColor = vec4(vUV.y, 0, 0, 1); \r\n"+
        
        "}\r\n"; 
  • This is my shader code

The UVs of your model do not look like they fit with your texture.

image
I don’t know what the problem is yet. My texture is implemented with one of these textures, but it seems to be in the wrong place on the model

yup, the texture is applied following uv values: UV mapping - Wikipedia

Hence why the issue probably lies in there

1 Like

I feel like I have a problem with the edge light calculation, but now I’m not entirely sure if it’s the texture

You should consider using literal quotes
``

so that way you don’t have to keep concatenating your lines and doing carriage returns.

1 Like

Sorry, I was wondering if BBL has an API for rendering mesh lines of models, not wireframe

*
I need to achieve this effect

What do you mean by mesh lines of models ?

What you show in your picture looks like a wireframe from a tesselated mesh mixed with an opacity fresnel of the same mesh ?

是的,他这个是用three.js实现的,内部的api

EdgesGeometry
EdgesGeometry
LineSegments

What should babylonjs do

@塞巴万绝地议会

Maybe @Pryme8 would come with an amazing custom shader ???

Or @nasimiasl :wink: ?

1 Like
  • I don’t know. Can they help me

hey let me see what we have before …

yes thanks

  • I want this effect
1 Like

don’t worry you get it let me do :slight_smile: