参考之前搜集到的资料
Unity Shader Graph使用多象限[UDIM]纹理贴图_嫣兰飞雪的博客-CSDN博客_unity多象限uv
具体的代码优化没有,看哪位大佬能帮忙进行一下优化。
Shader "DuoUV"
{
Properties
{
_EdgeLength ( "Edge length", Range( 2, 50 ) ) = 15
_Color("Color", Color) = (1,1,1,0)
_FaceTex1001("FaceTex1001", 2D) = "white" {}
_FaceAoTex1001("FaceAoTex1001", 2D) = "white" {}
_FaceNormalTex1001("FaceNormalTex1001", 2D) = "bump" {}
_BodyTex1002("BodyTex1002", 2D) = "white" {}
_BodyAoTex1002("BodyAoTex1002", 2D) = "white" {}
_BodyNormalTex1002("BodyNormalTex1002", 2D) = "bump" {}
_ArmTex1003("ArmTex1003", 2D) = "white" {}
_ArmAoTex1003("ArmAoTex1003", 2D) = "white" {}
_ArmNormalTex1003("ArmNormalTex1003", 2D) = "bump" {}
_LegAoTex1004("LegAoTex1004", 2D) = "white" {}
_LegTex1004("LegTex1004", 2D) = "white" {}
_LegNOrmalTex1004("LegNOrmalTex1004", 2D) = "bump" {}
_NormalIntesity("NormalIntesity", Range( 0 , 1)) = 0
_Metallic("Metallic", Range( 0 , 1)) = 0
_Smoothness("Smoothness", Range( 0 , 1)) = 0
_AOIntesity("AOIntesity", Float) = 0
[HideInInspector] _texcoord( "", 2D ) = "white" {}
[HideInInspector] __dirty( "", Int ) = 1
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" }
Cull Back
CGINCLUDE
#include "UnityPBSLighting.cginc"
#include "UnityStandardUtils.cginc"
#include "Tessellation.cginc"
#include "Lighting.cginc"
#pragma target 4.6
#ifdef UNITY_PASS_SHADOWCASTER
#undef INTERNAL_DATA
#undef WorldReflectionVector
#undef WorldNormalVector
#define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
#define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
#define WorldNormalVector(data,normal) half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
#endif
struct Input
{
float3 worldNormal;
INTERNAL_DATA
float2 uv_texcoord;
};
struct SurfaceOutputCustomLightingCustom
{
half3 Albedo;
half3 Normal;
half3 Emission;
half Metallic;
half Smoothness;
half Occlusion;
half Alpha;
Input SurfInput;
UnityGIInput GIData;
};
uniform sampler2D _FaceTex1001;
//uniform float4 _FaceTex1001_ST;
uniform sampler2D _BodyTex1002;
//uniform float4 _BodyTex1002_ST;
uniform sampler2D _ArmTex1003;
uniform float4 _ArmTex1003_ST;
uniform sampler2D _LegTex1004;
uniform float4 _LegTex1004_ST;
uniform float4 _Color;
uniform sampler2D _FaceNormalTex1001;
uniform float4 _FaceNormalTex1001_ST;
uniform float _NormalIntesity;
uniform sampler2D _BodyNormalTex1002;
uniform float4 _BodyNormalTex1002_ST;
uniform sampler2D _ArmNormalTex1003;
uniform float4 _ArmNormalTex1003_ST;
uniform sampler2D _LegNOrmalTex1004;
uniform float4 _LegNOrmalTex1004_ST;
uniform float _Metallic;
uniform float _Smoothness;
uniform sampler2D _FaceAoTex1001;
uniform float4 _FaceAoTex1001_ST;
uniform sampler2D _BodyAoTex1002;
uniform float4 _BodyAoTex1002_ST;
uniform sampler2D _ArmAoTex1003;
uniform float4 _ArmAoTex1003_ST;
uniform sampler2D _LegAoTex1004;
uniform float4 _LegAoTex1004_ST;
uniform float _AOIntesity;
uniform float _EdgeLength;
float4 tessFunction( appdata_full v0, appdata_full v1, appdata_full v2 )
{
return UnityEdgeLengthBasedTess (v0.vertex, v1.vertex, v2.vertex, _EdgeLength);
}
void vertexDataFunc( inout appdata_full v )
{
}
inline half4 LightingStandardCustomLighting( inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi )
{
UnityGIInput data = s.GIData;
Input i = s.SurfInput;
half4 c = 0;
SurfaceOutputStandard s120 = (SurfaceOutputStandard ) 0;
float2 uv_FaceTex1001 = i.uv_texcoord ;
float2 uv_BodyTex1002 = i.uv_texcoord ;
float UV78 = i.uv_texcoord.x;
float smoothstepResult53 = smoothstep( 1.0 , 1.0 , UV78);
float4 lerpResult56 = lerp( tex2D( _FaceTex1001, uv_FaceTex1001 ) , tex2D( _BodyTex1002, uv_BodyTex1002 ) , smoothstepResult53);
float2 uv_ArmTex1003 = i.uv_texcoord * _ArmTex1003_ST.xy + _ArmTex1003_ST.zw;
float smoothstepResult35 = smoothstep( 2.0 , 2.0 , UV78);
float4 lerpResult54 = lerp( lerpResult56 , tex2D( _ArmTex1003, uv_ArmTex1003 ) , smoothstepResult35);
float2 uv_LegTex1004 = i.uv_texcoord * _LegTex1004_ST.xy + _LegTex1004_ST.zw;
float smoothstepResult84 = smoothstep( 3.0 , 3.0 , UV78);
float4 lerpResult87 = lerp( lerpResult54 , tex2D( _LegTex1004, uv_LegTex1004 ) , smoothstepResult84);
float4 Albedo126 = ( lerpResult87 * _Color );
s120.Albedo = Albedo126.rgb;
float2 uv_FaceNormalTex1001 = i.uv_texcoord * _FaceNormalTex1001_ST.xy + _FaceNormalTex1001_ST.zw;
float NormalIntesity159 = _NormalIntesity;
float2 uv_BodyNormalTex1002 = i.uv_texcoord * _BodyNormalTex1002_ST.xy + _BodyNormalTex1002_ST.zw;
float smoothstepResult138 = smoothstep( 1.0 , 1.0 , UV78);
float3 lerpResult145 = lerp( UnpackScaleNormal( tex2D( _FaceNormalTex1001, uv_FaceNormalTex1001 ), NormalIntesity159 ) , UnpackScaleNormal( tex2D( _BodyNormalTex1002, uv_BodyNormalTex1002 ), NormalIntesity159 ) , smoothstepResult138);
float2 uv_ArmNormalTex1003 = i.uv_texcoord * _ArmNormalTex1003_ST.xy + _ArmNormalTex1003_ST.zw;
float smoothstepResult146 = smoothstep( 2.0 , 2.0 , UV78);
float3 lerpResult150 = lerp( lerpResult145 , UnpackScaleNormal( tex2D( _ArmNormalTex1003, uv_ArmNormalTex1003 ), NormalIntesity159 ) , smoothstepResult146);
float2 uv_LegNOrmalTex1004 = i.uv_texcoord * _LegNOrmalTex1004_ST.xy + _LegNOrmalTex1004_ST.zw;
float smoothstepResult151 = smoothstep( 3.0 , 3.0 , UV78);
float3 lerpResult154 = lerp( lerpResult150 , UnpackScaleNormal( tex2D( _LegNOrmalTex1004, uv_LegNOrmalTex1004 ), NormalIntesity159 ) , smoothstepResult151);
float3 Normal158 = lerpResult154;
s120.Normal = WorldNormalVector( i , Normal158 );
s120.Emission = float3( 0,0,0 );
s120.Metallic = _Metallic;
s120.Smoothness = _Smoothness;
float2 uv_FaceAoTex1001 = i.uv_texcoord * _FaceAoTex1001_ST.xy + _FaceAoTex1001_ST.zw;
float2 uv_BodyAoTex1002 = i.uv_texcoord * _BodyAoTex1002_ST.xy + _BodyAoTex1002_ST.zw;
float smoothstepResult203 = smoothstep( 1.0 , 1.0 , UV78);
float lerpResult207 = lerp( tex2D( _FaceAoTex1001, uv_FaceAoTex1001 ).r , tex2D( _BodyAoTex1002, uv_BodyAoTex1002 ).r , smoothstepResult203);
float2 uv_ArmAoTex1003 = i.uv_texcoord * _ArmAoTex1003_ST.xy + _ArmAoTex1003_ST.zw;
float smoothstepResult205 = smoothstep( 2.0 , 2.0 , UV78);
float lerpResult211 = lerp( lerpResult207 , tex2D( _ArmAoTex1003, uv_ArmAoTex1003 ).r , smoothstepResult205);
float2 uv_LegAoTex1004 = i.uv_texcoord * _LegAoTex1004_ST.xy + _LegAoTex1004_ST.zw;
float smoothstepResult210 = smoothstep( 3.0 , 3.0 , UV78);
float lerpResult212 = lerp( lerpResult211 , tex2D( _LegAoTex1004, uv_LegAoTex1004 ).r , smoothstepResult210);
float Ao215 = pow( lerpResult212 , _AOIntesity );
s120.Occlusion = Ao215;
data.light = gi.light;
UnityGI gi120 = gi;
#ifdef UNITY_PASS_FORWARDBASE
Unity_GlossyEnvironmentData g120 = UnityGlossyEnvironmentSetup( s120.Smoothness, data.worldViewDir, s120.Normal, float3(0,0,0));
gi120 = UnityGlobalIllumination( data, s120.Occlusion, s120.Normal, g120 );
#endif
float3 surfResult120 = LightingStandard ( s120, viewDir, gi120 ).rgb;
surfResult120 += s120.Emission;
#ifdef UNITY_PASS_FORWARDADD//120
surfResult120 -= s120.Emission;
#endif//120
c.rgb = surfResult120;
c.a = 1;
return c;
}
inline void LightingStandardCustomLighting_GI( inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi )
{
s.GIData = data;
}
void surf( Input i , inout SurfaceOutputCustomLightingCustom o )
{
o.SurfInput = i;
o.Normal = float3(0,0,1);
}
ENDCG
CGPROGRAM
#pragma surface surf StandardCustomLighting keepalpha fullforwardshadows vertex:vertexDataFunc tessellate:tessFunction
ENDCG
Pass
{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
ZWrite On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 4.6
#pragma multi_compile_shadowcaster
#pragma multi_compile UNITY_PASS_SHADOWCASTER
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
#include "HLSLSupport.cginc"
#if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
#define CAN_SKIP_VPOS
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
struct v2f
{
V2F_SHADOW_CASTER;
float2 customPack1 : TEXCOORD1;
float4 tSpace0 : TEXCOORD2;
float4 tSpace1 : TEXCOORD3;
float4 tSpace2 : TEXCOORD4;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert( appdata_full v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID( v );
UNITY_INITIALIZE_OUTPUT( v2f, o );
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
UNITY_TRANSFER_INSTANCE_ID( v, o );
Input customInputData;
vertexDataFunc( v );
float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
half3 worldNormal = UnityObjectToWorldNormal( v.normal );
half3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
half3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
o.customPack1.xy = customInputData.uv_texcoord;
o.customPack1.xy = v.texcoord;
TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
return o;
}
half4 frag( v2f IN
#if !defined( CAN_SKIP_VPOS )
, UNITY_VPOS_TYPE vpos : VPOS
#endif
) : SV_Target
{
UNITY_SETUP_INSTANCE_ID( IN );
Input surfIN;
UNITY_INITIALIZE_OUTPUT( Input, surfIN );
surfIN.uv_texcoord = IN.customPack1.xy;
float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
SurfaceOutputCustomLightingCustom o;
UNITY_INITIALIZE_OUTPUT( SurfaceOutputCustomLightingCustom, o )
surf( surfIN, o );
#if defined( CAN_SKIP_VPOS )
float2 vpos = IN.pos;
#endif
SHADOW_CASTER_FRAGMENT( IN )
}
ENDCG
}
}
Fallback "Diffuse"
CustomEditor "ASEMaterialInspector"
}