Code Monkey home page Code Monkey logo

raytracer's Introduction

An OpenCL raytracer

Usage

python clray.py scenes/scene-dev.py

(see python clray.py -h)

Requirements

  • Python (2.7)
  • pyopencl (>= 2012), tested with 2012.1, 2013.2, 2014.1, 2016.2
  • Mako (for pyopencl)
  • jinja2
  • numpy, scipy
  • sympy (for implicit surfaces)
  • for visualization: sdl2 (default, needs libsdl2-dev) or pygame. To use Pygame, enable it in imgutils.py

showcase

Installation

See https://wiki.tiker.net/PyOpenCL/Installation for a more comprehensive guide on installing OpenCL and PyOpenCL.

Notice that GPU-accelerated libraries almost never work out-of-the-box. The recommended steps and the encountered problems depend on your OS version, hardware configuration and the yearly planetary aligment. My astrological tip for CUDA on Linux is to avoid the Debian-packaged drivers and to download the evil proprietary ones from the Nvidia website, which, however, has a high risk of breaking any graphical desktop environment you might be using.

Here is an example how to get AMD's CPU version of OpenCL running on Debian Jessie in October 2016 (less likely to break things):

  1. Install OpenCL like this

    sudo aptitude install amd-libopencl1 amd-opencl-icd opencl-headers amd-opencl-dev
    
  2. Then install PyOpenCL, Mako etc. with pip (which itself is often broken)

    export LC_ALL=C # can fix problems with pip
    sudo pip install pyopencl Mako sympy jinja2
    sudo pip install sdl2 # if using PySDL2 for default visualization
    
  3. Install numpy, scipy and SDL (or Pygame) using the package manager

    sudo aptitude install python-numpy python-scipy
    sudo aptitude install libsdl2-dev # for default PySDL2 visualizations
    sudo aptitude install python-pygame # for pygame visualizations
    

raytracer's People

Contributors

oseiskar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

raytracer's Issues

error when running python clray.py scenes/scene-test.py

I am running with pyopencl with version 2014.1. Here is the error output truncated.

reading OFF with 8 points and 6 faces
constructed 12 triangles
auto-scaling to 40.0%
reading OFF with 8 points and 6 faces
constructed 12 triangles
auto-scaling to 40.0%
reading OFF with 8 points and 6 faces
constructed 12 triangles
auto-scaling to 40.0%
generating normals for 8 vertices
8 vertices
reading OFF with 8 points and 6 faces
constructed 12 triangles
auto-scaling to 40.0%
depth: 0 active nodes: 1 total leaves: 1 active faces: 12
Traceback (most recent call last):
  File "clray.py", line 61, in <module>
    renderer = renderer.Renderer(scene, args)
  File "/Users/xiaruhao/Documents/CS184/raytracer-master/renderer.py", line 49, in __init__
    self.prog = self.acc.build_program(program_code, args.cl_build_options)
  File "/Users/xiaruhao/Documents/CS184/raytracer-master/accelerator.py", line 49, in build_program
    self.prog = cl.Program(self.ctx, prog_code).build(options)
  File "/Users/xiaruhao/anaconda/lib/python2.7/site-packages/pyopencl/__init__.py", line 209, in build
    options=options, source=self._source)
  File "/Users/xiaruhao/anaconda/lib/python2.7/site-packages/pyopencl/__init__.py", line 249, in _build_and_catch_errors
    raise err
pyopencl.RuntimeError: clBuildProgram failed: build program failure - 

Build on <pyopencl.Device 'Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz' on 'Apple' at 0xffffffff>:

<program source>:27:9: warning: no previous prototype for function 'ia_mul'
ia_type ia_mul(ia_type a, ia_type b)
        ^
<program source>:47:9: warning: no previous prototype for function 'ia_pow2'
ia_type ia_pow2(ia_type a)
        ^
<program source>:53:9: warning: no previous prototype for function 'ia_pow3'
ia_type ia_pow3(ia_type a)
        ^
<program source>:58:9: warning: no previous prototype for function 'ia_pow4'
ia_type ia_pow4(ia_type a)
        ^
<program source>:67:8: warning: no previous prototype for function 'apply_linear_transform'
float3 apply_linear_transform(constant const float4 *p_matrix, float3 vector) {
       ^
<program source>:74:8: warning: no previous prototype for function 'apply_transposed_linear_transform'
float3 apply_transposed_linear_transform(constant const float4 *p_matrix, float3 vector) {
       ^
<program source>:81:8: warning: no previous prototype for function 'apply_affine_transform'
float3 apply_affine_transform(constant const float4 *p_mat_and_vec, float3 vector) {
       ^
<program source>:88:8: warning: no previous prototype for function 'quaternion_mult'
float4 quaternion_mult( float4 q1, float4 q2 )
       ^
<program source>:96:8: warning: no previous prototype for function 'quaternion_square'
float4 quaternion_square( float4 q )
       ^
<program source>:256:42: error: Cannot downconvert and widen scalar type 'double' to vector type '__float3'
            r = normalize(gauss_rvec + r * tan(M_PI*0.5*(1.0 - blur)));
                                       ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
<program source>:350:12: warning: unused variable 'n'
    float3 n = *normal;
           ^
<program source>:352:12: warning: unused variable 'gauss_rvec'
    float3 gauss_rvec = rvecs_cmask_and_light[1].xyz;
           ^
<program source>:351:18: warning: unused variable 'rvec'
    const float3 rvec = rvecs_cmask_and_light[0].xyz;
                 ^
<program source>:355:12: warning: unused variable 'cur_col'
    float3 cur_col;
           ^
<program source>:354:11: warning: unused variable 'cur_prob'
    float cur_prob = 0.0;
          ^
<program source>:362:52: warning: comparison of integers of different signs: '__global uint' (aka '__global unsigned int') and 'const int'
        if ((suppressed >= 0 && *surface_object_id != suppressed) || *surface_object_id == -suppressed)
                                ~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~
<program source>:362:89: warning: comparison of integers of different signs: '__global uint' (aka '__global unsigned int') and 'int'
        if ((suppressed >= 0 && *surface_object_id != suppressed) || *surface_object_id == -suppressed)
                                                                     ~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~
<program source>:469:49: error: Cannot downconvert and widen scalar type 'double' to vector type '__float3'
            r = normalize(gauss_rvec * blur + r * (1.0-blur));
                                              ~ ^ ~~~~~~~~~~
<program source>:621:49: error: Cannot downconvert and widen scalar type 'double' to vector type '__float3'
            r = normalize(gauss_rvec * blur + r * (1.0-blur));
                                              ~ ^ ~~~~~~~~~~
<program source>:747:29: error: Cannot downconvert and widen scalar type 'double' to vector type '__float3'
                            * (*ray_color) * (*pipeline_color) * cmask
                            ^ ~~~~~~~~~~~~
<program source>:767:25: error: Cannot downconvert and widen scalar type 'double' to vector type '__global __float3'
        *pipeline_color *= 2.0 * dot(n,r);
        ~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
<program source>:769:26: error: Cannot downconvert and widen scalar type 'double' to vector type '__global __float3'
    else *pipeline_color *= 0.0;
         ~~~~~~~~~~~~~~~ ^  ~~~
<program source>:1519:57: error: Cannot downconvert and widen scalar type 'double' to vector type 'float __attribute__((ext_vector_type(2)))'
    f = ia_pow2(qr)+ia_pow2(qi)+ia_pow2(qj)+ia_pow2(qk) - 4.0;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~
<program source>:1582:9: warning: unused variable 'qr1'
                float qr1;
        ^

pygame issue

Hi I was trying to run the raytracer - the program is running but pygame window never showed up. Have you ever encountered this issue? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.