Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/LightMap Blend Diffuse Specular Transparency" {
- Properties {
- _Color ("MainColor", Color) = (1, 1, 1, 1)
- _SpecColor ("Specular Color", Color) = (1, 1, 1, 1)
- _Shininess ("Shininess", Float) = 10
- _MainTex ("Base (RGB)", 2D) = "white" {}
- _LightMap01 ( "LightMap 1", 2D ) = "white" {}
- _LightMap02 ( "LightMap 2", 2D ) = "white" {}
- _Trans ("Transparency", Range(0, 1)) = 0
- }
- SubShader {
- Pass
- {
- Tags { "LightMode" = "ForwardBase" }
- CGPROGRAM
- #pragma multi_compile_fwdbase
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- uniform float4 _LightColor0;
- float4 _Color;
- float4 _SpecColor;
- float _Shininess;
- struct vertexIn
- {
- float4 pos : POSITION;
- float3 norm : normal;
- };
- struct vertexOut
- {
- float4 pos : SV_POSITION;
- float3 posWorld : TEXCOORD0;
- float3 norm : TEXCOORD1;
- float3 vertexLighting : TEXCOORD2;
- };
- vertexOut vert(vertexIn i)
- {
- vertexOut o;
- float4x4 modelMatrix = _Object2World;
- float4x4 modelMatrixInverse = _World2Object;
- o.posWorld = mul(modelMatrix, i.pos);
- o.norm = normalize( mul(float4(i.norm, 0), modelMatrixInverse).xyz );
- o.pos = mul( UNITY_MATRIX_MVP, i.pos);
- o.vertexLighting = float3(0, 0, 0);
- for (int i = 0; i < 8; i++)
- {
- float4 lightPosition = unity_LightPosition[i];
- float3 vertexToLightSource = lightPosition.xyz - o.posWorld.xyz;
- float3 lightDirection = normalize(vertexToLightSource);
- float squaredDistance = dot(vertexToLightSource, vertexToLightSource);
- float attenuation = 1.0 / (1.0 + unity_LightAtten[i] * squaredDistance);
- float3 diffuseReflection = attenuation
- * unity_LightColor[i].rgb * _Color.rgb
- * max(0.0, dot(o.norm, lightDirection));
- o.vertexLighting += diffuseReflection;
- }
- return o;
- }
- float4 frag(vertexOut o) : COLOR
- {
- float3 normalDirection = normalize(o.norm);
- float3 viewDirection = normalize(_WorldSpaceCameraPos - o.posWorld.xyz);
- float3 lightDirection = float3(0, 0, 0);
- float attenuation;
- lightDirection = normalize(_WorldSpaceLightPos0.xyz) * (1 - _WorldSpaceLightPos0.w);
- float3 PointLightDirection = _WorldSpaceLightPos0.xyz - o.posWorld.xyz;
- float PointLightLength = length(PointLightDirection);
- lightDirection += normalize(PointLightDirection) * _WorldSpaceLightPos0.w;
- attenuation = 1.0 / PointLightLength;
- float3 diffuseColor = lerp(_LightColor0.rgb * _Color.rgb * max(0, dot(normalDirection, lightDirection)),
- _LightColor0.rgb * _Color.rgb * max(0, dot(normalDirection, lightDirection) * attenuation), _WorldSpaceLightPos0.w);
- float3 specularColor = (_LightColor0.rgb * _Color.rgb * max(0, dot(reflect(-lightDirection, normalDirection), viewDirection)))
- * max(0, dot (normalDirection, lightDirection));
- return float4(o.vertexLighting, 1);
- }
- ENDCG
- }
- Pass
- {
- Tags { "LightMode" = "ForwardAdd" }
- Blend One One
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- uniform float4 _LightColor0;
- sampler2D _MainTex;
- float4 _Color;
- float4 _SpecColor;
- float _Shininess;
- struct vertexIn
- {
- float4 pos : POSITION;
- float3 norm : normal;
- };
- struct vertexOut
- {
- float4 pos : SV_POSITION;
- float4 col : COLOR;
- float3 posWorld : TEXCOORD0;
- float3 norm : TEXCOORD1;
- };
- vertexOut vert(vertexIn i)
- {
- vertexOut o;
- float4x4 modelMatrix = _Object2World;
- float4x4 modelMatrixInverse = _World2Object;
- o.posWorld = mul(modelMatrix, i.pos);
- o.norm = normalize( mul(float4(i.norm, 0), modelMatrixInverse).xyz );
- o.pos = mul( UNITY_MATRIX_MVP, i.pos);
- return o;
- }
- float4 frag(vertexOut o) : COLOR
- {
- float3 normalDirection = normalize(o.norm);
- float3 viewDirection = normalize(_WorldSpaceCameraPos - o.posWorld.xyz);
- float3 lightDirection = float3(0, 0, 0);
- float attenuation;
- lightDirection = normalize(_WorldSpaceLightPos0.xyz) * (1 - _WorldSpaceLightPos0.w);
- float3 PointLightDirection = _WorldSpaceLightPos0.xyz - o.posWorld.xyz;
- float PointLightLength = length(PointLightDirection);
- lightDirection += normalize(PointLightDirection) * _WorldSpaceLightPos0.w;
- attenuation = 1.0 / PointLightLength;
- float3 diffuseColor = lerp( _LightColor0.rgb * _Color.rgb * max(0, dot(normalDirection, lightDirection)),
- _LightColor0.rgb * _Color.rgb * max(0, dot(normalDirection, lightDirection) * attenuation), _WorldSpaceLightPos0.w );
- float3 specularColor = ( _LightColor0.rgb * _Color.rgb * max(0, dot(reflect(-lightDirection, normalDirection), viewDirection)) )
- * max(0, dot (normalDirection, lightDirection));
- return float4(diffuseColor, 0);
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement