float4 g_fResolution : register(c0); float3 g_vLightDir : register(c1); float4 g_fTime : register(c3); sampler3D randomSampler : register(s0); sampler2D tex : register(s1); sampler1D diffSampler : register(s2); sampler1D specSampler : register(s3); sampler2D shadowSampler : register(s4); sampler2D depthSampler : register(s5); static float g_fVariation = .1f; static float g_fBumpDepth = .02f; static float g_fBumpFalloff = 256.f; static float g_fTexScale = 1.f; static float g_fSpecularPower = 0.2f; static float g_fSpecularHardness = 32.f; struct psIn { float4 c : COLOR0; float2 t : TEXCOORD0; float3 n : TEXCOORD1; float3 v : TEXCOORD2; float4 s : TEXCOORD3; float3 w : TEXCOORD4; }; float noise(float3 t) { float4 r = tex3D(randomSampler, .03125f * t); float lr = dot(r, float4(1.f, 10.f, 100.f, 1000.f)); return lr * 2.f / 1111.f - 1.f; } float abs_noise(float3 t) { return abs( noise(t) ); } float4 ps_main(psIn i) : COLOR0 { float3 t = i.w * g_fTexScale; float4 fColor = i.c; float fStruct = noise(t) / 2.f; fStruct += noise(4.f * t) / 4.f; fStruct += noise(8.f * t) / 8.f; fStruct += noise(16.f * t) / 16.f; fStruct += noise(32.f * t) / 32.f; fColor.xyz *= (1.f - g_fVariation) + g_fVariation * fStruct; float fDetail = noise(81.f * t) / 2.f; fDetail += noise(243.f * t) / 4.f; fDetail += noise(729.f * t) / 8.f; // Bump mapping // float ddf = g_fBumpFalloff * dot(fwidth(i.w), 1.f); float3 pp = i.w + i.n * g_fBumpDepth * (fStruct + fDetail / 16.f); // (1.f + ddf) float3 ddppx = ddx(pp); float3 ddppy = ddy(pp); float3 n = normalize( cross(ddppx, ddppy) ); // calculate coloration (hypno toad commands you!) float3 wrd= float3( round( i.w.x / g_fTime.w ) * g_fTime.w, round( i.w.y / g_fTime.w ) * g_fTime.w, round( i.w.z / g_fTime.w ) * g_fTime.w ); float fOffset= 33.0f - wrd.z / 8.0f - g_fTime / 56.0f; if( fOffset < 0.0f ) { fOffset= 0.0f; } float plasmaVal = sin( sin ( 0.021f * g_fTime + wrd.y * 0.23f ) * 0.7f + wrd.x * 0.09f ) + sin( 0.009f * g_fTime + sin ( wrd.z * 0.35f ) * 0.9f + wrd.y * 0.47f ) + sin( sin ( 0.013f * g_fTime + wrd.x * 0.17f ) * 1.3f + wrd.z * 0.13f ) + fOffset; if( plasmaVal > 0.0f && plasmaVal < 1.0f ) { fColor.xyz= tex2D( tex, plasmaVal ).xyz; } // Shadow (AA) float2 sc = i.s.xy / i.s.w; float aa = abs( tex2D(depthSampler, sc).x - i.s.z ); float2 ddaa = float2(ddx(aa), ddy(aa)); float2 aaetc = sign(-ddaa) * g_fResolution.zw; sc += aaetc * saturate(4.f * aa); float fShadow = 0.2f + 0.8f * (float)tex2D(shadowSampler, sc); // Diffuse light fColor.xyz *= tex1D( diffSampler, fShadow * (0.5f + 0.5f * dot(n, -g_vLightDir)) ).xyz; // Specular highlights float3 h = normalize( normalize(i.v) + -g_vLightDir ); float s = saturate( dot(n, h) ); fColor.xyz += g_fSpecularPower * tex1D(specSampler, fShadow * s).xyz; return fColor; }