Standard Surface Shader - Billboard

Шейдеры и все-все-все.

Standard Surface Shader - Billboard

Сообщение ladder 14 янв 2018, 12:08

Здравствуйте, в шейдерах особо не разбераюсь. Хотел перенести код Billboard из Unlit шейдера в стандартный шейдер. Но он перестал следить за камерой. В Unlit все нормально. Помогите разобраться.

Синтаксис:
Используется csharp
Shader "TestShader/Billboard" {
        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
               
                CGPROGRAM
                // Physically based Standard lighting model, and enable shadows on all light types
                #pragma surface surf Standard fullforwardshadows
                #pragma vertex vert
                // Use shader model 3.0 target, to get nicer looking lighting
                #pragma target 3.0
                #include "UnityCG.cginc"
                sampler2D _MainTex;

                struct Input {
                        float2 uv_MainTex;
                };

                struct v2f
                {
                        float4 pos : SV_POSITION;
                        float2 uv : TEXCOORD0;
                };

                half _Glossiness;
                half _Metallic;
                fixed4 _Color;
                float4 vv;


                void surf (Input IN, inout SurfaceOutputStandard o) {
                        // Albedo comes from a texture tinted by color
                        fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
                        o.Albedo = c.rgb;
                        // Metallic and smoothness come from slider variables
                        o.Metallic = _Metallic;
                        o.Smoothness = _Glossiness;
                        o.Alpha = c.a;
                }



                v2f vert(inout appdata_full v) {

                        v2f o;
                        float4 ori = mul(UNITY_MATRIX_MV, float4(0, 0, 0, 0));
                        float4 vt = v.vertex;
                        vt.y = vt.z;
                        vt.z = 0;
                        vt.xyz += ori.xyz;//result is vt.z==ori.z ,so the distance to camera keeped ,and screen size keeped
                        o.pos = mul(UNITY_MATRIX_P, vt);
                        v.vertex = o.pos;
                        //o.uv = v.uv;
                        return o;

                }


                ENDCG
        }
        FallBack "Diffuse"
}
 
ladder
UNец
 
Сообщения: 5
Зарегистрирован: 14 янв 2018, 11:49

Re: Standard Surface Shader - Billboard

Сообщение ladder 16 янв 2018, 20:09

Синтаксис:
Используется csharp
Shader "TestShader/NewUnlitShader"
{
        Properties
        {
                _MainTex ("Texture", 2D) = "white" {}
                _TintColor("Tint Color", Color) = (1,1,1,1)
                _Transparency("Transparency", Range(0.0,0.5)) = 0.25

        }
        SubShader
        {
                        Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
                LOD 100

                        Lighting On


                        Blend SrcAlpha OneMinusSrcAlpha
                Pass
                {
                        CGPROGRAM
                        #pragma vertex vert
                        #pragma fragment frag
               
                        // make fog work
                        #pragma multi_compile_fog
                       
                        #include "UnityCG.cginc"

                        struct appdata
                        {
                                float4 vertex : POSITION;
                                float2 uv : TEXCOORD0;
                        };

                        struct v2f
                        {
                                float2 uv : TEXCOORD0;
                                UNITY_FOG_COORDS(1)
                                float4 vertex : SV_POSITION;
                        };

                        float _Transparency;
                        float4 _TintColor;

                        sampler2D _MainTex;
                        float4 _MainTex_ST;
                       

                        v2f vert (appdata v)
                        {
                                //v2f o;
                                //o.vertex = UnityObjectToClipPos(v.vertex);
                                //o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                                //UNITY_TRANSFER_FOG(o,o.vertex);
                                //return o;

                                v2f o;
                                float4 ori = mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1));
                                float4 vt = v.vertex;
                                vt.y = vt.z;
                                vt.z = 0;
                                vt.xyz += ori.xyz;//result is vt.z==ori.z ,so the distance to camera keeped ,and screen size keeped
                                o.vertex = mul(UNITY_MATRIX_P, vt);

                                o.uv = v.uv;
                                return o;
                        }
                        /**/
                        fixed4 frag (v2f i) : SV_Target
                        {
                                // sample the texture
                                fixed4 col = tex2D(_MainTex, i.uv) + _TintColor;
               
                                //if ((col.r > 200 )|| (col.g > 200) || (col.b > 200))
                                //col.a = _Transparency;
                               
                                // apply fog
                                UNITY_APPLY_FOG(i.fogCoord, col);
                                return col;
                        }
                        ENDCG
                }
        }
}
 


Этот код работает в Unlit шейдере,а в Standard Surface нет. Объект начинает неправильно вращаться. Помогите пожалуйста советом, где копать. Добавил тэг "DisableBatching"="True" - не помогло(

Код для Standard Surface в предыдущем посте.
ladder
UNец
 
Сообщения: 5
Зарегистрирован: 14 янв 2018, 11:49

Re: Standard Surface Shader - Billboard

Сообщение Turic 12 сен 2018, 23:29

простите за некропостинг, вроде по теме и вдруг кому будет полезно

Синтаксис:
Используется glsl
Shader "Custom/Feral" {

    Properties{
        _Color("Color", Color) = (1,1,1,1)
        _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
        _MainTex("Albedo Map", 2D) = "white" {}
                _BumpMap("Normal Map", 2D) = "bump" {}
                _EmissionMap("Emission Map", 2D) = "white" {}
                _EmissionColor("Emission Color", Color) = (0,0,0)
        _UpVector("Up Vector (XYZ)", Vector) = (0,1,0,0)
        }
        SubShader
                {
                        Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "DisableBatching" = "True"}



                        Name "FrontPass"
                        LOD 500
                        Cull Off
                        CGPROGRAM
                        #pragma target 3.0
                        #pragma surface surf SimpleLambert alphatest:_Cutoff vertex:vert addshadow

                        half4 _Color;
                        sampler2D _MainTex;
                        sampler2D _BumpMap;
                        sampler2D _EmissionMap;
                        half4 _EmissionColor;
                        float3 _UpVector;

                        struct Input {
                                float2 uv_MainTex;
                                float2 uv_BumpMap;
                                float2 uv_EmissionMap;
                        };

                        void vert(inout appdata_full v, out Input o)
                        {
                                UNITY_INITIALIZE_OUTPUT(Input, o);

                                // get the camera basis vectors
                                float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
                                float3 up = normalize(UNITY_MATRIX_V._m10_m11_m12);
                                float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);


                                // rotate to face camera
                                float4x4 rotationMatrix = float4x4(right, 0, up, 0, forward, 0, 0, 0, 0, 1);

                                //float offset = _Object2World._m22 / 2;
                                float offset = 0;
                                v.vertex = mul(v.vertex + float4(0, offset, 0, 0), rotationMatrix) + float4(0, -offset, 0, 0);
                                v.normal = mul(v.normal, rotationMatrix);
                        }


                        half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten) {
                                half4 c;
                                c.rgb = s.Albedo * _LightColor0.rgb * (atten);
                                c.a = s.Alpha;
                                return c;
                        }


                        void surf(Input IN, inout SurfaceOutput o)
                        {
                                half4 albedo = tex2D(_MainTex, IN.uv_MainTex) * _Color;
                                half3 emission = tex2D(_EmissionMap, IN.uv_EmissionMap).rgb * _EmissionColor;
                                o.Albedo = albedo.rgb - emission; // Emission cancels out other lights
                                o.Alpha = albedo.a;
                                o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
                                o.Emission = emission;
                                //o.Metallic = 0;
                        }
                        ENDCG
                }
               
        FallBack "Standard"
}
 
Аватара пользователя
Turic
UNец
 
Сообщения: 14
Зарегистрирован: 17 фев 2012, 14:48


Вернуться в Shader Lab

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2