Hi,
I’m trying to implemenent the Nautilus shader from shaderToy website. It compile without problem but I can only see weird glitch effect on the renderer and I have no idea where to look at but I feel it’s like a camera or point of view problem.
If you can help me here is the code :
float4x4 tW: WORLD;
float4x4 tV: VIEW;
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;
texture Tex <string uiname="Texture";>;
sampler Samp = sampler_state
{
Texture = (Tex);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
float4x4 tTex: TEXTUREMATRIX <string uiname="Texture Transform";>;
float time <string uiname="Time";>;
float2 res <string uiname="resolution";>;
float e(float3 c)
{
c = cos(float3(cos(c.r+time/6.0)*c.r-cos(c.g*3.0+time/5.0)*c.g, cos(time/4.0)*c.b/3.0*c.r-cos(time/7.0)*c.g, c.r+c.g+c.b+time));
return dot(c*c, float3(1.0, 1.0, 1.0))-1.0;
}
struct vs2ps
{
float4 Pos : POSITION;
float2 TexCd : TEXCOORD0;
};
vs2ps VS(
float4 PosO : POSITION,
float4 TexCd : TEXCOORD0)
{
vs2ps Out;
Out.Pos = mul(PosO, tWVP);
Out.TexCd = mul(TexCd, tTex);
return Out;
}
float4 PS(vs2ps In): COLOR
{
float2 c= -1.0+2.0*In.TexCd/res.xy;
float3 o= float3(c.r,c.g, 0.0), g= float3(c.r,c.g,1.0)/64.0, v = float3(0.1, 0.1, 0.1);
float m = -0.5;
for (int r=0; r<100; r++)
{
float h = e (o)-m;
if (h<0.0) break;
o+=h*10.0*g;
v+=h*0.02;
}
v+=e(o+0.1)*float3(0.7, 0.7, 1.0);
float a = 0.0;
for (int q=0; q<100; q++)
{
float l = e(o+0.5*float3(cos(1.1*float (q)), cos(1.6*float (q)), cos(1.4*float (q))))-m;
a+=clamp(4.0*l, 0.0, 1.0);
}
//v*=a/100.0;
v*=a/100.0;
return float4 (v,1.0);
}
technique TSimpleShader
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_3_0 PS();
}
}