Unity高級(jí)開發(fā)(四)-Shader編程:寫一個(gè)shader讓圖片的背面不被剔除

原因

面試了一家VR房地產(chǎn)公司,給了幾張圖片,要求做出VR漫游效果。通過3個(gè)小時(shí)研究,我發(fā)現(xiàn)問題還是在shader這一塊,故貼出代碼,如果其他小朋友遇到就可以嘗試一下,下面的方法

問題:

將圖片直接扔到材質(zhì)球中,結(jié)果并不能很好的顯示,而且場(chǎng)景光線很暗。原有的光線并不能很好的展示。

怎么做?

首先將素材打開

Paste_Image.png
Paste_Image.png

其次拖入工程,選取下面的模式


Paste_Image.png

創(chuàng)建一個(gè)材質(zhì)球


Paste_Image.png

建立一個(gè)shader

Paste_Image.png

shader代碼

如果看不懂,請(qǐng)看我之前的兩篇博客。就可以看明白下面寫的什么了。

Shader "Custom/SYShader" {
        Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Texture", 2D) = "white"{}
    }
        SubShader
    {
        //Ambient pass 
        Pass
    {
        Name "BASE"
        Tags{ "LightMode" = "Always" /* Upgrade NOTE: changed from PixelOrNone to Always */ }
        Color[_PPLAmbient]
        SetTexture[_BumpMap]
    {
        constantColor(.5,.5,.5)
        combine constant lerp(texture) previous
    }
        SetTexture[_MainTex]
    {
        constantColor[_Color]
        Combine texture * previous DOUBLE, texture *constant
    }

    }

        //Vertex lights 
        Pass{
        Name "BASE"
        Tags{ "LightMode" = "Vertex" }
        Material
    {
        Diffuse[_Color]
        Emission[_PPLAmbient]
        Shininess[_Shininess]
        Specular[_SpecColor]
    }

        SeparateSpecular On
        Lighting On
        cull off
        SetTexture[_BumpMap]
    {
        constantColor(.5,.5,.5)
        combine constant lerp(texture) previous
    }
        SetTexture[_MainTex]
    {
        Combine texture *previous DOUBLE, texture *primary
    }
    }

    }

        FallBack "Diffuse", 1
    }
}

再創(chuàng)建一個(gè)Sphere物體,放大10倍,最后將材質(zhì)球應(yīng)用就Ok了!


Paste_Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容