Search Unity

Runtime obj loader texture error

Discussion in 'Formats & External Tools' started by corrivai, Nov 6, 2021.

  1. corrivai

    corrivai

    Joined:
    Mar 14, 2016
    Posts:
    12
    Hi everyone,
    I have a 3D model (obj.) wich I upload to runtime with the Runtime Obj Importer asset.
    The problem is that if i apply a texture with some transparent parts, to a material, these parts become white.
    Can you help me?

    Shader:

    Code (CSharp):
    1. Shader "Custom/CullOffShader" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Metallic ("Metallic", Range(0,1)) = 0.0
    7.         //Properties
    8.         _EmissionLM("Emission (Lightmapper)", Float) = 0
    9.         [Toggle] _DynamicEmissionLM("Dynamic Emission (Lightmapper)", Int) = 0
    10.     }
    11.     SubShader {
    12.         Tags { "RenderType"="Opaque" }
    13.         LOD 200
    14.         Cull Off
    15.  
    16.         CGPROGRAM
    17.         // Physically based Standard lighting model, and enable shadows on all light types
    18.         #pragma surface surf Standard fullforwardshadows
    19.  
    20.         // Use shader model 3.0 target, to get nicer looking lighting
    21.         #pragma target 3.0
    22.  
    23.         sampler2D _MainTex;
    24.  
    25.         struct Input {
    26.             float2 uv_MainTex;
    27.         };
    28.  
    29.         half _Glossiness;
    30.         half _Metallic;
    31.         fixed4 _Color;
    32.  
    33.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    34.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    35.         // #pragma instancing_options assumeuniformscaling
    36.         UNITY_INSTANCING_BUFFER_START(Props)
    37.             // put more per-instance properties here
    38.         UNITY_INSTANCING_BUFFER_END(Props)
    39.  
    40.         void surf (Input IN, inout SurfaceOutputStandard o) {
    41.             // Albedo comes from a texture tinted by color
    42.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    43.             o.Albedo = c.rgb;
    44.             // Metallic and smoothness come from slider variables
    45.             o.Metallic = _Metallic;
    46.             o.Smoothness = _Glossiness;
    47.             o.Alpha = c.a;
    48.         }
    49.         ENDCG
    50.     }
    51.     FallBack "Diffuse"
    52. }
    3D model with transparent texture
    FB_IMG_1636205727030.jpg

    Material preview
    FB_IMG_1636205718980.jpg
    Applied texture
    FB_IMG_1636205711956.jpg


    Thank you