Last active
November 5, 2015 17:05
-
-
Save s2kw/9a0e864f76c6b44a6474 to your computer and use it in GitHub Desktop.
preview:https://vimeo.com/144771829
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "jigaX/Mosaic" { | |
Properties { | |
_Color ("Color", Color) = (1,1,1,1) | |
_MainTex ("Albedo (RGB)", 2D) = "white" {} | |
_SnapVal("Threashold", Range(0,1)) = 1 | |
} | |
SubShader { | |
Pass{ | |
Tags { "RenderType"="Opaque" } | |
LOD 200 | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
uniform float _SnapVal; | |
uniform sampler2D _MainTex; | |
uniform float4 _LightColor0; | |
uniform float4 _Color; | |
struct v2f { | |
float4 position : SV_POSITION; | |
fixed4 color : COLOR; | |
float2 uv : TEXCOORD0; | |
}; | |
v2f vert( appdata_full v:POSITION ) : SV_POSITION{ | |
float4 tmpV = mul ( UNITY_MATRIX_MV, v.vertex ); | |
float x = tmpV.x - ( tmpV.x % _SnapVal ); | |
float y = tmpV.y - ( tmpV.y % _SnapVal ); | |
float z = tmpV.z - ( tmpV.z % _SnapVal ); | |
float w = tmpV.w - ( tmpV.w % _SnapVal ); | |
tmpV = float4( x, y, z, w ); | |
tmpV = mul (UNITY_MATRIX_P, tmpV); | |
v2f o; | |
o.position = tmpV; | |
// diffuse color | |
float4 normalDirection = mul( UNITY_MATRIX_MVP, float4( v.normal, 0.0) ); | |
float3 surfaceNormal = normalize( normalDirection ); | |
float3 lightDirectionNormal = normalize(float3(_WorldSpaceLightPos0)); | |
float halfLambert = max(0.0, dot(surfaceNormal, lightDirectionNormal)) * 0.5 + 0.5; | |
float3 diffuseReflection = float3(_LightColor0) * float3(_Color) * halfLambert * halfLambert; | |
float4 color = float4(diffuseReflection, 1.0); | |
o.color = color;//v.color; | |
o.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord); | |
return o; | |
} | |
float4 frag(v2f i) : COLOR { | |
return i.color; | |
} | |
ENDCG | |
} | |
} | |
//FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment