Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/NewPSXTEST"
- {
- Properties
- {
- _Color("Main Color", Color) = (1,1,1,1)
- [Header(Player position)][Space]
- _Player ("Player Position", Vector) = (0,0,0,0)
- [Header(Diffuse Alpha Cutoff)][Space]
- _MainTex ("Texture (Alpha Cutoff)", 2D) = "white" {}
- _VertexTex ("Color Map (Vertex)", 2D) = "white" {}
- _Distortion ("Geometric Resolution",Float) = 40
- _Distance ("Texture Draw Distance" , Float) = 2
- _LodDistance ("LOD Change" , Range(0,1)) = .5
- [Space]
- _Translucency ("Translucency Off/On", Range (0,1)) = 1
- _TranCutOff ("Cutoff Threshold", Range (0,1)) = .5
- [Space][Header(Emission)][Space]
- _EmiVal ("Intensity Off/Range", Range(0,10)) = 0
- _EmiMap ("Emission Map (Alpha Cutout)", 2D) = "white" {}
- _EmiTexture ("Emission texture", 2D) = "gray" {}
- //_EmiDistance ("Texture Draw Distance" , Float) = 2
- [HDR]_EmiColor ("Color", color) = (1., 1., 1., 1.)
- [Space][Header(Reflection)][Space]
- _RefValue ("Reflection Off/On", Range(0,1)) = 1
- _RefMapTex ("Reflection Map (Alpha Cutout)", 2D) = "white" {}
- _RefCubemap ("Reflection Cubemap", CUBE) = "" {}
- [Space][Header(Specular)][Space]
- _SpecLerp ("Specular Off/On", Range(0, 1)) = .5
- _Shininess ("Shininess", Range(0.1, 10)) = 1.
- [Space][Header(Shadow)][Space]
- _IlumStrength ("Shadow Strength", Range (0,1)) = 0.9
- _IlumDistance ("Shadow Draw Distance", Float) = 3
- }
- Category
- {
- Tags{ "RenderType"="TransparentCutout"}
- LOD 150
- SubShader
- {
- Pass
- {
- Name "COLOR"
- Tags{ "LightMode" = "Vertex" }
- //ZWrite Off
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- #include "UnityLightingCommon.cginc" // for _LightColor0
- //> INPUT STRUCT
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- fixed4 color : COLOR0;
- float3 normal : NORMAL;
- };
- struct v2f
- {
- float4 pos : SV_POSITION;
- float4 worldSpacePosition : TEXCOORD0;
- float3 uv : TEXCOORD1;
- float4 screenPos : TEXCOORD2;
- half3 worldRefl : TEXCOORD3;
- float4 color : COLOR0;
- };
- //> TEXTURES
- float4 _Player;
- sampler2D _MainTex;
- float4 _MainTex_ST;
- sampler2D _VertexTex;
- sampler2D _VertexTex_ST;
- float _Distortion;
- //> DISTANCES
- float _Distance;
- float _LodDistance;
- //> REFLECTION
- sampler2D _RefMapTex;
- samplerCUBE _RefCubemap;
- float _RefValue;
- //> EMISSION
- sampler2D _EmiMap;
- sampler2D _EmiTexture;
- fixed4 _EmiColor;
- float _EmiVal;
- //> SPECULAR
- float _Shininess;
- float _SpecLerp;
- uniform float _Translucency;
- v2f vert(appdata v)
- {
- v2f o;
- //o.pos = UnityObjectToClipPos(v.vertex);
- //> VERTEX SNAPPING
- //
- float3 wp = UnityObjectToViewPos (v.vertex); //converts object space to view space
- o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex);
- wp = floor(wp * _Distortion) / _Distortion;
- //
- float4 sp = mul(UNITY_MATRIX_P, fixed4(wp.xyz,1));//converts to projection matrix
- o.pos = sp;
- //
- float2 uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.uv = float3(uv * sp.w, sp.w);
- o.screenPos = ComputeScreenPos(o.pos);
- //> ILUMINATION
- // world space normal
- half3 worldNormal = UnityObjectToWorldNormal(v.normal);
- half nDotl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
- //assign darkness to the vertex colors while factoring in the light color
- float4 lightColor = v.color * _LightColor0 ;//* tex2Dlod(_VertexTex, float4(uv.xy, 0.0, 0.0));
- //> DISTANCE
- //convert the World Space and calculate distance between vertices and player
- o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex);
- //> SPECULAR
- float3 refl = reflect(-(normalize(_WorldSpaceLightPos0.xyz)), worldNormal);
- float RdotV = max(0., dot(refl, normalize(_WorldSpaceCameraPos.xyz - o.worldSpacePosition.xyz)));
- fixed3 spec = pow(RdotV, _Shininess) * _LightColor0.rgb * ceil(nDotl);
- //spec.a = lerp(spec.a, 0, _Translucency);
- fixed3 specColor = lerp(0, spec, _SpecLerp) * _Shininess;
- //> FINAL COLOR
- o.color = lightColor + fixed4(specColor.rgb, 0);
- //> RESULT
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- //> TEXTURE
- i.worldSpacePosition = floor(i.worldSpacePosition);
- //get distance from player to world position of vertices
- float dist = distance(i.worldSpacePosition, _Player) / (_Distance*10);
- //lerp between the texture and the vertex colors calculated in vertex shader
- float2 uv = i.uv.xy / i.uv.z;
- fixed4 fragTexture = lerp(tex2Dlod(_MainTex, float4(uv.xy, 0.0, 0.0)),
- tex2Dlod(_MainTex, float4(uv.xy, 0.0, 1.0)), dist * _LodDistance) * step(dist, _LodDistance);
- fragTexture += lerp(tex2Dlod(_MainTex, float4(uv.xy, 0.0, 1.0)),
- tex2Dlod(_MainTex, float4(uv.xy, 0.0, 2.0)), 1 - _LodDistance) * step(_LodDistance, dist);
- //
- fixed4 fragColor = lerp(fragTexture * i.color, i.color, dist);
- if(dist > 1)
- fragColor = i.color;
- //> Emission
- //add calculated Emission to vertex colors
- fixed4 emiTexture = tex2Dlod(_EmiMap, float4(uv.xy, 0.0, 0.0));
- fixed4 emiColor = tex2Dlod(_EmiTexture, float4(uv.xy, 0.0, 0.0)).r * _EmiColor;
- emiColor = lerp(emiColor, _EmiColor, dist + 1);
- if(dist > 1)
- emiColor = _EmiColor;
- fragColor.rgb += lerp(0, emiColor.rgb, _EmiVal) * emiTexture.a;
- //> REFLECTION
- // sample the default reflection cubemap, using the reflection vector
- half4 skyData = texCUBE(_RefCubemap, i.worldRefl);
- // decode cubemap data into actual color
- half3 skyColor = lerp(DecodeHDR (skyData, unity_SpecCube0_HDR), 0, dist);
- // get the transparent objects
- fixed4 refTexture = tex2Dlod(_RefMapTex, float4(uv.xy, 0.0, 0.0));
- //
- if(dist > 1)
- skyColor = 0;
- fragColor.rgb += lerp(0, skyColor.rgb, _RefValue) * refTexture.a;
- //> TRANSPARENCY
- fragColor.a =lerp(0, fragColor.a, 1 - _Translucency) * tex2Dlod(_MainTex, float4(uv.xy, 0.0, 0.0)).a;
- //Screen-door transparency: Discard pixel if below threshold.
- float4x4 thresholdMatrix =
- { 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
- 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
- 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
- 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
- };
- float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
- float2 pos = i.screenPos.xy / i.screenPos.w;
- pos *= _ScreenParams.xy; // pixel position
- clip(fragColor.a - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
- //> RESULT
- return fragColor;
- }
- ENDCG
- }
- //> DIRECTIONAL LIGHT
- Pass
- {
- Name "VERTELIT"
- Tags{ "LightMode" = "Vertex" }
- //Blend One One //ZWrite Off
- Blend SrcAlpha OneMinusSrcAlpha //ZWrite Off
- Lighting On
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- //#pragma target 2.0
- #pragma multi_compile_fog
- #pragma multi_compile_fwdbase
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- //> INPUT STRUCT
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- fixed4 color : COLOR0;
- float3 normal : NORMAL;
- };
- //> OUTPUT STRUCT
- struct v2f {
- float4 color : COLOR0;
- float4 pos : SV_POSITION;
- float4 worldSpacePosition : TEXCOORD0;
- float3 uv : TEXCOORD1;
- float4 screenPos : TEXCOORD2;
- SHADOW_COORDS(3)
- float distance : TEXCOORD4;
- };
- uniform float4 _Color;
- //> TEXTURES
- float4 _Player;
- sampler2D _MainTex;
- float4 _MainTex_ST;
- sampler2D _VertexTex;
- sampler2D _VertexTex_ST;
- float _Distortion;
- float _IlumDistance;
- float _IlumStrength;
- float _TranCutOff;
- //> TRANSPARENCY
- uniform float _Translucency;
- //>
- v2f vert(appdata v)
- {
- v2f o;
- //> VERTEX SNAPPING
- // including the line below will tell Unity not to upgrade the matrix mul() operations below...
- // UNITY_SHADER_NO_UPGRADE
- float3 wp = UnityObjectToViewPos (v.vertex);
- o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex);
- wp = floor(wp * _Distortion) / _Distortion;
- //
- float4 sp = mul(UNITY_MATRIX_P, fixed4(wp.xyz,1));
- o.pos = sp;
- //
- float2 uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.uv = float3(uv * sp.w, sp.w);
- o.screenPos = ComputeScreenPos(o.pos);
- //> DISTANCE
- //convert the World Space and calculate distance between vertices and player
- o.worldSpacePosition = floor(o.worldSpacePosition);
- o.distance = distance(o.worldSpacePosition, _Player) / (_IlumDistance);
- //> FINAL COLOR
- o.color = v.color;
- TRANSFER_VERTEX_TO_FRAGMENT(o)
- //TRANSFER_SHADOW(o)
- //> RESULT
- return o;
- }
- //>
- fixed4 frag(v2f i) : SV_Target
- {
- //> SHADING + SHADOWS
- //compute shadow attenuation (1.0 = fully lit, 0.0 = fully shadowed)
- fixed shadow = SHADOW_ATTENUATION(i);
- // darken light's illumination with shadow, keep ambient intact
- fixed4 lighting = shadow;// + i.ambient;
- lighting.a = (1 - shadow);
- //>
- float2 uv = i.uv.xy / i.uv.z;
- half4 color = fixed4(0, 0, 0, 1);// i.color;//fixed4(1,1,1,1);
- color.a = lerp(.2, 1, 1 - i.distance) * _IlumStrength * tex2Dlod(_MainTex, float4(uv.xy, 0.0, 1.0)).a;
- lerp(1, 0, i.distance) * _IlumStrength;
- //> TRANSPARENCY
- if(i.distance > 1)
- color = 0;
- //calculate transparency cutoff
- if(lighting.a < _TranCutOff)
- color = 0.0;
- // Screen-door transparency: Discard pixel if below threshold.
- float4x4 thresholdMatrix = {
- 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
- 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
- 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
- 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
- };
- float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
- float2 pos = i.screenPos.xy / i.screenPos.w;
- pos *= _ScreenParams.xy;
- clip((color.a) - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
- //> FOG
- //UNITY_APPLY_FOG(i.fogCoord, fragColor);
- //> RETURN
- return color;
- }
- ENDCG
- }
- //> VERTEX LIT, emulated in shaders (8 lights max, no specular)
- Pass
- {
- Name "VERTEXLIT"
- Tags{ "LightMode" = "Vertex" }
- //Blend SrcAlpha OneMinusSrcAlpha
- Blend One One
- Lighting Off
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #pragma multi_compile_fog
- #pragma multi_compile_fwdbase
- #include "UnityCG.cginc"
- #include "UnityLightingCommon.cginc" // for _LightColor0
- //> INPUT STRUCT
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- fixed4 color : COLOR0;
- float3 normal : NORMAL;
- };
- //> OUTPUT STRUCT
- struct v2f {
- float4 color : COLOR0;
- float4 pos : SV_POSITION;
- float4 worldSpacePosition : TEXCOORD0;
- float3 uv : TEXCOORD1;
- float4 screenPos : TEXCOORD2;
- float distance : TEXCOORD3;
- };
- uniform float4 _Color;
- //> TEXTURES
- float4 _Player;
- sampler2D _MainTex;
- float4 _MainTex_ST;
- sampler2D _VertexTex;
- sampler2D _VertexTex_ST;
- float _Distortion;
- //> LIGHTING
- float _IlumStrength;
- float _IlumDistance;
- //> TRANSPARENCY
- uniform float _Translucency;
- //>
- v2f vert(appdata v)
- {
- v2f o;
- //> VERTEX SNAPPING
- // including the line below will tell Unity not to upgrade the matrix mul() operations below...
- // UNITY_SHADER_NO_UPGRADE
- float3 wp = UnityObjectToViewPos (v.vertex);
- o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex);
- wp = floor(wp * _Distortion) / _Distortion;
- //
- float4 sp = mul(UNITY_MATRIX_P, fixed4(wp.xyz,1));
- o.pos = sp;
- //
- float2 uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.uv = float3(uv * sp.w, sp.w);
- o.screenPos = ComputeScreenPos(o.pos);
- //> DISTANCE
- //convert the World Space and calculate distance between vertices and player
- o.worldSpacePosition = floor(o.worldSpacePosition);
- o.distance = distance(o.worldSpacePosition, _Player) / (_IlumDistance );
- //> VERTEX LIGHTS
- float3 lighting = float4(ShadeVertexLightsFull(v.vertex, v.normal, 8, true),1);
- o.color.rgb = lighting *.05;
- o.color.a = v.color.a ;//* tex2Dlod(_MainTex, float4(uv.xy, 0.0, 0.0)).a;
- //> RESULT
- return o;
- }
- //>
- fixed4 frag(v2f i) : SV_Target
- {
- float2 uv = i.uv.xy / i.uv.z;
- fixed4 c;
- c = i.color;//* shadow;
- c.a = lerp(1, 0, i.distance) * _IlumStrength * tex2Dlod(_MainTex, float4(uv.xy, 0.0, 1.0)).a;
- // Screen-door transparency: Discard pixel if below threshold.
- float4x4 thresholdMatrix = {
- 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
- 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
- 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
- 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
- };
- float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
- float2 pos = i.screenPos.xy / i.screenPos.w;
- pos *= _ScreenParams.xy;
- clip((c.a) - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
- //> RESULT
- return c;
- }
- ENDCG
- }
- //> SHADOWCASTER PASS
- Pass
- {
- Tags {"LightMode"="ShadowCaster"}
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile_shadowcaster
- #include "UnityCG.cginc"
- #include "UnityShaderVariables.cginc"
- //>
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- fixed4 color : COLOR0;
- float3 normal : NORMAL;
- };
- //>
- struct v2f {
- V2F_SHADOW_CASTER;
- float3 uv : TEXCOORD0;
- float4 screenPos : TEXCOORD1;
- float4 worldSpacePosition : TEXCOORD2;
- float4 color : COLOR0;
- };
- //>
- sampler2D _MainTex;
- float4 _MainTex_ST;
- float _Distortion;
- //>
- v2f vert(appdata v)
- {
- //> STRUCT
- v2f o;
- //>
- //> VERTEX SNAPPING
- // including the line below will tell Unity not to upgrade the matrix mul() operations below...
- // UNITY_SHADER_NO_UPGRADE
- float3 wp = UnityObjectToViewPos (v.vertex);
- wp = floor(wp * _Distortion) / _Distortion;
- //v.vertex = mul(unity_WorldToObject, o.worldSpacePosition);
- TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
- return o;
- }
- //>
- float4 frag(v2f i) : SV_Target
- {
- SHADOW_CASTER_FRAGMENT(i);
- }
- ENDCG
- }
- }
- }
- //FallBack "Legacy Shaders/VertexLit"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement