|
|
|
|
|
|
// Vertex and Fragment functions // |
|
|
|
/////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
// Vertex: Used for Standard and StandardSimpleLighting shaders |
|
|
|
// Used in Standard (Physically Based) shader |
|
|
|
LightweightVertexOutput LitPassVertex(LightweightVertexInput v) |
|
|
|
{ |
|
|
|
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|
|
|
|
|
|
o.uv = TransformMainTextureCoord(v.texcoord); |
|
|
|
|
|
|
|
o.posWSShininess.xyz = TransformObjectToWorld(v.vertex.xyz); |
|
|
|
o.posWSShininess.w = _Shininess * 128.0; |
|
|
|
o.clipPos = TransformWorldToHClip(o.posWSShininess.xyz); |
|
|
|
|
|
|
|
half3 viewDir = VertexViewDirWS(GetCameraPositionWS() - o.posWSShininess.xyz); |
|
|
|
|
|
|
return o; |
|
|
|
} |
|
|
|
|
|
|
|
// Used for Standard shader |
|
|
|
// Used in Standard (Physically Based) shader |
|
|
|
half4 LitPassFragment(LightweightVertexOutput IN) : SV_Target |
|
|
|
{ |
|
|
|
UNITY_SETUP_INSTANCE_ID(IN); |
|
|
|
|
|
|
|
|
|
|
ApplyFog(color.rgb, inputData.fogCoord); |
|
|
|
return color; |
|
|
|
} |
|
|
|
|
|
|
|
// Used in Standard (Simple Lighting) shader |
|
|
|
// TODO: we only need to specialise this because of _Shininess prop |
|
|
|
// Once we refactor SimpleLighting shader we will be able to share vertex |
|
|
|
// between PBS and Simple |
|
|
|
LightweightVertexOutput LitPassVertexSimple(LightweightVertexInput v) |
|
|
|
{ |
|
|
|
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|
|
|
|
|
|
|
UNITY_SETUP_INSTANCE_ID(v); |
|
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o); |
|
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|
|
|
|
|
|
|
o.uv = TransformMainTextureCoord(v.texcoord); |
|
|
|
|
|
|
|
o.posWSShininess.xyz = TransformObjectToWorld(v.vertex.xyz); |
|
|
|
o.posWSShininess.w = _Shininess * 128.0; |
|
|
|
o.clipPos = TransformWorldToHClip(o.posWSShininess.xyz); |
|
|
|
|
|
|
|
half3 viewDir = VertexViewDirWS(GetCameraPositionWS() - o.posWSShininess.xyz); |
|
|
|
|
|
|
|
#ifdef _NORMALMAP |
|
|
|
o.normal.w = viewDir.x; |
|
|
|
o.tangent.w = viewDir.y; |
|
|
|
o.binormal.w = viewDir.z; |
|
|
|
#else |
|
|
|
o.viewDir = viewDir; |
|
|
|
#endif |
|
|
|
|
|
|
|
// initializes o.normal and if _NORMALMAP also o.tangent and o.binormal |
|
|
|
OUTPUT_NORMAL(v, o); |
|
|
|
|
|
|
|
// We either sample GI from lightmap or SH. |
|
|
|
// Lightmap UV and vertex SH coefficients use the same interpolator ("float2 lightmapUV" for lightmap or "half3 vertexSH" for SH) |
|
|
|
// see DECLARE_LIGHTMAP_OR_SH macro. |
|
|
|
// The following funcions initialize the correct variable with correct data |
|
|
|
OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUV); |
|
|
|
OUTPUT_SH(o.normal.xyz, o.vertexSH); |
|
|
|
|
|
|
|
half3 vertexLight = VertexLighting(o.posWSShininess.xyz, o.normal.xyz); |
|
|
|
half fogFactor = ComputeFogFactor(o.clipPos.z); |
|
|
|
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); |
|
|
|
|
|
|
|
#ifdef _SHADOWS_ENABLED |
|
|
|
#if SHADOWS_SCREEN |
|
|
|
o.shadowCoord = ComputeShadowCoord(o.clipPos); |
|
|
|
#else |
|
|
|
o.shadowCoord = TransformWorldToShadowCoord(o.posWSShininess.xyz); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
return o; |
|
|
|
} |
|
|
|
|
|
|
|
// Used for StandardSimpleLighting shader |
|
|
|