2 * Copyright 1993-2012 NVIDIA Corporation. All rights reserved.
4 * Please refer to the NVIDIA end user license agreement (EULA) associated
5 * with this source code for terms and conditions that govern your use of
6 * this software. Any use, reproduction, disclosure, or distribution of
7 * this software and related documentation outside the terms of the EULA
8 * is strictly prohibited.
12 // Simple implementation of Mandelbrot set from Wikipedia
13 // http://en.wikipedia.org/wiki/Mandelbrot_set
15 // Note that this kernel is meant to be a simple, straight-forward
16 // implementation, and so may not represent optimized GPU code.
19 void mandelbrot(float* Data) {
22 unsigned DataX = blockIdx.x * blockDim.x + threadIdx.x;
23 unsigned DataY = blockIdx.y * blockDim.y + threadIdx.y;
24 unsigned Width = gridDim.x * blockDim.x;
25 unsigned Height = gridDim.y * blockDim.y;
29 // Scale coordinates to (-2.5, 1) and (-1, 1)
31 float NormX = (float)DataX / (float)Width;
35 float NormY = (float)DataY / (float)Height;
46 unsigned MaxIter = 1000;
49 while(X*X + Y*Y < 4.0f && Iter < MaxIter) {
50 float XTemp = X*X - Y*Y + X0;
58 unsigned ColorG = Iter % 50;
59 unsigned ColorB = Iter % 25;
62 G = (float)ColorG / 50.0f;
63 B = (float)ColorB / 25.0f;
66 Data[DataY*Width*4+DataX*4+0] = R;
67 Data[DataY*Width*4+DataX*4+1] = G;
68 Data[DataY*Width*4+DataX*4+2] = B;
69 Data[DataY*Width*4+DataX*4+3] = A;