Fur shader

Just finished porting Fur shader to shaderlab.
It was an easy one, and I’m pretty sure that I’ve done it 100% right, although I might have made a mistake somewhere so you might want to read through it.

I’m not quite sure how to use it properly lol, I tried attaching it to a sphere, and even though the shader works fine and has some decent effect, I can’t seem to understand why it’s called “Fur shader” because it doesn’t do anything fur-ish :smile:

Maybe I just don’t know how to use it properly, tell me if you manage to get anything interesting out of it :slight_smile:

Shader "Edvinas/FurShader" {
	Properties {
		s_diffuse_texture("g_diffuse_texture", 2D) = "white" {}
		s_detail_texture("g_detail_texture", 2D) = "white" {}
		g_layer("g_layer", Float) = 1.0
		g_fur_current_length("g_fur_current_length", Float) = 1.0
		light_colour("light_color", Color) = (1,1,1)
			
		g_wind_direction("g_wind_direction", Float) = 1.0
		g_wind_magnitutde("g_wind_magnitutde", Float) = 1.0
		g_wind_speed("g_wind_speed", Float) = 1.0
		g_wind_fizzling("g_wind_fizzling", Float) = 1.0
			
		_Cutoff ("Alpha cutoff", Range (0,1)) = 0.5
		
	}
	
	SubShader {
Pass {

Cull Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest Greater [_Cutoff]
	
CGPROGRAM


#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"


	sampler2D s_detail_texture;
	sampler2D s_diffuse_texture;

	
	float g_layer;
	float g_fur_current_length;
	
	float2 g_wind_direction;
	float g_wind_magnitutde;
	float2 g_wind_speed;
	float g_wind_fizzling;
	
	float3 light_colour;
	
	float3 directional_lighting_colour(float3 normal, float3 light_dir)
{
	return light_colour * saturate(dot(light_dir, normal));		

}

struct v2f
{
	float4	position	: POSITION;
	float3	normal		: TEXCOORD0;
	float2	texcoord_uv	: TEXCOORD1;	
};




v2f vert ( appdata_base v) {
appdata_tan n;
v2f r;

  //r.position = mul(glstate.matrix.mvp, v.vertex);
  float4 pos = v.vertex;
	
	float fur_length		= float(float(g_layer + 1) / 30.0f);
	float fur_length_scalar = 0.8;
	pos.xyz					+= (v.normal * fur_length);
	
// now apply the wind effect
	//g_dir					= mul(g_dir, g_world);
	float k					= pow(fur_length , g_wind_fizzling);
	//float k					= pow(fur_length , 3);
	pos.xz					+= k * g_wind_direction;
	r.position				= mul(glstate.matrix.mvp, pos);
	// pass the normal
	r.normal				= v.normal;
	
	// pass the texture coordinates as is
	r.texcoord_uv			= v.texcoord * 20;
	
  return r;

}

float4 frag (v2f v) : COLOR {
	
	// read the pixels from the samplers
    float4 diffuse_pixel 	= tex2D(s_diffuse_texture, v.texcoord_uv);
    float4 detail_pixel		= tex2D(s_detail_texture, v.texcoord_uv);
    
    // Detail Mapping
    diffuse_pixel.rgb 		= lerp(diffuse_pixel.rgb, detail_pixel.rgb, detail_pixel.a);

    // calculate diffuse color
    detail_pixel.rgb 		*= directional_lighting_colour(v.normal.rgb, light_colour);
   
   	float4 finalcolor 		= float4(detail_pixel.rgb,diffuse_pixel.a);
    //finalcolor 			= float4(diffuse_pixel.rgb + glstate.lightmodel.ambient,diffuse_pixel.a);
  	//finalcolor 			= float4(diffuse_pixel.rgb, diffuse_pixel.a);
	//finalcolor 			= float4(normal_pixel.rgb, diffuse_pixel.a);
	//finalcolor 			= float4(v.normal.rgb, diffuse_pixel.a);
	
 	return finalcolor;

}

ENDCG

}

	} 

}

Thanks

Where did you port this from?

Hmm this is an Old thread, but honestly i haven’t read this yet. Is anyone tried it already?