1. Homepage
  2. Programming
  3. CUDA Lab 6. A simple CUDA ray caster - Mandelbrot and Julia Sets

CUDA Lab 6. A simple CUDA ray caster - Mandelbrot and Julia Sets

Engage in a Conversation
C++CUDAMandelbrot setJulia Set

  CourseNana.COM

CUDA Lab 6. A simple CUDA ray caster CourseNana.COM

1. Understand how to draw simple image in CUDA CourseNana.COM

2. Understand how to draw Mandelbrot and Julia Sets. CourseNana.COM

  CourseNana.COM

Exercise 1. Set up a virtual canvas and draw on it an image in CUDA CourseNana.COM

1. The lab descriptions shown below are based on the start programs “Drawing_cuda.cpp” _and “Drawing _cuda.cu”, simple to the framework provided in Lab 4, which are created directly from CUDA SDK sample “bicubicTexture”. Start from your work on Lab 4 and replace “I_m_a_g_e_P_r_o_c_e_s_s___c_u_d_a_._c_p_p_” _a_n_d_ _“I_m_a_g_e_P_r_o_c_e_s_s___c_u_d_a_._c_u_” _with “Drawing_cuda.cpp” _and “Drawing _cuda.cu”. CourseNana.COM

  CourseNana.COM

2. Compile your program, you should see a red image. CourseNana.COM

  CourseNana.COM

3. Modify the first three values shown in make_uchar4( ) in the following line of code to draw an image of different colours, say, a green image, a grey image. CourseNana.COM

  CourseNana.COM

d_output[i] = make_uchar4(0, 0, 0xff, 0); CourseNana.COM

  CourseNana.COM

Exercise 2. Drawing a checkboard in CUDA CourseNana.COM

1. Edit the d_render( ) method to draw an checkboard image shown below. CourseNana.COM

  CourseNana.COM

You can get an idea of how to draw it by refer to the void makeCheckImage(void) method provided from the link: CourseNana.COM

https://www.glprogramming.com/red/chapter09.html CourseNana.COM

  CourseNana.COM

2. Modify you code to draw a checkboard with much larger red-blocks, as shown below CourseNana.COM

  CourseNana.COM

3. Further modify your code to draw a red disc in the middle of the image of a red disc: CourseNana.COM

4. Redraw the above image based on pixel coordinates defined in float type variables in [-1, 1]x[-1, 1], as is shown below. CourseNana.COM

  CourseNana.COM

This can be done by performing transformation to (x, y) coordinates (screen space pixel location) in the following way. CourseNana.COM

  CourseNana.COM

float u = x / (float)width; CourseNana.COM

float v = y / (float)height; CourseNana.COM

u =2.0*u- 1.0; CourseNana.COM

v = -(2.0*v - 1.0); CourseNana.COM

  CourseNana.COM

To avoid distortion to the image when resizing, it is better to make the image has the same aspect ratio as the window. This can be achieved by scaling u-coordinate using the window aspect ratio: CourseNana.COM

u *= width / (float)height; CourseNana.COM

Now draw the red disc using the (u,v) coordinates. CourseNana.COM

  CourseNana.COM

a) Both the Mandelbrot set and the Julia set are famous 2D fractal objects initially defined based on complex number z=x+yi, by considering iteratively calculating a sequence of complex numbers from b) In a), for each point (u, v), the 2D vector T is defined with the start coordinates (u, v). If you replace it with vector independent of (u,v), say, T = {0.25, 0.5}, we can get a Julia set shown below. Different Ts give different Julia sets. Thus, in general, there are infinite different Julia sets. CourseNana.COM

  CourseNana.COM

Exercise 3. Drawing the Mandelbrot and Julia Sets. CourseNana.COM

Z0=x+y*i, CourseNana.COM

Zn+1=zn2+C, n_=_1_,_ _2_,_ _3_,_ _… _…,_ _ CourseNana.COM

where C is a constant complex number. Mandelbrot and Julia sets are defined as sets of those complex numbers such that the sequence of complex numbers from each of these complex numbers never goes to infinity. CourseNana.COM

For z= x+yi, if we regard it as a point in an image with coordinates(x, y), then z2 corresponds to a point with coordinates (x2-y2, 2*x*y). Thus, we can directly visualize these fractals in CUDA. CourseNana.COM

Scale the image size you used in Exercise 2 to a relatively bigger size, say, [-4, 4]x[-4, 4]. You can easily achieve this by multiplying u and v with 4: CourseNana.COM

u *=4.0; v *=4.0; CourseNana.COM

Now regard each (u, v) as a complex number u+v*i, we can visualize what Mandelbrot set by modifying the code you achieved in exercise 2 in the following way: CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
C++代写,CUDA代写,Mandelbrot set代写,Julia Set代写,C++代编,CUDA代编,Mandelbrot set代编,Julia Set代编,C++代考,CUDA代考,Mandelbrot set代考,Julia Set代考,C++help,CUDAhelp,Mandelbrot sethelp,Julia Sethelp,C++作业代写,CUDA作业代写,Mandelbrot set作业代写,Julia Set作业代写,C++编程代写,CUDA编程代写,Mandelbrot set编程代写,Julia Set编程代写,C++programming help,CUDAprogramming help,Mandelbrot setprogramming help,Julia Setprogramming help,C++assignment help,CUDAassignment help,Mandelbrot setassignment help,Julia Setassignment help,C++solution,CUDAsolution,Mandelbrot setsolution,Julia Setsolution,