J
J
Just_Graf2018-10-06 01:31:19
Shaders
Just_Graf, 2018-10-06 01:31:19

How to make the dark sides of a polygon visible in Unity?

That is, you need to make sure that the texture is displayed in the interior of the model. I know a way to achieve this (you need to select the "Alpha Blended" shader in the "Mobile" shaders list), but it does not fully meet my requirements, namely through the texture, where there is no alpha channel, places where there is an alpha channel are visible. I hope I was able to explain the situation. In general, if someone does not understand, you need a shader that makes transparent places where there is an alpha channel, so that this transparent place does not shine through the texture when viewed from different angles, i.e. this transparent place should be visible directly if look at it exactly, which is exactly what the "Alpha Blended" shader does not have, and this shader should display the texture on two sides of one polygon. Yes, probably, By default, Unity does not have all the desired shaders and you will need to write it yourself ... Then, if this is the case, if there is no such default shader, I'm waiting for your tips on writing just such a shader or an article on this topic. I don't know shader languages, if that. I know very basic C# stuff. Voot.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2018-10-06
@freeExec

In general, this is not a shader problem, it is a crooked model. If you need to look from the inside, then the inner surface must be created in it.

D
Daniil Basmanov, 2018-10-08
@BasmanovDaniil

A two-sided shader is easy to make, the instruction is responsible for this Cull Off, you can read more about culling here . You can get the transparency you need with the help alpha:fadeof, if we talk about surface shaders , it will be a little more difficult with other shaders. Below is the usual shader template, which I cleaned up a bit and added the two missing instructions.

Shader "Custom/NewSurfaceShader"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        // Выключаем куллинг, чтобы меш рисовался с двух сторон
        Cull Off

        CGPROGRAM
        // По с равнению со стандартным шаблоном в конце добавилось "alpha:fade" для получения прозрачности
        #pragma surface surf Standard fullforwardshadows alpha:fade
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
        };

        fixed4 _Color;
        sampler2D _MainTex;
        half _Glossiness;
        half _Metallic;

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 color = tex2D (_MainTex, IN.uv_MainTex)*_Color;
            o.Albedo = color.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = color.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

If you want to learn more about shaders, you can read The Book of Shaders and the corresponding section of the manual . There is also a good series of tutorials on this topic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question