Julia Set
This sample draws an animated julia set in real time using the fragment shader for the computation.
// The 4x4 world view projection matrix. float4x4 worldViewProjection : WORLDVIEWPROJECTION; // The seed for the julia set (c in the expression z(n+1) = z(n)^2+c). float2 seed; // input parameters for our vertex shader struct VertexShaderInput { float4 position : POSITION; float2 texCoord : TEXCOORD0; }; // input parameters for our pixel shader // also the output parameters for our vertex shader struct PixelShaderInput { float4 position : POSITION; float2 texCoord : TEXCOORD0; }; /** * vertexShaderMain - our vertex shader for the julia set texture */ PixelShaderInput vertexShaderMain(VertexShaderInput input) { PixelShaderInput output; output.position = mul(input.position, worldViewProjection); output.texCoord = 4.0 * (input.texCoord - float2(0.5, 0.5)); return output; } /** * pixelShaderMain - pixel shader does nothing but return whatever * color it was given. */ float4 pixelShaderMain(PixelShaderInput input) : COLOR { float2 Z = input.texCoord; for(int i = 0; i < 11; ++i) Z = float2(Z.x * Z.x - Z.y * Z.y, 2.0 * Z.x * Z.y) + seed; // Some video hardware has trouble coping with floats of large magnitude, // so we explicitly clamp and return black here, instead of relying on // the correct pixel clamping behaviour. float l = length(Z); if (l > 1.0E10) { return float4(0.0, 0.0, 0.0, 1.0); } else { return (1 - l) * float4(0.5, 1, 2, 1); } } // Here we tell our effect file *which* functions are // our vertex and pixel shaders. // #o3d VertexShaderEntryPoint vertexShaderMain // #o3d PixelShaderEntryPoint pixelShaderMain // #o3d MatrixLoadOrder RowMajor