您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

82 行
2.6 KiB

#ifndef UNITY_STANDARD_META_INCLUDED
#define UNITY_STANDARD_META_INCLUDED
// Functionality for Standard shader "meta" pass
// (extracts albedo/emission for lightmapper etc.)
// define meta pass before including other files; they have conditions
// on that in some places
#define UNITY_PASS_META 1
#include "UnityCG.cginc"
#include "UnityMetaPass.cginc"
#include "UnityLayeredPhotogrammetryCore.cginc"
#include "UnityLayeredPhotogrammetryInput.cginc"
struct v2f_meta
{
float4 uv : TEXCOORD0;
float4 uv2 : TEXCOORD1;
half4 tangentToWorldAndPackedData[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax or worldPos]
float4 pos : SV_POSITION;
float4 color : COLOR;
#if UNITY_REQUIRE_FRAG_WORLDPOS && !UNITY_PACK_WORLDPOS_WITH_TANGENT
float3 posWorld : TEXCOORD8;
#endif
};
v2f_meta vert_meta (VertexInput v)
{
v2f_meta o;
o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST);
o.uv = TexCoords(v);
o.uv2 = float4(v.uv2, v.uv3); // JIG CHECK UV SCALE
o.color = v.color;
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
#if UNITY_REQUIRE_FRAG_WORLDPOS
#if UNITY_PACK_WORLDPOS_WITH_TANGENT
o.tangentToWorldAndPackedData[0].w = posWorld.x;
o.tangentToWorldAndPackedData[1].w = posWorld.y;
o.tangentToWorldAndPackedData[2].w = posWorld.z;
#else
o.posWorld = posWorld.xyz;
#endif
#endif
return o;
}
// Albedo for lightmapping should basically be diffuse color.
// But rough metals (black diffuse) still scatter quite a lot of light around, so
// we want to take some of that into account too.
half3 UnityLightmappingAlbedo (half3 diffuse, half3 specular, half smoothness)
{
half roughness = SmoothnessToRoughness(smoothness);
half3 res = diffuse;
res += specular * roughness * 0.5;
return res;
}
float4 frag_meta (v2f_meta i) : SV_Target
{
// we're interested in diffuse & specular colors,
// and surface roughness to produce final albedo.
FragmentCommonData data = FragmentSetupLayeredPhotogrammetry(i.pos, i.uv, i.uv2, i.color, float3(0.0, 0.0, 0.0), i.tangentToWorldAndPackedData, IN_WORLDPOS(i));
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
#if defined(EDITOR_VISUALIZATION)
o.Albedo = data.diffColor;
#else
o.Albedo = UnityLightmappingAlbedo (data.diffColor, data.specColor, data.smoothness);
#endif
o.SpecularColor = data.specColor;
o.Emission = float3(0.0, 0.0, 0.0);// Emission(i.uv.xy);
return UnityMetaFragment(o);
}
#endif // UNITY_STANDARD_META_INCLUDED