|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
inline void CalculateNormal(half3 normalMap, LightweightVertexOutput i, out half3 normal) |
|
|
|
{ |
|
|
|
#if _NORMALMAP |
|
|
|
normal = normalize(half3(dot(normalMap, i.tangentToWorld0), dot(normalMap, i.tangentToWorld1), dot(normalMap, i.tangentToWorld2))); |
|
|
|
#else |
|
|
|
normal = normalize(i.normal); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
half4 OutputColor(half3 color, half alpha) |
|
|
|
{ |
|
|
|
#if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON) |
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
void Vertex(inout VertexInput v); |
|
|
|
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|
|
|
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|
|
|
UNITY_SETUP_INSTANCE_ID(v); |
|
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|
|
|
UNITY_SETUP_INSTANCE_ID(v); |
|
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|
|
|
|
|
|
|
o.normal = normalize(UnityObjectToWorldNormal(v.normal)); |
|
|
|
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex); |
|
|
|
o.meshUV0.xy = TRANSFORM_TEX(v.texcoord0, _MainTex); |
|
|
|
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw; |
|
|
|
o.meshUV0.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw; |
|
|
|
o.hpos = UnityObjectToClipPos(v.vertex); |
|
|
|
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; |
|
|
|
o.posWS.xyz = worldPos; |
|
|
|
|
|
|
|
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - worldPos); |
|
|
|
half3 normal = normalize(UnityObjectToWorldNormal(v.normal)); |
|
|
|
//${ VertexShaderBody } |
|
|
|
o.tangent = normalize(UnityObjectToWorldDir(v.tangent)); |
|
|
|
o.binormal = cross(o.normal, o.tangent) * v.tangent.w; |
|
|
|
//End VertexShaderBody |
|
|
|
#if _NORMALMAP |
|
|
|
half sign = v.tangent.w * unity_WorldTransformParams.w; |
|
|
|
half3 tangent = normalize(UnityObjectToWorldDir(v.tangent)); |
|
|
|
half3 binormal = cross(normal, tangent) * v.tangent.w; |
|
|
|
o.hpos = UnityObjectToClipPos(v.vertex); |
|
|
|
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; |
|
|
|
o.posWS.xyz = worldPos; |
|
|
|
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - worldPos); |
|
|
|
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code |
|
|
|
o.tangentToWorld0 = half3(tangent.x, binormal.x, normal.x); |
|
|
|
o.tangentToWorld1 = half3(tangent.y, binormal.y, normal.y); |
|
|
|
o.tangentToWorld2 = half3(tangent.z, binormal.z, normal.z); |
|
|
|
#else |
|
|
|
o.normal = normal; |
|
|
|
#endif |
|
|
|
|
|
|
|
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU |
|
|
|
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU |
|
|
|
half3 diffuse = half3(1.0, 1.0, 1.0); |
|
|
|
// pixel lights shaded = min(pixelLights, perObjectLights) |
|
|
|
// vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded |
|
|
|
// Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights) |
|
|
|
int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y); |
|
|
|
int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y); |
|
|
|
for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter) |
|
|
|
{ |
|
|
|
int lightIndex = unity_4LightIndices0[lightIter]; |
|
|
|
LightInput lightInput; |
|
|
|
INITIALIZE_LIGHT(lightInput, lightIndex); |
|
|
|
half3 diffuse = half3(1.0, 1.0, 1.0); |
|
|
|
// pixel lights shaded = min(pixelLights, perObjectLights) |
|
|
|
// vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded |
|
|
|
// Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights) |
|
|
|
int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y); |
|
|
|
int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y); |
|
|
|
for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter) |
|
|
|
{ |
|
|
|
int lightIndex = unity_4LightIndices0[lightIter]; |
|
|
|
LightInput lightInput; |
|
|
|
INITIALIZE_LIGHT(lightInput, lightIndex); |
|
|
|
half3 lightDirection; |
|
|
|
half atten = ComputeLightAttenuationVertex(lightInput, normal, worldPos, lightDirection); |
|
|
|
o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, normal, atten); |
|
|
|
} |
|
|
|
half3 lightDirection; |
|
|
|
half atten = ComputeLightAttenuationVertex(lightInput, o.normal, worldPos, lightDirection); |
|
|
|
o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, normal, atten); |
|
|
|
} |
|
|
|
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1))); |
|
|
|
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(o.normal, 1))); |
|
|
|
UNITY_TRANSFER_FOG(o, o.hpos); |
|
|
|
return o; |
|
|
|
UNITY_TRANSFER_FOG(o, o.hpos); |
|
|
|
return o; |
|
|
|
} |
|
|
|
|
|
|
|
#endif |