Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // some badass macro magic for both dx9+ and gl3+ support
- #ifdef SM4
- #define TECH(n,v,p) \
- technique n { pass { VertexShader = compile vs_4_0_level_9_3 v (); PixelShader = compile ps_4_0_level_9_3 p (); }}
- #else
- #define TECH(n,v,p) \
- technique n { pass { VertexShader = compile vs_2_0 v (); PixelShader = compile ps_3_0 p (); }}
- #endif
- float3 LightPosition = float3(-100, 100, -100);
- float3 CameraPosition;
- float4x4 View;
- float4x4 Projection;
- float4x4 World;
- float3 BaseColor;
- struct VertexShaderInput
- {
- float4 Position : POSITION;
- float2 Texcoord : TEXCOORD0;
- float3 Normal : NORMAL0;
- };
- struct VertexShaderOutput
- {
- float4 Position : POSITION;
- float2 Texcoord : TEXCOORD0;
- float3 ViewDirection : TEXCOORD1;
- float3 LightDirection : TEXCOORD2;
- float3 Normal : TEXCOORD3;
- };
- VertexShaderOutput VertexShaderFunction( VertexShaderInput Input )
- {
- VertexShaderOutput Output;
- float4x4 vp = mul(View, Projection);
- Output.Position = mul( Input.Position, mul(World, vp) );
- Output.Texcoord = Input.Texcoord;
- float3 ObjectPosition = mul( Input.Position, View ).xyz;
- Output.ViewDirection = CameraPosition - ObjectPosition;
- Output.LightDirection = LightPosition - ObjectPosition;
- Output.Normal = (mul( Input.Normal, View )).xyz;
- return( Output );
- }
- float4 fvAmbient = float4(.3686, .3686, .3686, 1.0);
- float4 fvSpecular = float4(.4902, .4902, .4902, 1.0);
- float4 fvDiffuse = float4(.8863, .8863, .8863, 1.0);
- float fSpecularPower = 25;
- struct PS_INPUT
- {
- float2 Texcoord : TEXCOORD0;
- float3 ViewDirection : TEXCOORD1;
- float3 LightDirection: TEXCOORD2;
- float3 Normal : TEXCOORD3;
- };
- float u_time;
- float2 u_resolution;
- float2 random2(float2 st){
- st = float2( dot(st,float2(127.1,311.7)),
- dot(st,float2(269.5,183.3)) );
- return -1.0 + 2.0*frac(sin(st)*43758.5453123);
- }
- float noise(float2 st) {
- float2 i = floor(st);
- float2 f = frac(st);
- float2 u = f*f*(3.0-2.0*f);
- return lerp(lerp( dot( random2(i + float2(0.0,0.0) ), f - float2(0.0,0.0) ),
- dot( random2(i + float2(1.0,0.0) ), f - float2(1.0,0.0) ), u.x),
- lerp( dot( random2(i + float2(0.0,1.0) ), f - float2(0.0,1.0) ),
- dot( random2(i + float2(1.0,1.0) ), f - float2(1.0,1.0) ), u.x), u.y);
- }
- float2 toPolar(float2 src){
- return float2( atan(src.x / src.y), length(src) );
- }
- float4 mc(float2 tex) {
- float2 st = toPolar( tex.xy );
- st.x *= u_resolution.x/u_resolution.y;
- float3 color = float3(0,0,0);
- float t = 1.0;
- // Uncomment to animate
- t = abs(1-sin(u_time*.125))*5;
- // Comment and uncomment the following lines:
- st += noise(st*2.)*t; // Animate the coordinate space
- color = float3(1,1,1) * smoothstep(.18,.2,noise(st)); // Big black drops
- color += smoothstep(.15,.2,noise(st*10.)); // Black splatter
- color -= smoothstep(.35,.4,noise(st*10.)); // Holes on splatter
- color = BaseColor - color;
- return float4(color.x, color.y, color.z,1.0);
- }
- float4 PixelShaderFunction( PS_INPUT Input ) : COLOR0
- {
- float3 fvLightDirection = normalize( Input.LightDirection );
- float3 fvNormal = normalize( Input.Normal );
- float fNDotL = dot( fvNormal, fvLightDirection );
- float3 fvReflection = normalize( ( ( 2.0f * fvNormal ) * ( fNDotL ) ) - fvLightDirection );
- float3 fvViewDirection = normalize( Input.ViewDirection );
- float fRDotV = max( 0.0f, dot( fvReflection, fvViewDirection ) );
- float4 fvBaseColor = mc( Input.Texcoord );
- float4 fvTotalAmbient = fvAmbient * fvBaseColor;
- float4 fvTotalDiffuse = fvDiffuse * fNDotL * fvBaseColor;
- float4 fvTotalSpecular = fvSpecular * pow( fRDotV, fSpecularPower );
- return( saturate( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular ) );
- }
- TECH(texturer, VertexShaderFunction, PixelShaderFunction)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement