[unity] Shader cleanup: removed duplicate unused cginc files. See #1255.

This commit is contained in:
Harald Csaszar 2019-07-11 19:24:58 +02:00
parent 90444cc226
commit bf365a0dad
12 changed files with 0 additions and 1328 deletions

View File

@ -1,363 +0,0 @@
#ifndef SHADER_SHARED_INCLUDED
#define SHADER_SHARED_INCLUDED
#include "UnityCG.cginc"
////////////////////////////////////////
// Space functions
//
inline float4 calculateWorldPos(float4 vertex)
{
return mul(unity_ObjectToWorld, vertex);
}
inline float4 calculateLocalPos(float4 vertex)
{
return UnityObjectToClipPos(vertex);
}
inline half3 calculateWorldNormal(float3 normal)
{
return UnityObjectToWorldNormal(normal);
}
////////////////////////////////////////
// Maths functions
//
inline float dotClamped(float3 a, float3 b)
{
#if (SHADER_TARGET < 30 || defined(SHADER_API_PS3))
return saturate(dot(a, b));
#else
return max(0.0h, dot(a, b));
#endif
}
inline float oneDividedBy(float value)
{
//Catches NANs
float sign_value = sign(value);
float sign_value_squared = sign_value*sign_value;
return sign_value_squared / ( value + sign_value_squared - 1.0);
}
inline float4 quat_from_axis_angle(float3 axis, float angleRadians)
{
float4 qr;
float half_angle = (angleRadians * 0.5);
qr.x = axis.x * sin(half_angle);
qr.y = axis.y * sin(half_angle);
qr.z = axis.z * sin(half_angle);
qr.w = cos(half_angle);
return qr;
}
inline float3 rotate_vertex_position(float3 position, float3 axis, float angleRadians)
{
float4 q = quat_from_axis_angle(axis, angleRadians);
float3 v = position.xyz;
return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);
}
////////////////////////////////////////
// Normal map functions
//
#if defined(_NORMALMAP)
uniform sampler2D _BumpMap;
inline half3 calculateWorldTangent(float4 tangent)
{
return UnityObjectToWorldDir(tangent);
}
inline half3 calculateWorldBinormal(half3 normalWorld, half3 tangentWorld, float tangentW)
{
// For odd-negative scale transforms we need to flip the binormal
return cross(normalWorld, tangentWorld.xyz) * tangentW * unity_WorldTransformParams.w;
}
inline half3 calculateNormalFromBumpMap(float2 texUV, half3 tangentWorld, half3 binormalWorld, half3 normalWorld)
{
half3 localNormal = UnpackNormal(tex2D(_BumpMap, texUV));
half3x3 rotation = half3x3(tangentWorld, binormalWorld, normalWorld);
half3 normal = normalize(mul(localNormal, rotation));
return normal;
}
#endif // _NORMALMAP
////////////////////////////////////////
// Blending functions
//
inline fixed4 calculateLitPixel(fixed4 texureColor, fixed4 color, fixed3 lighting) : SV_Target
{
fixed4 finalPixel;
#if defined(_ALPHAPREMULTIPLY_ON)
//Pre multiplied alpha
finalPixel = texureColor * color;
finalPixel.rgb *= lighting * color.a;
#elif defined(_MULTIPLYBLEND)
//Multiply
finalPixel = color * texureColor;
finalPixel.rgb *= lighting;
finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a);
#elif defined(_MULTIPLYBLEND_X2)
//Multiply x2
finalPixel.rgb = texureColor.rgb * color.rgb * lighting * 2.0f;
finalPixel.a = color.a * texureColor.a;
finalPixel = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), finalPixel, finalPixel.a);
#elif defined(_ADDITIVEBLEND)
//Additive
finalPixel = texureColor * 2.0f * color;
finalPixel.rgb *= lighting * color.a;
#elif defined(_ADDITIVEBLEND_SOFT)
//Additive soft
finalPixel = texureColor * color;
finalPixel.rgb *= lighting * finalPixel.a;
#else
finalPixel.a = texureColor.a * color.a;
finalPixel.rgb = texureColor.rgb * color.rgb * (lighting * finalPixel.a);
#endif
return finalPixel;
}
inline fixed4 calculateLitPixel(fixed4 texureColor, fixed3 lighting) : SV_Target
{
fixed4 finalPixel;
#if defined(_ALPHAPREMULTIPLY_ON)
//Pre multiplied alpha
finalPixel = texureColor;
finalPixel.rgb *= lighting;
#elif defined(_MULTIPLYBLEND)
//Multiply
finalPixel = texureColor;
finalPixel.rgb *= lighting;
finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a);
#elif defined(_MULTIPLYBLEND_X2)
//Multiply x2
finalPixel.rgb = texureColor.rgb * lighting * 2.0f;
finalPixel.a = texureColor.a;
finalPixel = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), finalPixel, finalPixel.a);
#elif defined(_ADDITIVEBLEND)
//Additive
finalPixel = texureColor * 2.0f;
finalPixel.rgb *= lighting;
#elif defined(_ADDITIVEBLEND_SOFT)
//Additive soft
finalPixel = texureColor;
finalPixel.rgb *= lighting * finalPixel.a;
#else
finalPixel.a = texureColor.a;
finalPixel.rgb = texureColor.rgb * (lighting * finalPixel.a);
#endif
return finalPixel;
}
inline fixed4 calculateAdditiveLitPixel(fixed4 texureColor, fixed4 color, fixed3 lighting) : SV_Target
{
fixed4 finalPixel;
#if defined(_ALPHAPREMULTIPLY_ON)
//Pre multiplied alpha
finalPixel.rgb = texureColor.rgb * lighting * color.rgb * color.a;
finalPixel.a = 1.0;
#else
//All other alpha
finalPixel.rgb = (texureColor.rgb * lighting * color.rgb) * (texureColor.a * color.a);
finalPixel.a = 1.0;
#endif
return finalPixel;
}
inline fixed4 calculatePixel(fixed4 texureColor, fixed4 color) : SV_Target
{
fixed4 finalPixel;
#if defined(_ALPHAPREMULTIPLY_ON)
//Pre multiplied alpha
finalPixel = texureColor * color;
finalPixel.rgb *= color.a;
#elif defined(_MULTIPLYBLEND)
//Multiply
finalPixel = color * texureColor;
finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a);
#elif defined(_MULTIPLYBLEND_X2)
//Multiply x2
finalPixel.rgb = texureColor.rgb * color.rgb * 2.0f;
finalPixel.a = color.a * texureColor.a;
finalPixel = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), finalPixel, finalPixel.a);
#elif defined(_ADDITIVEBLEND)
//Additive
finalPixel = texureColor * 2.0f * color;
#elif defined(_ADDITIVEBLEND_SOFT)
//Additive soft
finalPixel = color * texureColor;
finalPixel.rgb *= finalPixel.a;
#else
//Standard alpha
finalPixel.a = texureColor.a * color.a;
finalPixel.rgb = (texureColor.rgb * color.rgb) * finalPixel.a;
#endif
return finalPixel;
}
inline fixed4 calculatePixel(fixed4 texureColor) : SV_Target
{
fixed4 finalPixel;
#if defined(_ALPHAPREMULTIPLY_ON)
//Pre multiplied alpha
finalPixel = texureColor;
#elif defined(_MULTIPLYBLEND)
//Multiply
finalPixel = texureColor;
finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a);
#elif defined(_MULTIPLYBLEND_X2)
//Multiply x2
finalPixel.rgb = texureColor.rgb * 2.0f;
finalPixel.a = texureColor.a;
finalPixel = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), finalPixel, finalPixel.a);
#elif defined(_ADDITIVEBLEND)
//Additive
finalPixel = texureColor * 2.0f;
#elif defined(_ADDITIVEBLEND_SOFT)
//Additive soft
finalPixel = texureColor;
finalPixel.rgb *= finalPixel.a;
#else
//Standard alpha
finalPixel.a = texureColor.a;
finalPixel.rgb = texureColor.rgb * finalPixel.a;
#endif
return finalPixel;
}
////////////////////////////////////////
// Alpha Clipping
//
#if defined(_ALPHA_CLIP)
uniform fixed _Cutoff;
#define ALPHA_CLIP(pixel, color) clip((pixel.a * color.a) - _Cutoff);
#else
#define ALPHA_CLIP(pixel, color)
#endif
////////////////////////////////////////
// Color functions
//
uniform fixed4 _Color;
inline fixed4 calculateVertexColor(fixed4 color)
{
return color * _Color;
}
#if defined(_COLOR_ADJUST)
uniform float _Hue;
uniform float _Saturation;
uniform float _Brightness;
uniform fixed4 _OverlayColor;
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c)
{
c = float3(c.x, clamp(c.yz, 0.0, 1.0));
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
inline fixed4 adjustColor(fixed4 color)
{
float3 hsv = rgb2hsv(color.rgb);
hsv.x += _Hue;
hsv.y *= _Saturation;
hsv.z *= _Brightness;
color.rgb = hsv2rgb(hsv);
return color;
}
#define COLORISE(pixel) pixel.rgb = lerp(pixel.rgb, _OverlayColor.rgb, _OverlayColor.a * pixel.a);
#define COLORISE_ADDITIVE(pixel) pixel.rgb = ((1.0-_OverlayColor.a) * pixel.rgb);
#else // !_COLOR_ADJUST
#define COLORISE(pixel)
#define COLORISE_ADDITIVE(pixel)
#endif // !_COLOR_ADJUST
////////////////////////////////////////
// Texture functions
//
uniform sampler2D _MainTex;
#if _TEXTURE_BLEND
uniform sampler2D _BlendTex;
uniform float _BlendAmount;
fixed4 calculateBlendedTexturePixel(float2 texcoord)
{
return (1.0-_BlendAmount) * tex2D(_MainTex, texcoord) + _BlendAmount * tex2D(_BlendTex, texcoord);
}
#endif // _TEXTURE_BLEND
inline fixed4 calculateTexturePixel(float2 texcoord)
{
fixed4 pixel;
#if _TEXTURE_BLEND
pixel = calculateBlendedTexturePixel(texcoord);
#else
pixel = tex2D(_MainTex, texcoord);
#endif // !_TEXTURE_BLEND
#if defined(_COLOR_ADJUST)
pixel = adjustColor(pixel);
#endif // _COLOR_ADJUST
return pixel;
}
uniform fixed4 _MainTex_ST;
inline float2 calculateTextureCoord(float4 texcoord)
{
return TRANSFORM_TEX(texcoord, _MainTex);
}
#endif // SHADER_SHARED_INCLUDED

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: ce9f78731d2f39c49a8688633f53a524
timeCreated: 1479457856
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,162 +0,0 @@
#ifndef SPRITE_LIGHTING_INCLUDED
#define SPRITE_LIGHTING_INCLUDED
//Check for using mesh normals
#if !defined(_FIXED_NORMALS) && !defined(_FIXED_NORMALS_BACK_RENDERING)
#define MESH_NORMALS
#endif // _FIXED_NORMALS || _FIXED_NORMALS_BACK_RENDERING
////////////////////////////////////////
// Vertex structs
//
struct VertexInput
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float4 color : COLOR;
#if defined(MESH_NORMALS)
float3 normal : NORMAL;
#endif // MESH_NORMALS
#if defined(_NORMALMAP)
float4 tangent : TANGENT;
#endif // _NORMALMAP
};
////////////////////////////////////////
// Normal functions
//
//Fixed Normal defined in view space
uniform float4 _FixedNormal = float4(0, 0, -1, 1);
inline half3 calculateSpriteWorldNormal(VertexInput vertex)
{
#if defined(MESH_NORMALS)
return calculateWorldNormal(vertex.normal);
#else //MESH_NORMALS
//Rotate fixed normal by inverse camera matrix to convert the fixed normal into world space
float3x3 invView = transpose((float3x3)UNITY_MATRIX_VP);
float3 normal = _FixedNormal.xyz;
#if UNITY_REVERSED_Z
normal.z = -normal.z;
#endif
return normalize(mul(invView, normal));
#endif // !MESH_NORMALS
}
inline half3 calculateSpriteViewNormal(VertexInput vertex)
{
#if defined(MESH_NORMALS)
return normalize(mul((float3x3)UNITY_MATRIX_IT_MV, vertex.normal));
#else // !MESH_NORMALS
float3 normal = _FixedNormal.xyz;
#if UNITY_REVERSED_Z
normal.z = -normal.z;
#endif
return normal;
#endif // !MESH_NORMALS
}
////////////////////////////////////////
// Normal map functions
//
#if defined(_NORMALMAP)
inline half3 calculateSpriteWorldBinormal(half3 normalWorld, half3 tangentWorld, float tangentW)
{
#if defined(_FIXED_NORMALS_BACK_RENDERING)
//If we're using fixed normals and sprite is facing away from camera, flip tangentW
float3 zAxis = float3(0.0, 0.0, 1.0);
float3 modelForward = mul((float3x3)unity_ObjectToWorld, zAxis);
float3 cameraForward = mul((float3x3)UNITY_MATRIX_VP, zAxis);
float directionDot = dot(modelForward, cameraForward);
//Don't worry if directionDot is zero, sprite will be side on to camera so invisible meaning it doesnt matter that tangentW will be zero too
tangentW *= sign(directionDot);
#endif // _FIXED_NORMALS_BACK_RENDERING
return calculateWorldBinormal(normalWorld, tangentWorld, tangentW);
}
#endif // _NORMALMAP
#if defined(_DIFFUSE_RAMP)
////////////////////////////////////////
// Diffuse ramp functions
//
//Disable for softer, more traditional diffuse ramping
#define HARD_DIFFUSE_RAMP
uniform sampler2D _DiffuseRamp;
inline fixed3 calculateDiffuseRamp(float ramp)
{
return tex2D(_DiffuseRamp, float2(ramp, ramp)).rgb;
}
inline fixed3 calculateRampedDiffuse(fixed3 lightColor, float attenuation, float angleDot)
{
float d = angleDot * 0.5 + 0.5;
#if defined(HARD_DIFFUSE_RAMP)
half3 ramp = calculateDiffuseRamp(d * attenuation * 2);
return lightColor * ramp;
#else
half3 ramp = calculateDiffuseRamp(d);
return lightColor * ramp * (attenuation * 2);
#endif
}
#endif // _DIFFUSE_RAMP
////////////////////////////////////////
// Rim Lighting functions
//
#ifdef _RIM_LIGHTING
uniform float _RimPower;
uniform fixed4 _RimColor;
inline fixed3 applyRimLighting(fixed3 posWorld, fixed3 normalWorld, fixed4 pixel) : SV_Target
{
fixed3 viewDir = normalize(_WorldSpaceCameraPos - posWorld);
float invDot = 1.0 - saturate(dot(normalWorld, viewDir));
float rimPower = pow(invDot, _RimPower);
float rim = saturate(rimPower * _RimColor.a);
#if defined(_DIFFUSE_RAMP)
rim = calculateDiffuseRamp(rim).r;
#endif
return lerp(pixel.rgb, _RimColor.xyz * pixel.a, rim);
}
#endif //_RIM_LIGHTING
////////////////////////////////////////
// Emission functions
//
#ifdef _EMISSION
uniform sampler2D _EmissionMap;
uniform fixed4 _EmissionColor;
uniform float _EmissionPower;
#define APPLY_EMISSION(diffuse, uv) \
{ \
diffuse += tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb * _EmissionPower; \
}
#else //!_EMISSION
#define APPLY_EMISSION(diffuse, uv)
#endif //!_EMISSION
#endif // SPRITE_LIGHTING_INCLUDED

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 252dba02e84702448a0838ced241467d
timeCreated: 1479457856
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,198 +0,0 @@
#ifndef SPRITE_PIXEL_LIGHTING_INCLUDED
#define SPRITE_PIXEL_LIGHTING_INCLUDED
#include "ShaderShared.cginc"
#include "SpriteLighting.cginc"
#include "AutoLight.cginc"
////////////////////////////////////////
// Defines
//
////////////////////////////////////////
// Vertex output struct
//
#if defined(_NORMALMAP)
#define _VERTEX_LIGHTING_INDEX TEXCOORD5
#define _LIGHT_COORD_INDEX_0 6
#define _LIGHT_COORD_INDEX_1 7
#define _FOG_COORD_INDEX 8
#else
#define _VERTEX_LIGHTING_INDEX TEXCOORD3
#define _LIGHT_COORD_INDEX_0 4
#define _LIGHT_COORD_INDEX_1 5
#define _FOG_COORD_INDEX 6
#endif // _NORMALMAP
struct VertexOutput
{
float4 pos : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 posWorld : TEXCOORD1;
half3 normalWorld : TEXCOORD2;
#if defined(_NORMALMAP)
half3 tangentWorld : TEXCOORD3;
half3 binormalWorld : TEXCOORD4;
#endif // _NORMALMAP
fixed3 vertexLighting : _VERTEX_LIGHTING_INDEX;
LIGHTING_COORDS(_LIGHT_COORD_INDEX_0, _LIGHT_COORD_INDEX_1)
#if defined(_FOG)
UNITY_FOG_COORDS(_FOG_COORD_INDEX)
#endif // _FOG
};
////////////////////////////////////////
// Light calculations
//
uniform fixed4 _LightColor0;
inline fixed3 calculateLightDiffuse(VertexOutput input, float3 normalWorld)
{
//For directional lights _WorldSpaceLightPos0.w is set to zero
float3 lightWorldDirection = normalize(_WorldSpaceLightPos0.xyz - input.posWorld.xyz * _WorldSpaceLightPos0.w);
float attenuation = LIGHT_ATTENUATION(input);
float angleDot = max(0, dot(normalWorld, lightWorldDirection));
#if defined(_DIFFUSE_RAMP)
fixed3 lightDiffuse = calculateRampedDiffuse(_LightColor0.rgb, attenuation, angleDot);
#else
fixed3 lightDiffuse = _LightColor0.rgb * (attenuation * angleDot);
#endif // _DIFFUSE_RAMP
return lightDiffuse;
}
inline float3 calculateNormalWorld(VertexOutput input)
{
#if defined(_NORMALMAP)
return calculateNormalFromBumpMap(input.texcoord, input.tangentWorld, input.binormalWorld, input.normalWorld);
#else
return input.normalWorld;
#endif
}
fixed3 calculateVertexLighting(float3 posWorld, float3 normalWorld)
{
fixed3 vertexLighting = fixed3(0,0,0);
#ifdef VERTEXLIGHT_ON
//Get approximated illumination from non-important point lights
vertexLighting = Shade4PointLights ( unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
unity_4LightAtten0, posWorld, normalWorld) * 0.5;
#endif
return vertexLighting;
}
fixed3 calculateAmbientLight(half3 normalWorld)
{
#if defined(_SPHERICAL_HARMONICS)
fixed3 ambient = ShadeSH9(half4(normalWorld, 1.0)) * 0.75f;
#else
fixed3 ambient = unity_AmbientSky.rgb * 0.75;
#endif
return ambient;
}
////////////////////////////////////////
// Vertex program
//
VertexOutput vert(VertexInput v)
{
VertexOutput output;
output.pos = calculateLocalPos(v.vertex);
output.color = calculateVertexColor(v.color);
output.texcoord = calculateTextureCoord(v.texcoord);
output.posWorld = calculateWorldPos(v.vertex);
output.normalWorld = calculateSpriteWorldNormal(v);
output.vertexLighting = calculateVertexLighting(output.posWorld, output.normalWorld);
#if defined(_NORMALMAP)
output.tangentWorld = calculateWorldTangent(v.tangent);
output.binormalWorld = calculateSpriteWorldBinormal(output.normalWorld, output.tangentWorld, v.tangent.w);
#endif
TRANSFER_VERTEX_TO_FRAGMENT(output)
#if defined(_FOG)
UNITY_TRANSFER_FOG(output,output.pos);
#endif // _FOG
return output;
}
////////////////////////////////////////
// Fragment programs
//
fixed4 fragBase(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord);
ALPHA_CLIP(texureColor, input.color)
//Get normal direction
fixed3 normalWorld = calculateNormalWorld(input);
//Get Ambient diffuse
fixed3 ambient = calculateAmbientLight(normalWorld);
//Get primary pixel light diffuse
fixed3 diffuse = calculateLightDiffuse(input, normalWorld);
//Combine along with vertex lighting for the base lighting pass
fixed3 lighting = ambient + diffuse + input.vertexLighting;
APPLY_EMISSION(lighting, input.texcoord)
fixed4 pixel = calculateLitPixel(texureColor, input.color, lighting);
#if defined(_RIM_LIGHTING)
pixel.rgb = applyRimLighting(input.posWorld, normalWorld, pixel);
#endif
COLORISE(pixel)
#if defined(_FOG)
fixed4 fogColor = lerp(fixed4(0,0,0,0), unity_FogColor, pixel.a);
UNITY_APPLY_FOG_COLOR(input.fogCoord, pixel, fogColor);
#endif // _FOG
return pixel;
}
fixed4 fragAdd(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord);
#if defined(_COLOR_ADJUST)
texureColor = adjustColor(texureColor);
#endif // _COLOR_ADJUST
ALPHA_CLIP(texureColor, input.color)
//Get normal direction
fixed3 normalWorld = calculateNormalWorld(input);
//Get light diffuse
fixed3 lighting = calculateLightDiffuse(input, normalWorld);
fixed4 pixel = calculateAdditiveLitPixel(texureColor, input.color, lighting);
COLORISE_ADDITIVE(pixel)
#if defined(_FOG)
UNITY_APPLY_FOG_COLOR(input.fogCoord, pixel.rgb, fixed4(0,0,0,0)); // fog towards black in additive pass
#endif // _FOG
return pixel;
}
#endif // SPRITE_PIXEL_LIGHTING_INCLUDED

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 38bcbfc10385d424c9cbac5b5b9ec1af
timeCreated: 1479457856
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,54 +0,0 @@
#ifndef SPRITE_SHADOWS_INCLUDED
#define SPRITE_SHADOWS_INCLUDED
#include "UnityCG.cginc"
////////////////////////////////////////
// Vertex structs
//
struct vertexInput
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct vertexOutput
{
V2F_SHADOW_CASTER;
float4 texcoordAndAlpha : TEXCOORD1;
};
////////////////////////////////////////
// Vertex program
//
uniform sampler2D _MainTex;
uniform fixed4 _MainTex_ST;
vertexOutput vert(vertexInput v, float4 vertexColor : COLOR)
{
vertexOutput o;
TRANSFER_SHADOW_CASTER(o)
o.texcoordAndAlpha.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
o.texcoordAndAlpha.z = 0;
o.texcoordAndAlpha.a = vertexColor.a;
return o;
}
////////////////////////////////////////
// Fragment program
//
uniform fixed _ShadowAlphaCutoff;
fixed4 frag(vertexOutput IN) : SV_Target
{
fixed4 texureColor = tex2D(_MainTex, IN.texcoordAndAlpha.xy);
clip(texureColor.a * IN.texcoordAndAlpha.a - _ShadowAlphaCutoff);
SHADOW_CASTER_FRAGMENT(IN)
}
#endif // SPRITE_SHADOWS_INCLUDED

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 0f58b811a44f1b44cb9aac3ddfe24f37
timeCreated: 1479457856
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,67 +0,0 @@
#ifndef SPRITE_UNLIT_INCLUDED
#define SPRITE_UNLIT_INCLUDED
#include "ShaderShared.cginc"
////////////////////////////////////////
// Vertex structs
//
struct VertexInput
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
struct VertexOutput
{
float4 pos : SV_POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
#if defined(_FOG)
UNITY_FOG_COORDS(1)
#endif // _FOG
};
////////////////////////////////////////
// Vertex program
//
VertexOutput vert(VertexInput input)
{
VertexOutput output;
output.pos = calculateLocalPos(input.vertex);
output.texcoord = calculateTextureCoord(input.texcoord);
output.color = calculateVertexColor(input.color);
#if defined(_FOG)
UNITY_TRANSFER_FOG(output,output.pos);
#endif // _FOG
return output;
}
////////////////////////////////////////
// Fragment program
//
fixed4 frag(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
ALPHA_CLIP(texureColor, input.color)
fixed4 pixel = calculatePixel(texureColor, input.color);
COLORISE(pixel)
#if defined(_FOG)
fixed4 fogColor = lerp(fixed4(0,0,0,0), unity_FogColor, pixel.a);
UNITY_APPLY_FOG_COLOR(input.fogCoord, pixel, fogColor);
#endif // _FOG
return pixel;
}
#endif // SPRITE_UNLIT_INCLUDED

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: e67832d6dd9dd914ca946fa7fcaa4a9e
timeCreated: 1479457856
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,430 +0,0 @@
#ifndef SPRITE_VERTEX_LIGHTING_INCLUDED
#define SPRITE_VERTEX_LIGHTING_INCLUDED
#include "ShaderShared.cginc"
#include "SpriteLighting.cginc"
#include "UnityStandardUtils.cginc"
////////////////////////////////////////
// Defines
//
//Define to use spot lights (more expensive)
#define SPOT_LIGHTS
//Have to process lighting per pixel if using normal maps or a diffuse ramp or rim lighting
#if defined(_NORMALMAP) || defined(_DIFFUSE_RAMP) || defined(_RIM_LIGHTING)
#define PER_PIXEL_LIGHTING
#endif
//Turn off bump mapping and diffuse ramping on older shader models as they dont support needed number of outputs
#if defined(PER_PIXEL_LIGHTING) && (SHADER_TARGET < 30)
#undef PER_PIXEL_LIGHTING
#undef _NORMALMAP
#undef _DIFFUSE_RAMP
#undef _RIM_LIGHTING
#endif
//In D3D9 only have a max of 9 TEXCOORD so can't have diffuse ramping or fog or rim lighting if processing lights per pixel
#if defined(SHADER_API_D3D9) && defined(PER_PIXEL_LIGHTING)
#if defined(_NORMALMAP)
#undef _DIFFUSE_RAMP
#undef _FOG
#undef _RIM_LIGHTING
#elif defined(_DIFFUSE_RAMP)
#undef _FOG
#undef _RIM_LIGHTING
#elif defined(_RIM_LIGHTING)
#undef _FOG
#undef _DIFFUSE_RAMP
#else
#undef _DIFFUSE_RAMP
#undef _RIM_LIGHTING
#endif
#endif
#if defined(PER_PIXEL_LIGHTING)
#if defined(_NORMALMAP) && defined(_DIFFUSE_RAMP)
#define ATTENUATIONS TEXCOORD9
#if defined(_RIM_LIGHTING)
#define _POS_WORLD_INDEX TEXCOORD10
#define _FOG_COORD_INDEX 11
#else
#define _FOG_COORD_INDEX 10
#endif
#elif defined(_NORMALMAP) != defined(_DIFFUSE_RAMP)
#define ATTENUATIONS TEXCOORD8
#if defined(_RIM_LIGHTING)
#define _POS_WORLD_INDEX TEXCOORD9
#define _FOG_COORD_INDEX 10
#else
#define _FOG_COORD_INDEX 9
#endif
#else //!_DIFFUSE_RAMP && !_NORMALMAP
#if defined(_RIM_LIGHTING)
#define _POS_WORLD_INDEX TEXCOORD8
#define _FOG_COORD_INDEX 9
#else
#define _FOG_COORD_INDEX 8
#endif
#endif
#else //!PER_PIXEL_LIGHTING
#define _FOG_COORD_INDEX 2
#endif
////////////////////////////////////////
// Vertex output struct
//
struct VertexOutput
{
float4 pos : SV_POSITION;
fixed4 color : COLOR;
float3 texcoord : TEXCOORD0;
#if defined(PER_PIXEL_LIGHTING)
half4 VertexLightInfo0 : TEXCOORD1;
half4 VertexLightInfo1 : TEXCOORD2;
half4 VertexLightInfo2 : TEXCOORD3;
half4 VertexLightInfo3 : TEXCOORD4;
half4 VertexLightInfo4 : TEXCOORD5;
#if defined(_NORMALMAP)
half4 normalWorld : TEXCOORD6;
half4 tangentWorld : TEXCOORD7;
half4 binormalWorld : TEXCOORD8;
#else
half3 normalWorld : TEXCOORD6;
half3 VertexLightInfo5 : TEXCOORD7;
#endif
#if defined(_DIFFUSE_RAMP)
half4 LightAttenuations : ATTENUATIONS;
#endif
#if defined(_RIM_LIGHTING)
float4 posWorld : _POS_WORLD_INDEX;
#endif
#else //!PER_PIXEL_LIGHTING
half3 FullLighting : TEXCOORD1;
#endif // !PER_PIXEL_LIGHTING
#if defined(_FOG)
UNITY_FOG_COORDS(_FOG_COORD_INDEX)
#endif // _FOG
};
////////////////////////////////////////
// Light calculations
//
struct VertexLightInfo
{
half3 lightDirection;
fixed3 lightColor;
#if defined(_DIFFUSE_RAMP)
float attenuation;
#endif // _DIFFUSE_RAMP
};
inline VertexLightInfo getVertexLightAttenuatedInfo(int index, float3 viewPos)
{
VertexLightInfo lightInfo;
//For directional lights unity_LightPosition.w is set to zero
lightInfo.lightDirection = unity_LightPosition[index].xyz - viewPos.xyz * unity_LightPosition[index].w;
float lengthSq = dot(lightInfo.lightDirection, lightInfo.lightDirection);
// don't produce NaNs if some vertex position overlaps with the light
lengthSq = max(lengthSq, 0.000001);
lightInfo.lightDirection *= rsqrt(lengthSq);
float attenuation = 1.0 / (1.0 + lengthSq * unity_LightAtten[index].z);
#if defined(SPOT_LIGHTS)
//Spot light attenuation - for non-spot lights unity_LightAtten.x is set to -1 and y is set to 1
{
float rho = max (0, dot(lightInfo.lightDirection, unity_SpotDirection[index].xyz));
float spotAtt = (rho - unity_LightAtten[index].x) * unity_LightAtten[index].y;
attenuation *= saturate(spotAtt);
}
#endif // SPOT_LIGHTS
//If using a diffuse ramp texture then need to pass through the lights attenuation, otherwise premultiply the light color with it
#if defined(_DIFFUSE_RAMP)
lightInfo.lightColor = unity_LightColor[index].rgb;
lightInfo.attenuation = attenuation;
#else
lightInfo.lightColor = unity_LightColor[index].rgb * attenuation;
#endif // _DIFFUSE_RAMP
return lightInfo;
}
fixed3 calculateAmbientLight(half3 normalWorld)
{
#if defined(_SPHERICAL_HARMONICS)
//Magic constants used to tweak ambient to approximate pixel shader spherical harmonics
static const fixed3 worldUp = fixed3(0,1,0);
static const float skyGroundDotMul = 2.5;
static const float minEquatorMix = 0.5;
static const float equatorColorBlur = 0.33;
float upDot = dot(normalWorld, worldUp);
//Fade between a flat lerp from sky to ground and a 3 way lerp based on how bright the equator light is.
//This simulates how directional lights get blurred using spherical harmonics
//Work out color from ground and sky, ignoring equator
float adjustedDot = upDot * skyGroundDotMul;
fixed3 skyGroundColor = lerp(unity_AmbientGround, unity_AmbientSky, saturate((adjustedDot + 1.0) * 0.5));
//Work out equator lights brightness
float equatorBright = saturate(dot(unity_AmbientEquator.rgb, unity_AmbientEquator.rgb));
//Blur equator color with sky and ground colors based on how bright it is.
fixed3 equatorBlurredColor = lerp(unity_AmbientEquator, saturate(unity_AmbientEquator + unity_AmbientGround + unity_AmbientSky), equatorBright * equatorColorBlur);
//Work out 3 way lerp inc equator light
fixed3 equatorColor = lerp(equatorBlurredColor, unity_AmbientGround, -upDot) * step(upDot, 0) + lerp(equatorBlurredColor, unity_AmbientSky, upDot) * step(0, upDot);
//Mix the two colors together based on how bright the equator light is
return lerp(skyGroundColor, equatorColor, saturate(equatorBright + minEquatorMix)) * 0.75;
#else // !_SPHERICAL_HARMONICS
//Flat ambient is just the sky color
return unity_AmbientSky.rgb * 0.75;
#endif // !_SPHERICAL_HARMONICS
}
////////////////////////////////////////
// Light Packing Functions
//
#if defined(_DIFFUSE_RAMP)
inline fixed3 calculateLightDiffuse(fixed3 lightColor, half3 viewNormal, half3 lightViewDir, float attenuation)
{
float angleDot = max(0, dot(viewNormal, lightViewDir));
return calculateRampedDiffuse(lightColor, attenuation, angleDot);
}
#else
inline fixed3 calculateLightDiffuse(fixed3 attenuatedLightColor, half3 viewNormal, half3 lightViewDir)
{
float angleDot = max(0, dot(viewNormal, lightViewDir));
return attenuatedLightColor * angleDot;
}
#endif // _NORMALMAP
#if defined(PER_PIXEL_LIGHTING)
#define VERTEX_LIGHT_0_DIR VertexLightInfo0.xyz
#define VERTEX_LIGHT_0_R VertexLightInfo4.x
#define VERTEX_LIGHT_0_G VertexLightInfo4.y
#define VERTEX_LIGHT_0_B VertexLightInfo4.z
#define VERTEX_LIGHT_1_DIR VertexLightInfo1.xyz
#define VERTEX_LIGHT_1_R VertexLightInfo0.w
#define VERTEX_LIGHT_1_G VertexLightInfo1.w
#define VERTEX_LIGHT_1_B VertexLightInfo2.w
#define VERTEX_LIGHT_2_DIR VertexLightInfo2.xyz
#define VERTEX_LIGHT_2_R VertexLightInfo3.w
#define VERTEX_LIGHT_2_G VertexLightInfo4.w
#define VERTEX_LIGHT_2_B texcoord.z
#define VERTEX_LIGHT_3_DIR VertexLightInfo3.xyz
#if defined(_NORMALMAP)
#define VERTEX_LIGHT_3_R normalWorld.w
#define VERTEX_LIGHT_3_G tangentWorld.w
#define VERTEX_LIGHT_3_B binormalWorld.w
#else
#define VERTEX_LIGHT_3_R VertexLightInfo5.x
#define VERTEX_LIGHT_3_G VertexLightInfo5.y
#define VERTEX_LIGHT_3_B VertexLightInfo5.z
#endif
#if defined(_DIFFUSE_RAMP)
#define LIGHT_DIFFUSE_ATTEN_0 LightAttenuations.x
#define LIGHT_DIFFUSE_ATTEN_1 LightAttenuations.y
#define LIGHT_DIFFUSE_ATTEN_2 LightAttenuations.z
#define LIGHT_DIFFUSE_ATTEN_3 LightAttenuations.w
#define PACK_VERTEX_LIGHT_DIFFUSE(index, output, lightInfo) \
{ \
output.LIGHT_DIFFUSE_ATTEN_##index = lightInfo.attenuation; \
}
#define ADD_VERTEX_LIGHT_DIFFUSE(index, diffuse, input, lightColor, viewNormal, lightViewDir) \
{ \
diffuse += calculateLightDiffuse(lightColor, viewNormal, lightViewDir, input.LIGHT_DIFFUSE_ATTEN_##index); \
}
#else
#define PACK_VERTEX_LIGHT_DIFFUSE(index, output, lightInfo)
#define ADD_VERTEX_LIGHT_DIFFUSE(index, diffuse, input, lightColor, viewNormal, lightViewDir) \
{ \
diffuse += calculateLightDiffuse(lightColor, viewNormal, lightViewDir); \
}
#endif
#define PACK_VERTEX_LIGHT(index, output, viewPos) \
{ \
VertexLightInfo lightInfo = getVertexLightAttenuatedInfo(index, viewPos); \
output.VERTEX_LIGHT_##index##_DIR = lightInfo.lightDirection; \
output.VERTEX_LIGHT_##index##_R = lightInfo.lightColor.r; \
output.VERTEX_LIGHT_##index##_G = lightInfo.lightColor.g; \
output.VERTEX_LIGHT_##index##_B = lightInfo.lightColor.b; \
PACK_VERTEX_LIGHT_DIFFUSE(index, output, lightInfo); \
}
#define ADD_VERTEX_LIGHT(index, input, viewNormal, diffuse) \
{ \
half3 lightViewDir = input.VERTEX_LIGHT_##index##_DIR; \
fixed3 lightColor = fixed3(input.VERTEX_LIGHT_##index##_R, input.VERTEX_LIGHT_##index##_G, input.VERTEX_LIGHT_##index##_B); \
ADD_VERTEX_LIGHT_DIFFUSE(index, diffuse, input, lightColor, viewNormal, lightViewDir) \
}
#else //!PER_PIXEL_LIGHTING
////////////////////////////////////////
// Vertex Only Functions
//
inline fixed3 calculateLightDiffuse(int index, float3 viewPos, half3 viewNormal)
{
VertexLightInfo lightInfo = getVertexLightAttenuatedInfo(index, viewPos);
float angleDot = max(0, dot(viewNormal, lightInfo.lightDirection));
return lightInfo.lightColor * angleDot;
}
#endif // !PER_PIXEL_LIGHTING
////////////////////////////////////////
// Vertex program
//
VertexOutput vert(VertexInput input)
{
VertexOutput output;
output.pos = calculateLocalPos(input.vertex);
output.color = calculateVertexColor(input.color);
output.texcoord = float3(calculateTextureCoord(input.texcoord), 0);
float3 viewPos = UnityObjectToViewPos(input.vertex);
#if defined(PER_PIXEL_LIGHTING)
#if defined(_RIM_LIGHTING)
output.posWorld = calculateWorldPos(input.vertex);
#endif
PACK_VERTEX_LIGHT(0, output, viewPos)
PACK_VERTEX_LIGHT(1, output, viewPos)
PACK_VERTEX_LIGHT(2, output, viewPos)
PACK_VERTEX_LIGHT(3, output, viewPos)
output.normalWorld.xyz = calculateSpriteWorldNormal(input);
#if defined(_NORMALMAP)
output.tangentWorld.xyz = calculateWorldTangent(input.tangent);
output.binormalWorld.xyz = calculateSpriteWorldBinormal(output.normalWorld, output.tangentWorld, input.tangent.w);
#endif
#else // !PER_PIXEL_LIGHTING
//Just pack full lighting
float3 viewNormal = calculateSpriteViewNormal(input);
//Get Ambient diffuse
float3 normalWorld = calculateSpriteWorldNormal(input);
fixed3 ambient = calculateAmbientLight(normalWorld);
fixed3 diffuse = calculateLightDiffuse(0, viewPos, viewNormal);
diffuse += calculateLightDiffuse(1, viewPos, viewNormal);
diffuse += calculateLightDiffuse(2, viewPos, viewNormal);
diffuse += calculateLightDiffuse(3, viewPos, viewNormal);
output.FullLighting = ambient + diffuse;
#endif // !PER_PIXEL_LIGHTING
#if defined(_FOG)
UNITY_TRANSFER_FOG(output, output.pos);
#endif // _FOG
return output;
}
////////////////////////////////////////
// Fragment program
//
fixed4 frag(VertexOutput input) : SV_Target
{
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
ALPHA_CLIP(texureColor, input.color)
#if defined(PER_PIXEL_LIGHTING)
#if defined(_NORMALMAP)
half3 normalWorld = calculateNormalFromBumpMap(input.texcoord.xy, input.tangentWorld.xyz, input.binormalWorld.xyz, input.normalWorld.xyz);
#else
half3 normalWorld = input.normalWorld.xyz;
#endif
//Get Ambient diffuse
fixed3 ambient = calculateAmbientLight(normalWorld);
//Find vertex light diffuse
fixed3 diffuse = fixed3(0,0,0);
//Add each vertex light to diffuse
half3 normalView = normalize(mul((float3x3)UNITY_MATRIX_V, normalWorld));
ADD_VERTEX_LIGHT(0, input, normalView, diffuse)
ADD_VERTEX_LIGHT(1, input, normalView, diffuse)
ADD_VERTEX_LIGHT(2, input, normalView, diffuse)
ADD_VERTEX_LIGHT(3, input, normalView, diffuse)
fixed3 lighting = ambient + diffuse;
APPLY_EMISSION(lighting, input.texcoord.xy)
fixed4 pixel = calculateLitPixel(texureColor, input.color, lighting);
#if defined(_RIM_LIGHTING)
pixel.rgb = applyRimLighting(input.posWorld, normalWorld, pixel);
#endif
#else // !PER_PIXEL_LIGHTING
APPLY_EMISSION(input.FullLighting, input.texcoord.xy)
fixed4 pixel = calculateLitPixel(texureColor, input.color, input.FullLighting);
#endif // !PER_PIXEL_LIGHTING
COLORISE(pixel)
#if defined(_FOG)
fixed4 fogColor = lerp(fixed4(0,0,0,0), unity_FogColor, pixel.a);
UNITY_APPLY_FOG_COLOR(input.fogCoord, pixel, fogColor);
#endif // _FOG
return pixel;
}
#endif // SPRITE_VERTEX_LIGHTING_INCLUDED

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: b256f9f092407414392d98f339173a2d
timeCreated: 1479457856
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant: