Git Product home page Git Product logo

vray's Introduction

vray

Description

vray is a simple ray tracer program, written only in vlang, based entirely off of Ray Tracing in One Weekend by Peter Shirley, Trevor David Black and Steve Hollasch.

This program is an exercise (more like an excuse really) for me to learn vlang the hardway, and what better way than to reimplement an existing project written in another language (C++ in this case).

What is vlang?

Check out vlang here (GitHub here). It's a general purpose programming language that is heavily inspired by C and Go.

Tested on

  • This has been tested to compile and ran on Windows and Linux, using the following vlang version
    • V 0.4.2 140c838, timestamp: 2023-11-06 12:24:58 +0200
  • Untested on macOS, but it should work~

Progress

Sample Output

NOTE: This program outputs a .ppm image file. Please use a valid PPM image viewer or convert said image to PNG/JPG for viewing. The output.png file in this repo is only meant for displaying in this README.

  • Arguments used for this sample: 1280 720 500 50

Changes

  • Entire project is re-written in vlang, without any dependencies other than vlang's own builtin modules (essentially its standard library).

  • Most if not all algorithms used are kept the same, just rewritten in V instead.

    • There are a small handful of functions used in the book that I do not agree with when it comes to its implementation, so minor changes have been applied with performance in mind.

Usage

Once vlang has been setup for you, checkout this repo and run the following command in the root directory. It should not produce any warnings

v run .

You can specify the output image width, height, iteration sample and depth count by appending the arguments after the above command. Eg.

v run . 512 288 500 50

The default values for the arguments are used if none are specified

  • width: 512
  • height: 288
  • sample: 500
  • depth: 50

To build an executable, run the following command

v -prod .

The -prod flag indicates production mode, meaning the executable will not be built with TCC, leading to a more optimized bytecode. You can then run the executable with the same arguments by running

./vray . 512 288 500 50

Generating C code

vlang has a feature where it can generate the C code that will be used for compilation, you can get it by running the following command in the root directory. Do note that

v . -o vray.c

vray's People

Contributors

lamweilun avatar

Stargazers

Isaiah avatar

Watchers

 avatar

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.