找回密码
 注册帐号

扫一扫,访问微社区

着色器 求会用ShadeGraph帮我转一下材质

1
回复
155
查看
[ 复制链接 ]
3偶尔光临
212/300
排名
18293
昨日变化

7

主题

65

帖子

212

积分

Rank: 3Rank: 3Rank: 3

UID
259178
好友
0
蛮牛币
10
威望
0
注册时间
2017-12-12
在线时间
107 小时
最后登录
2019-9-12
2019-8-27 14:50:27 显示全部楼层 阅读模式
15蛮牛币
因为需要在unityHDP高清渲染管道下使用一个插件,但是这个插件里边有自定义的shader,除了unity自带的shader可以一键转换,自定义shader是真的并不会转,求帮忙!!!这个是VRPanorama/FadeVR:
[C#] 纯文本查看 复制代码
Shader "VRPanorama/FadeVR" {
    Properties {
        _Main ("Main", 2D) = "white" {}
        _FadeTex ("FadeTex", 2D) = "white" {}
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
        _U ("U", Float ) = 512
        _V ("V", Float ) = 512
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Overlay"
        }
        Pass {
            Name "ForwardBase"
            Tags {
                "LightMode"="ForwardBase"
            }
           // Blend SrcAlpha OneMinusSrcAlpha
         	Blend SrcAlpha OneMinusSrcAlpha
            ZTest LEqual
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase
            #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0
            // float4 unity_LightmapST;
            #ifdef DYNAMICLIGHTMAP_ON
                // float4 unity_DynamicLightmapST;
            #endif
            uniform sampler2D _Main; uniform float4 _Main_ST;
            uniform sampler2D _FadeTex; uniform float4 _FadeTex_ST;
            uniform float _U;
            uniform float _V;
            half4 _Main_TexelSize;
            
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                #ifndef LIGHTMAP_OFF
                    float4 uvLM : TEXCOORD1;
                #else
                    float3 shLight : TEXCOORD1;
                #endif
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.pos = UnityObjectToClipPos(v.vertex);
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
/////// Vectors:
////// Lighting:
////// Emissive:
				float _TXWidth = (1.0f / _U);
				float _TXHeight = (1.0f / _V);




 				float4 c1 = tex2D(_Main, i.uv0 + float2(0.0f, 0.0f));
				float4 c2 = tex2D(_Main, i.uv0 + float2(_TXWidth, 0.0f));
				float4 c3 = tex2D(_Main, i.uv0 + float2(-_TXWidth, _TXHeight));
				float4 c4 = tex2D(_Main, i.uv0 + float2(-_TXWidth, 0.0f));
				float4 c5 = tex2D(_Main, i.uv0 + float2(-_TXWidth, -_TXHeight));
				
				
				float4 d2 = tex2D(_Main, i.uv0 + float2(0.0f, -_TXHeight * 2.0f));
				float4 d3 = tex2D(_Main, i.uv0 + float2(0.0f, _TXHeight * 2.0f));
				float4 d4 = tex2D(_Main, i.uv0 + float2(-_TXWidth * 2.0f, 0.0f));
				float4 d5 = tex2D(_Main, i.uv0 + float2(_TXWidth * 2.0f, 0.0f));
                
                float4 _Col = (c1 + c2 + c3 + c4 + c5 + d2 + d3 + d4 + d5) / 9.0f;

//                half3 magic = float3(0.06711056, 0.00583715, 52.9829189);
//   				half gradient = frac(magic.z * frac(dot(i.uv0 / _Main_TexelSize/0.2, magic.xy))) / 255.0;
//    			_Col.rgb -= gradient.xxx;


                float3 emissive = _Col.rgb;
                float3 finalColor = emissive;
                float4 _FadeTex_var = tex2D(_FadeTex,TRANSFORM_TEX(i.uv0, _FadeTex));
                return fixed4(finalColor,_FadeTex_var.r * _Col.a);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}


这个是VRPanorama/unwrapShader:
[C#] 纯文本查看 复制代码
Shader "VRPanorama/unwrapShader" {
    Properties {
        _Cube ("Cube", Cube) = "_Skybox" {}
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        Pass {
            Name "ForwardBase"
            Tags {
                "LightMode"="ForwardBase"
            }
            
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragma multi_compile_fog
            #pragma exclude_renderers gles xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0
            // float4 unity_LightmapST;
            #ifdef DYNAMICLIGHTMAP_ON
                // float4 unity_DynamicLightmapST;
            #endif
            uniform samplerCUBE _Cube;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float3 normalDir : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                #ifndef LIGHTMAP_OFF
                    float4 uvLM : TEXCOORD2;
                #else
                    float3 shLight : TEXCOORD2;
                #endif
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.normalDir = mul(unity_ObjectToWorld, float4(v.normal,0)).xyz;
                o.pos = UnityObjectToClipPos(v.vertex);
                UNITY_TRANSFER_FOG(o,o.pos);
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
/////// Vectors:
                float3 normalDirection = i.normalDir;
////// Lighting:
////// Emissive:
                float4 _Cube_var = texCUBE(_Cube,(-1*i.normalDir));
                float3 emissive = _Cube_var.rgb;
                float3 finalColor = emissive;
                fixed4 finalRGBA = fixed4(finalColor,1);
                UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
                return finalRGBA;
            }
            ENDCG
        }
    }
    FallBack "Diffuse"

}


还有这个VRPanorama/FadeVRBD
[C#] 纯文本查看 复制代码
Shader "VRPanorama/FadeVRBD" {
    Properties {
        _Main ("Main", 2D) = "white" {}
        _MainR ("MainR", 2D) = "white" {}
        _MainX ("MainX", 2D) = "white" {}
        _MainRX ("MainRX", 2D) = "white" {}
        _FadeTex ("FadeTex", 2D) = "white" {}
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
        _U ("U", Float ) = 512
        _V ("V", Float ) = 512
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Overlay"
        }
        Pass {
            Name "ForwardBase"
            Tags {
                "LightMode"="ForwardBase"
            }
            Blend SrcAlpha OneMinusSrcAlpha
            ZTest Always
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase
            #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0
            // float4 unity_LightmapST;
            #ifdef DYNAMICLIGHTMAP_ON
                // float4 unity_DynamicLightmapST;
            #endif
            uniform sampler2D _Main; uniform sampler2D _MainR; uniform sampler2D _MainX; uniform sampler2D _MainRX; uniform float4 _Main_ST;
            uniform sampler2D _FadeTex; uniform float4 _FadeTex_ST;
            uniform float _U; uniform float _V;  half4 _Main_TexelSize;
            
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                #ifndef LIGHTMAP_OFF
                    float4 uvLM : TEXCOORD1;
                #else
                    float3 shLight : TEXCOORD1;
                #endif
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.pos = UnityObjectToClipPos(v.vertex);
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
/////// Vectors:
////// Lighting:
////// Emissive:
				float _TXWidth = (1.0f / _U);
				float _TXHeight = (1.0f / _V);


              
                float4 c1 = tex2D(_Main, i.uv0);
				float4 c2 = tex2D(_Main, i.uv0 + float2(_TXWidth, 0.0f));
				float4 c3 = tex2D(_Main, i.uv0 + float2(0.0f, _TXHeight));
				float4 c4 = tex2D(_Main, i.uv0 + float2(-_TXWidth , 0.0f));
				float4 c5 = tex2D(_Main, i.uv0 + float2(0.0f , -_TXHeight));
				
				float4 r1 = tex2D(_MainR, i.uv0);
				float4 r2 = tex2D(_MainR, i.uv0 + float2(_TXWidth, 0.0f));
				float4 r3 = tex2D(_MainR, i.uv0 + float2(0.0f, _TXHeight));
				float4 r4 = tex2D(_MainR, i.uv0 + float2(-_TXWidth , 0.0f));
				float4 r5 = tex2D(_MainR, i.uv0 + float2(0.0f , -_TXHeight));
				
				float4 cx1 = tex2D(_MainX, i.uv0);
				float4 cx2 = tex2D(_MainX, i.uv0 + float2(_TXWidth, 0.0f));
				float4 cx3 = tex2D(_MainX, i.uv0 + float2(0.0f, _TXHeight));
				float4 cx4 = tex2D(_MainX, i.uv0 + float2(-_TXWidth , 0.0f));
				float4 cx5 = tex2D(_MainX, i.uv0 + float2(0.0f , -_TXHeight));
				
				float4 rx1 = tex2D(_MainRX, i.uv0);
				float4 rx2 = tex2D(_MainRX, i.uv0 + float2(_TXWidth, 0.0f));
				float4 rx3 = tex2D(_MainRX, i.uv0 + float2(0.0f, _TXHeight));
				float4 rx4 = tex2D(_MainRX, i.uv0 + float2(-_TXWidth , 0.0f));
				float4 rx5 = tex2D(_MainRX, i.uv0 + float2(0.0f , -_TXHeight));
				
                
                float4 _Col = (c1 + c2 + c3 + c4 + c5) / 5.0f;
                float4 _Colr = (r1 + r2 + r3 + r4 + r5) / 5.0f;
                
                float4 _Colx = (cx1 + cx2 + cx3 + cx4 + cx5) / 5.0f;
                float4 _Colrx = (rx1 + rx2 + rx3 + rx4 + rx5) / 5.0f;
                
                float4 _FadeTex_var = tex2D(_FadeTex,TRANSFORM_TEX(i.uv0, _FadeTex));
                float3 emissive = lerp(_Col.rgb, _Colr.rgb, _FadeTex_var.g);
                float3 emissive2 = lerp(_Colx.rgb, _Colrx.rgb, _FadeTex_var.b);
                float3 emissivex = lerp(emissive.rgb, emissive2.rgb, _FadeTex_var.a);
                float3 finalColor = emissivex;

//                half3 magic = float3(0.06711056, 0.00583715, 52.9829189);
//   				half gradient = frac(magic.z * frac(dot(i.uv0 / _Main_TexelSize , magic.xy))) / 255.0;
//    			finalColor.rgb -= gradient.xxx;


                return fixed4(finalColor, _FadeTex_var.r * _Col.a);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}

捕获.PNG
捕获.PNG
捕获.PNG
回复

使用道具 举报

0

主题

19

帖子

19

积分

Rank: 1

UID
331756
好友
0
蛮牛币
2
威望
0
注册时间
2019-9-15
在线时间
0 小时
最后登录
2019-9-15
15 小时前 显示全部楼层
非常不错。。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册帐号

本版积分规则