Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Spine/BumpedSkeleton" {
- Properties
- {
- _MainTex ("Diffuse Texture", 2D) = "white" {}
- _Normal ("Normal", 2D) = "bump" {}
- }
- SubShader
- {
- AlphaTest Greater 0.9
- Blend One OneMinusSrcAlpha
- Pass
- {
- Tags { "LightMode" = "ForwardBase" }
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- // User-specified properties
- uniform sampler2D _MainTex;
- struct VertexInput
- {
- float4 vertex : POSITION;
- float4 color : COLOR;
- float4 uv : TEXCOORD0;
- };
- struct VertexOutput
- {
- float4 pos : POSITION;
- float4 color : COLOR;
- float2 uv : TEXCOORD0;
- };
- VertexOutput vert(VertexInput input)
- {
- VertexOutput output;
- output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
- output.color = input.color;
- output.uv = float2(input.uv);
- return output;
- }
- float4 frag(VertexOutput input) : COLOR
- {
- float4 diffuseColor = tex2D(_MainTex, input.uv);
- float3 ambientLighting = float3(UNITY_LIGHTMODEL_AMBIENT) * float3(diffuseColor) * float3(input.color);
- return float4(ambientLighting, diffuseColor.a);
- }
- ENDCG
- }
- Pass {
- Tags { "LightMode"="ForwardAdd" }
- Blend One OneMinusSrcAlpha
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- // User-specified properties
- uniform sampler2D _MainTex;
- uniform sampler2D _Normal;
- uniform float4 _LightColor0;
- struct VertexInput
- {
- float4 vertex : POSITION;
- float4 tangent : TANGENT;
- float3 normal : NORMAL;
- float4 uv : TEXCOORD0;
- float4 texcoord1 : TEXCOORD1;
- fixed4 color : COLOR;
- };
- struct VertexOutput
- {
- float4 pos : POSITION;
- float4 color : COLOR;
- float2 uv : TEXCOORD0;
- float4 posWorld : TEXCOORD1;
- float4 info : TEXCOORD2;
- };
- VertexOutput vert(VertexInput input)
- {
- VertexOutput output;
- output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
- output.posWorld = mul(_Object2World, input.vertex);
- output.color = input.color;
- output.uv = float2(input.uv);
- output.info.x = input.tangent.x;
- output.info.y = input.tangent.y;
- output.info.z = input.tangent.z;
- output.info.w = input.tangent.w;
- return output;
- }
- float4 frag(VertexOutput input) : COLOR
- {
- float4 diffuseColor = tex2D(_MainTex, input.uv);
- //Computing the normal:
- float3 normalDirection = (tex2D(_Normal, input.uv).xyz * 2.0f) - 1.0f;
- //rotation matrix
- float angle = -input.info.x;
- float scale = input.info.y;
- float4x4 rotMatrix = float4x4(cos(angle) * scale, -sin(angle) * scale, 0, 0,
- sin(angle) * scale, cos(angle) * scale, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1);
- normalDirection = float3(mul(float4(normalDirection, 1.0f), mul(rotMatrix, _World2Object)));
- normalDirection.z *= -1;
- normalDirection = normalize(normalDirection);
- // Distance
- float3 vertexToLightSource = float3(_WorldSpaceLightPos0 - input.posWorld);
- float distance = length(float3(vertexToLightSource));
- // The values for attenuation and lightDirection are assuming point lights
- float attenuation = 30.0 / distance; // Linear attenuation is good enough for now
- float3 lightDirection = normalize(vertexToLightSource);
- // Compute diffuse part of lighting
- float normalDotLight = clamp(dot(normalDirection, lightDirection), 0.0, 1.0);
- float diffuseLevel = normalDotLight * attenuation;
- float3 diffuseReflection =
- float3(diffuseColor)
- * input.color
- * float3(_LightColor0)
- * float3(diffuseLevel)
- ;
- return float4(diffuseReflection, diffuseColor.a);
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement