Skip to content

Instantly share code, notes, and snippets.

@eoger
Created February 23, 2014 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eoger/9167203 to your computer and use it in GitHub Desktop.
Save eoger/9167203 to your computer and use it in GitHub Desktop.
Shader "Curved Bumped Specular" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Curvature ("Curvature", Float) = 0.001
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
CGPROGRAM
#pragma surface surf BlinnPhong vertex:vert
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;
float _Curvature;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};
// This is where the curvature is applied
void vert( inout appdata_full v)
{
// Transform the vertex coordinates from model space into world space
float4 vv = mul( _Object2World, v.vertex );
// Now adjust the coordinates to be relative to the camera position
vv.xyz -= _WorldSpaceCameraPos.xyz;
// Reduce the y coordinate (i.e. lower the "height") of each vertex based
// on the square of the distance from the camera in the z axis, multiplied
// by the chosen curvature factor
vv = float4( 0.0f, (vv.z * vv.z) * - _Curvature, 0.0f, 0.0f );
// Now apply the offset back to the vertices in model space
v.vertex += mul(_World2Object, vv);
}
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
FallBack "Specular"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment