113 lines
2.8 KiB
Plaintext
113 lines
2.8 KiB
Plaintext
float3 g_vLightDir : register(c1);
|
|
float g_fTime : register(c3);
|
|
|
|
sampler3D randomSampler : register(s0);
|
|
sampler1D diffSampler : register(s2);
|
|
sampler1D specSampler : register(s3);
|
|
sampler2D shadowSampler : register(s4);
|
|
|
|
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_CENTROID;
|
|
float3 w : TEXCOORD4;
|
|
};
|
|
|
|
float3 hslToRgb(float3 color)
|
|
{
|
|
float3 result = 0;
|
|
float h = color.r;
|
|
float s = color.g;
|
|
float l = color.b;
|
|
float q,p;
|
|
if (l < 0.5)
|
|
q = l*(1+s);
|
|
else if (l >= 0.5)
|
|
q = l+s-(l*s);
|
|
p=2*l-q;
|
|
result.r=h+1.0/3.0;
|
|
result.g=h;
|
|
result.b=h-1.0/3.0;
|
|
for (int j = 0; j < 3; ++j)
|
|
{
|
|
if (result[j]<0) result[j] += 1;
|
|
if (result[j]>1) result[j] -= 1;
|
|
}
|
|
for (int i = 0; i < 3; ++i)
|
|
{
|
|
if (result[i]<1.0/6.0)
|
|
result[i]=p+((q-p)*6*result[i]);
|
|
else if (result[i]<0.5)
|
|
result[i]=q;
|
|
else if (result[i]<2.0/3.0)
|
|
result[i]=p+((q-p)*6*(2.0/3.0-result[i]));
|
|
else
|
|
result[i]=p;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
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;
|
|
|
|
float3 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 *= (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) );
|
|
|
|
// Shadow
|
|
float fShadow = 0.2f + 0.8f * (float)tex2Dproj(shadowSampler, i.s);
|
|
|
|
// Diffuse light
|
|
fColor *= 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 += g_fSpecularPower * tex1D(specSampler, fShadow * s).xyz;
|
|
|
|
//return float4(fColor, 1.f);
|
|
|
|
// calculate coloration (hypno toad commands you!)
|
|
float4 plasmaVal = tex3D(randomSampler, g_fTime * 0.001 + t * 0.0025);
|
|
float plasmaPower = saturate((i.w.z - 80) + g_fTime * 15 ) * plasmaVal.a;
|
|
float3 plasmaColor = lerp(1, hslToRgb(1 + plasmaVal.rgb), plasmaPower);
|
|
|
|
return float4(fColor * plasmaColor, 1.f);
|
|
}
|