diff --git a/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj b/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj index 4515c57..573d64f 100755 --- a/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj +++ b/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj @@ -25,6 +25,8 @@ + + @@ -75,7 +77,7 @@ - + @@ -196,10 +198,11 @@ $(ProjectDir)$(Platform)/$(Configuration)/%(Filename)%(Extension).obj C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;C:/ProgramData/NVIDIA Corporation/CUDA Samples/v5.5/common/inc;../shared/glew/includes;../shared/freeglut/includes + compute_10,sm_10 - + - + \ No newline at end of file diff --git a/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.filters b/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.filters index d49ad9c..6a3ce76 100755 --- a/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.filters +++ b/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.filters @@ -30,6 +30,8 @@ stb_image + + diff --git a/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.user b/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.user index dfd9f6c..f1c81fe 100755 --- a/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.user +++ b/PROJ1_WIN/565Pathtracer/565Pathtracer.vcxproj.user @@ -13,7 +13,7 @@ WindowsLocalDebugger - scene=../../scenes/sampleScene.txt + scene=../../scenes/sampleScene.txt frame=0 mblur=0 dof=0 WindowsLocalDebugger - + \ No newline at end of file diff --git a/README.md b/README.md index 1e36dc5..41e82be 100755 --- a/README.md +++ b/README.md @@ -1,24 +1,17 @@ ------------------------------------------------------------------------------- -CIS565: Project 2: CUDA Pathtracer -------------------------------------------------------------------------------- -Fall 2013 -------------------------------------------------------------------------------- -Due Wednesday, 10/02/13 +CUDA Pathtracer ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -NOTE: -------------------------------------------------------------------------------- -This project requires an NVIDIA graphics card with CUDA capability! Any card after the Geforce 8xxx series will work. If you do not have an NVIDIA graphics card in the machine you are working on, feel free to use any machine in the SIG Lab or in Moore100 labs. All machines in the SIG Lab and Moore100 are equipped with CUDA capable NVIDIA graphics cards. If this too proves to be a problem, please contact Patrick or Liam as soon as possible. ------------------------------------------------------------------------------- INTRODUCTION: ------------------------------------------------------------------------------- -In this project, you will extend your raytracer from Project 1 into a full CUDA based global illumination pathtracer. +This is an implementation of path tracing rendering algorithm on the GPU, using CUDA. -For this project, you may either choose to continue working off of your codebase from Project 1, or you may choose to use the included basecode in this repository. The basecode for Project 2 is the same as the basecode for Project 1, but with some missing components you will need filled in, such as the intersection testing and camera raycasting methods. +Path tracing is considered to be the best known solution to the classic rendering equation. -How you choose to extend your raytracer into a pathtracer is a fairly open-ended problem; the supplied basecode is meant to serve as one possible set of guidelines for doing so, but you may choose any approach you want in your actual implementation, including completely scrapping the provided basecode in favor of your own from-scratch solution. +The scary looking integral in the rendering equation is approximated beautifully by Monte Carlo sampling which also implies that in order to reduce our approximation errors, we need to take a really large number of samples. ------------------------------------------------------------------------------- CONTENTS: @@ -26,8 +19,8 @@ CONTENTS: The Project2 root directory contains the following subdirectories: * src/ contains the source code for the project. Both the Windows Visual Studio solution and the OSX makefile reference this folder for all source; the base source code compiles on OSX and Windows without modification. -* scenes/ contains an example scene description file. -* renders/ contains two example renders: the raytraced render from Project 1 (GI_no.bmp), and the same scene rendered with global illumination (GI_yes.bmp). +* scenes/ contains some example scene files that were used to create the renders which can be found in the "renders/" subdir +* renders/ contains a few renders showcasing the abilities of my path tracer * PROJ1_WIN/ contains a Windows Visual Studio 2010 project and all dependencies needed for building and running on Windows 7. * PROJ1_OSX/ contains a OSX makefile, run script, and all dependencies needed for building and running on Mac OSX 10.8. * PROJ1_NIX/ contains a Linux makefile for building and running on Ubuntu @@ -37,111 +30,227 @@ The Project2 root directory contains the following subdirectories: - PATH=$PATH:/usr/local/cuda-5.5/bin - LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64:/lib -The projects build and run exactly the same way as in Project0 and Project1. +------------------------------------------------------------------------------- +FEATURES: +------------------------------------------------------------------------------- +Path tracing lends itself naturally to a lot of generally "sought" after features in rendering. +We can implement these features at almost no extra cost. The following is the list of features of my path tracer. + +Features that you get for free with path tracing +* Supersampling +* Area lighting and soft shadows +* Full global illumination + +Features that I implemented additionally +* Stream compaction on the GPU +* A generic BRDF model that supports diffuse, specular and transmittive surfaces (or a combination of those) +* Fresnel reflections and refractions +* Translational motion blur +* Depth of field based on aperture and focal plane +* Procedural textures +* User interaction with the scene ------------------------------------------------------------------------------- -REQUIREMENTS: +FEATURES (in a bit more detail) ------------------------------------------------------------------------------- -In this project, you are given code for: +* **Stream compaction on the GPU**: This is basically a technique that prunes out inactive rays after every bounce. This helps in reducing the number of threads for the next bounce, and hence can achieve speedups especially when we have a large number of rays that don't hit anything in the scene. Currently I am using "thrust" library for this task. -* All of the basecode from Project 1, plus: -* Intersection testing code for spheres and cubes -* Code for raycasting from the camera +* **BRDF model:** : Here is an example of results from a scene having surfaces that are both diffuse and specular at the same time. +The way the BRDF deals with it is a russian roulette based on probabilities. Simply put, if a material is 70% diffuse, at every iteration, draw a random number from 0 to 1, and if its less than 0.7, then calculate diffuse reflection, else specular reflection. +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/pool.0.bmp) -You will need to implement the following features. A number of these required features you may have already implemented in Project 1. If you have, you are ahead of the curve and have less work to do! +* **Fresnel reflection and refractions:** +This physically based model tells you the amount of reflection or transmittance that takes place at given incoming directions of rays on the material. +Notice that the sphere at the bottom refracts and reflects based on angles. If we do not use fresnel, then we will see either of those phenomena on the sphere but not both. +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/refr_refl_fresnel.bmp) -* Full global illumination (including soft shadows, color bleeding, etc.) by pathtracing rays through the scene. -* Properly accumulating emittance and colors to generate a final image -* Supersampled antialiasing -* Parallelization by ray instead of by pixel via stream compaction -* Perfect specular reflection +* **Translational motion blur:** +The idea is to do temporal sampling in addition to spatial sampling. Given a frame, go back in time, and linearly (could be cubic or higher order) interpolate between the positions of geometry now and then. +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/motion_blurred.bmp) -You are also required to implement at least two of the following features. Some of these features you may have already implemented in Project 1. If you have, you may NOT resubmit those features and instead must pick two new ones to implement. +* **Depth of field:** +Based on the aperture and focal plane specified as camera attributes in the config file. +The idea is to jitter the rays in such a manner that the jittering is least at the focal plane region. +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/dof_image.bmp) -* Additional BRDF models, such as Cook-Torrance, Ward, etc. Each BRDF model may count as a separate feature. -* Texture mapping -* Bump mapping -* Translational motion blur -* Fresnel-based Refraction, i.e. glass -* OBJ Mesh loading and rendering without KD-Tree -* Interactive camera -* Integrate an existing stackless KD-Tree library, such as CUKD (https://github.com/unvirtual/cukd) -* Depth of field +* **Procedural textures:** +I cannot be more fascinated by the beauty of procedural textures (two things that amazed me the most during this assignment are Monte Carlo sampling and Perlin Noise. +So beautiful!). I have implemented a few basic procedural textures for the path tracer -Vertical stripes texture,Horizontal stripes texture, Checkerboard texture ,Marble texture , and a generic Perlin texture +And then, it was time to play with these parameters and just appreciate mathematics. +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/perlin_texture.bmp) -Alternatively, implementing just one of the following features can satisfy the "pick two" feature requirement, since these are correspondingly more difficult problems: +As you can see, this was too much fun. So here is an image with everything textured using perlin textures. +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/perlin_earth.bmp) -* Physically based subsurface scattering and transmission -* Implement and integrate your own stackless KD-Tree from scratch. -* Displacement mapping -* Deformational motion blur +* **User interaction with the path tracer:** +According to me, this was the coolest part of the assignment. User interaction with photorealistic rendering algorithms are best avoided, but hey, we have the GPU! And we have inherently formulated the path tracing algorithm in a parallel and iterative fashion. This makes it idea for user interaction. +There are three types of user interactions supported. -As yet another alternative, if you have a feature or features you really want to implement that are not on this list, let us know, and we'll probably say yes! +1. Interactive "look-at" depth of field: + The user can focus on any part of the image by using the right mouse button. Just click and let it be in focus! +2. Interactive positioning of objects on screen: + LMB on any object in the scene, and use the following keys to move the object + + x : move in positive x-direction + + X : move in negative x-direction + + y : move in positive y-direction + + Y : move in negative y-direction + + z : move in positive z-direction + + Z : move in negative z-direction +3. Interacitve editing of procedural textures : + Press "t" on the keyboard to enter/exit the world of procedural textures. This feature grew out of necessity. It was taking me quite a while to come up with good settings for the "attempted" earth procedural texture above. So, I thought it might be covenient to do this visually. +Finally, I ended up implementing this feature as an integral part of path tracer. We can think of it like this. If you don't like the way, your procedural textures are rendering in your path tracer, you can hit 't' and set your textures as per your liking, and then hit 't' again to path trace with these textures. +A "Texture session" basically shows a flat color render without any lighting. The user can tweak values (see the keyboard controls given below) and interactively see if he likes any of the textures. Right now, the interface doesn't cover "all" the parameters, so you will be basically see derivations or variations from an existing configuration. For example, you can't change the colors, but can change the pattern. -------------------------------------------------------------------------------- -NOTES ON GLM: -------------------------------------------------------------------------------- -This project uses GLM, the GL Math library, for linear algebra. You need to know two important points on how GLM is used in this project: +Last but not the least, since these are interactive features, images will not be able to describe them completely. Please see the **video of these features**at this link, + +https://vimeo.com/76013561 -* In this project, indices in GLM vectors (such as vec3, vec4), are accessed via swizzling. So, instead of v[0], v.x is used, and instead of v[1], v.y is used, and so on and so forth. -* GLM Matrix operations work fine on NVIDIA Fermi cards and later, but pre-Fermi cards do not play nice with GLM matrices. As such, in this project, GLM matrices are replaced with a custom matrix struct, called a cudaMat4, found in cudaMat4.h. A custom function for multiplying glm::vec4s and cudaMat4s is provided as multiplyMV() in intersections.h. +**SECRET SAUCE** behind these user interactive features, +In the first iteration and the first bounce, I am capturing the depth and the object IDs at every pixel. + + "Depth map" : This helps in interactive DOF. We just set the focal plane to the value of the clicked pixel in the depth buffer + + "OBJID map" : This is how I identify which pixels correspond to which objects. Basis of both interactive textures and interactive translations features. +Here is an example depth map, +![alt tag](https://raw.github.com/vimanyu/Project2-Pathtracer/master/renders/depthMap_pool.bmp) ------------------------------------------------------------------------------- -README +BUILDING AND RUNNING THE CODE ------------------------------------------------------------------------------- -All students must replace or augment the contents of this Readme.md in a clear -manner with the following: -* A brief description of the project and the specific features you implemented. -* At least one screenshot of your project running. -* A 30 second or longer video of your project running. To create the video you - can use http://www.microsoft.com/expression/products/Encoder4_Overview.aspx -* A performance evaluation (described in detail below). +New additional command line options: +dof, mblur,textureMode -------------------------------------------------------------------------------- -PERFORMANCE EVALUATION -------------------------------------------------------------------------------- -The performance evaluation is where you will investigate how to make your CUDA -programs more efficient using the skills you've learned in class. You must have -performed at least one experiment on your code to investigate the positive or -negative effects on performance. +Eg: +565Pathtracer.exe scene="../testScene.txt" dof=1 mblur=0 +565Pathtracer.exe scene="../testScene.txt" textureMode=1 + +There are a few example scene files under the "scenes/" directory. +Desicription of the scene file format can be found at +https://github.com/vimanyu/Project1-RayTracer under the heading "TAKUAscene format". + +Here are a few things that I added to the existing TAKUAscene format. + +* Map : These are basically texture maps which are bound to materials. Materials have an attribute called "MAPID" that links the material to the map. +Different types of maps are supported, and they have the following common attributes (though for some maps, the meanings of the attributes are not self-explanatory). + +MAP (int) // Map header + +type //Type of map + +COL1 (vec3) // Primary color + +COL2 (vec3) // Secondary color + +WIDTH1 (float) // Width of the primary color -One such experiment would be to investigate the performance increase involved -with adding a spatial data-structure to your scene data. +WIDTH2 (float) // Width of the secondary color -Another idea could be looking at the change in timing between various block -sizes. +SMOOTH (int) // Smooth interpolation between the two colors -A good metric to track would be number of rays per second, or frames per -second, or number of objects displayable at 60fps. +Types of maps: +1.base +For base maps, the options are more or less non-functional. Base maps are a special kind of map which the materials use to specify that all the properties come from the material, and none from the map. +This is in effect a dummy map -We encourage you to get creative with your tweaks. Consider places in your code -that could be considered bottlenecks and try to improve them. +2.hstripe: +For horizontal stripes. The attributes perform expected actions. Width2 is ignored. -Each student should provide no more than a one page summary of their -optimizations along with tables and or graphs to visually explain any -performance differences. +3.vstripe: +For vertical stripes. The attributes perform expected actions. Width2 is ignored. + +4.checkerboard: +For 2D grid textures. All the attributes are useful. + +5.marble +For marble looking patterns. The colors are expected, but the width1 and width2 settings have an effect on the turbulence and the amplitude of noise functions + +6.perlin +A generic perlin function. ------------------------------------------------------------------------------- -THIRD PARTY CODE POLICY +KEYBOARD CONTROLS ------------------------------------------------------------------------------- -* Use of any third-party code must be approved by asking on the Google group. If it is approved, all students are welcome to use it. Generally, we approve use of third-party code that is not a core part of the project. For example, for the ray tracer, we would approve using a third-party library for loading models, but would not approve copying and pasting a CUDA function for doing refraction. -* Third-party code must be credited in README.md. -* Using third-party code without its approval, including using another student's code, is an academic integrity violation, and will result in you receiving an F for the semester. + + x : move in positive x-direction + + X : move in negative x-direction + + y : move in positive y-direction + + Y : move in negative y-direction + + z : move in positive z-direction + + Z : move in negative z-direction + + h : increase width1 of selected object's map + + j : decrease width1 of selected object's map + + k : increase width2 of selected object's map + + l : decrease width2 of selected object's map ------------------------------------------------------------------------------- -SELF-GRADING +PERFORMANCE EVALUATION ------------------------------------------------------------------------------- -* On the submission date, email your grade, on a scale of 0 to 100, to Liam, liamboone+cis565@gmail.com, with a one paragraph explanation. Be concise and realistic. Recall that we reserve 30 points as a sanity check to adjust your grade. Your actual grade will be (0.7 * your grade) + (0.3 * our grade). We hope to only use this in extreme cases when your grade does not realistically reflect your work - it is either too high or too low. In most cases, we plan to give you the exact grade you suggest. -* Projects are not weighted evenly, e.g., Project 0 doesn't count as much as the path tracer. We will determine the weighting at the end of the semester based on the size of each project. +For performance tests, I started with testing my code with tiles of different sizes. +Tested this with two image sizes - 800 X 800 and 1280 X 720 on a machine equipped with +Nvidia GT 650M. + +For resolution 800 X 800, (sampleScene.txt) + +Tile Size | Average time per iteration (ms) +--- | --- +4|447 +8|208 +16|224 +32|245 + +For resolution 1280 X 720, (sampleScene.txt) + +Tile Size | Average time per iteration (ms) +--- | --- +4|522 +8|243 +16|264 +32|292 + +So it looked like the tile size of 8 was the most optimum. + +Next I went on to see the impact of stream compaction. Got quite a mixed set of results here. + +At first, my code without stream compaction ran faster than with stream compaction. This made me think that the +cost of compacting the array was more than having idle threads lying around. This was done on the provided example file +sampleScene.txt. + +Stream Compaction | Average time per iteration (ms) +--- | --- +ON|208 +OFF|184 + +This made me believe that the benefits of stream compaction are seen when we have a lot of rays without any intersections. +So I removed the left wall from the scene + +Stream Compaction | Average time per iteration (ms) +--- | --- +ON|143 +OFF|134 + +Then I removed the right wall as well, + +Stream Compaction | Average time per iteration (ms) +--- | --- +ON| 91 +OFF|101 + +Final tests were done with different types of memory. My implementation has an array of 512 random integers that must be passed to the gpu for perlin computations. + +So, I first moved them to constant memory on gpu, using __constant__declaration and cudaMemcpyToSymbol + +Type of memory for perlin array | Average time per iteration (ms) +--- | --- +Global| 309 +Constant|342 +Shared|224 + +Though shared memory implementation was crashing for me after a few iterations. +But on my slow machine ( 8600m gt), constant memory showed a dramatic improvement for the same scene. +From 5600 ms to 4400 ms. + +Apart from these, in the implementation, I still feel there are places where I can avoid normalizing operations if I am sure the input vectors are normalized. +Also, for texture mode implementatoin, I thought it was best to duplicate and trim down the ray tracing code so to avoid branching in gpu and to run only as much as needed. ------------------------------------------------------------------------------- -SUBMISSION +THIRD PARTY CODE CREDITS ------------------------------------------------------------------------------- -As with the previous project, you should fork this project and work inside of your fork. Upon completion, commit your finished project back to your fork, and make a pull request to the master repository. -You should include a README.md file in the root directory detailing the following - -* A brief description of the project and specific features you implemented -* At least one screenshot of your project running, and at least one screenshot of the final rendered output of your pathtracer -* Instructions for building and running your project if they differ from the base code -* A link to your blog post detailing the project -* A list of all third-party code used +* Perlin noise function: http://www.codermind.com/articles/Raytracer-in-C++-Part-III-Textures.html diff --git a/renders/test.0.bmp b/renders/depthMap_pool.bmp similarity index 53% rename from renders/test.0.bmp rename to renders/depthMap_pool.bmp index 9319138..32a7c46 100644 Binary files a/renders/test.0.bmp and b/renders/depthMap_pool.bmp differ diff --git a/renders/depth_map.bmp b/renders/depth_map.bmp new file mode 100644 index 0000000..0c33fc2 Binary files /dev/null and b/renders/depth_map.bmp differ diff --git a/renders/depth_map0.bmp b/renders/depth_map0.bmp new file mode 100644 index 0000000..ad22c10 Binary files /dev/null and b/renders/depth_map0.bmp differ diff --git a/renders/dof.bmp b/renders/dof.bmp new file mode 100644 index 0000000..0625e38 Binary files /dev/null and b/renders/dof.bmp differ diff --git a/renders/dof_image.bmp b/renders/dof_image.bmp new file mode 100644 index 0000000..f1eab8c Binary files /dev/null and b/renders/dof_image.bmp differ diff --git a/renders/fresnel_frame1.bmp b/renders/fresnel_frame1.bmp new file mode 100644 index 0000000..f0404a6 Binary files /dev/null and b/renders/fresnel_frame1.bmp differ diff --git a/renders/mblur.bmp b/renders/mblur.bmp new file mode 100644 index 0000000..241dc83 Binary files /dev/null and b/renders/mblur.bmp differ diff --git a/renders/motion_blurred.bmp b/renders/motion_blurred.bmp new file mode 100644 index 0000000..968266c Binary files /dev/null and b/renders/motion_blurred.bmp differ diff --git a/renders/perlin_earth.bmp b/renders/perlin_earth.bmp new file mode 100644 index 0000000..187837d Binary files /dev/null and b/renders/perlin_earth.bmp differ diff --git a/renders/perlin_texture.bmp b/renders/perlin_texture.bmp new file mode 100644 index 0000000..8cb6671 Binary files /dev/null and b/renders/perlin_texture.bmp differ diff --git a/renders/pool.0.bmp b/renders/pool.0.bmp new file mode 100644 index 0000000..74cd90b Binary files /dev/null and b/renders/pool.0.bmp differ diff --git a/renders/refr_refl_diff_DOF.bmp b/renders/refr_refl_diff_DOF.bmp new file mode 100644 index 0000000..c6795fa Binary files /dev/null and b/renders/refr_refl_diff_DOF.bmp differ diff --git a/renders/refr_refl_fresnel.bmp b/renders/refr_refl_fresnel.bmp new file mode 100644 index 0000000..8fe29ff Binary files /dev/null and b/renders/refr_refl_fresnel.bmp differ diff --git a/renders/texture_session.bmp b/renders/texture_session.bmp new file mode 100644 index 0000000..670ebf5 Binary files /dev/null and b/renders/texture_session.bmp differ diff --git a/scenes/dof_demo.txt b/scenes/dof_demo.txt new file mode 100644 index 0000000..2f6ffe9 --- /dev/null +++ b/scenes/dof_demo.txt @@ -0,0 +1,305 @@ +MAP 0 +base +COL1 1 1 1 +COL2 1 1 1 +WIDTH1 1 +WIDTH2 1 +SMOOTH 0 + +MAP 1 +hstripe +COL1 0 1 1 +COL2 1 1 0 +WIDTH1 0.4 +WIDTH2 0.5 +SMOOTH 0 + +MAP 2 +vstripe +COL1 0.9 0.9 0.9 +COL2 0.9 0.9 0.9 +WIDTH1 0.5 +WIDTH2 0.2 +SMOOTH 0 + +MAP 3 //Sphere checker +checkerboard +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 4 //Perlin +marble +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + + +MATERIAL 0 //white diffuse +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 1 //red diffuse +RGB .63 .06 .04 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 2 //green diffuse +RGB .15 .48 .09 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 3 //red glossy +RGB .63 .26 .24 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 4 //white glossy +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 5 //glass +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 1 +REFRIOR 2.2 +SCATTER 0 +ABSCOEFF .02 5.1 5.7 +RSCTCOEFF 13 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 6 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.7 +MAPID 0 + +MATERIAL 7 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 1 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 8 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 15 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 9 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1.0 +MAPID 4 + + +CAMERA +RES 800 800 +FOVY 25 +ITERATIONS 5000 +FILE test.bmp +FOCALDIST 2 +APERTURE 2.2 +frame 0 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 +frame 1 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 + +OBJECT 0 +cube +material 0 +frame 0 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 1 +cube +material 0 +frame 0 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +frame 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 + +OBJECT 2 +cube +material 0 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 3 +cube +material 1 +frame 0 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 4 +cube +material 2 +frame 0 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 5 +sphere +material 5 +frame 0 +TRANS 0 5 0 +ROTAT 0 180 0 +SCALE 3 3 3 +frame 1 +TRANS 0 5 0 +ROTAT 0 180 0 +SCALE 3 3 3 + +OBJECT 6 +sphere +material 3 +frame 0 +TRANS 2 5 2 +ROTAT 0 180 0 +SCALE 3 3 3 +frame 1 +TRANS 2 5 2 +ROTAT 0 180 0 +SCALE 3 3 3 + +OBJECT 7 +sphere +material 6 +frame 0 +TRANS -2 5 -2 +ROTAT 0 180 0 +SCALE 3 3 3 +frame 1 +TRANS -2 5 -2 +ROTAT 0 180 0 +SCALE 3 3 3 + +OBJECT 8 +cube +material 8 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 diff --git a/scenes/perlin.txt b/scenes/perlin.txt new file mode 100644 index 0000000..ae86acd --- /dev/null +++ b/scenes/perlin.txt @@ -0,0 +1,414 @@ +MAP 0 +base +COL1 1 1 1 +COL2 1 1 1 +WIDTH1 1 +WIDTH2 1 +SMOOTH 0 + +MAP 1 +hstripe +COL1 0 1 1 +COL2 1 1 0 +WIDTH1 0.4 +WIDTH2 0.5 +SMOOTH 0 + +MAP 2 +vstripe +COL1 0.4 0.6 0.4 +COL2 0.3 0.2 0.8 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 3 //checker +checkerboard +COL1 0.1 0.2 0.1 +COL2 0.0 0.0 0.0 +WIDTH1 0.02 +WIDTH2 0.02 +SMOOTH 0 + +MAP 4 //Earth Perlin +marble +COL1 0.0 0.3 0.0 +COL2 0.5 0.1 2.5 +WIDTH1 0.6 +WIDTH2 0.95 +SMOOTH 0 + +MAP 5 //Wall Perlin +marble +COL1 0.5 0.5 0.5 +COL2 1.0 0.0 0.0 +WIDTH1 0.2 +WIDTH2 0.4 +SMOOTH 0 + +MAP 6 //Bump +bump +COL1 0.3 0.1 0.85 +COL2 1.0 1.0 1.0 +WIDTH1 0.4 +WIDTH2 0.85 +SMOOTH 0 + +MAP 7 //Floor Marble +marble +COL1 0 0.2 0.1 +COL2 0.2 0.4 0.4 +WIDTH1 0.85 +WIDTH2 0.95 +SMOOTH 0 + + +MAP 8 //Sky Back wall Perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.75 +WIDTH2 0.15 +SMOOTH 0 + +MAP 9 //Sky Left wall Perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.75 +WIDTH2 0.15 +SMOOTH 0 + +MAP 10 //Sky Right wall Perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.75 +WIDTH2 0.15 +SMOOTH 0 + + +MAP 11 //Floor sky perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.95 +WIDTH2 0.23 +SMOOTH 0 + + +MAP 12 //Roof sky plain +base +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.45 +WIDTH2 0.23 +SMOOTH 0 + +MATERIAL 0 //white diffuse +RGB 0.1 0.1 0.2 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 11 + +MATERIAL 1 //red diffuse +RGB .63 .06 .04 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 9 + +MATERIAL 2 //green diffuse +RGB .15 .48 .09 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 10 + +MATERIAL 3 //red glossy +RGB .63 .26 .24 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 4 //white glossy +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 5 //glass +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 1 +REFRIOR 2.2 +SCATTER 0 +ABSCOEFF .02 5.1 5.7 +RSCTCOEFF 13 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 6 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.7 +MAPID 0 + +MATERIAL 7 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 1 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 8 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 15 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 9 //perlin mtl +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.95 +MAPID 4 + +MATERIAL 10 //bump mtl +RGB .45 .68 .89 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.95 +MAPID 6 + +MATERIAL 11 //marble mtl +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.9 +MAPID 11 + +MATERIAL 12 //back wall mtl +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.9 +MAPID 8 + + +CAMERA +RES 800 800 +FOVY 25 +ITERATIONS 5000 +FILE test.bmp +FOCALDIST 1 +APERTURE 2.0 +frame 0 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 +frame 1 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 + +OBJECT 0 //Floor +cube +material 11 +frame 0 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 1 //Back wall +cube +material 12 +frame 0 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +frame 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 + +OBJECT 2 //Roof +cube +material 0 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 3 //Left wall +cube +material 1 +frame 0 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 4 //Right wall +cube +material 2 +frame 0 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 5 +sphere +material 9 +frame 0 +TRANS 0 5 -2 +ROTAT 0 180 0 +SCALE 5 5 5 +frame 1 +TRANS 0 5 -2 +ROTAT 0 180 0 +SCALE 6 6 6 + + +OBJECT 6 +cube +material 8 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 + +OBJECT 7 +sphere +material 8 +frame 0 +TRANS -3 5 2 +ROTAT 0 180 0 +SCALE 1 1 1 +frame 1 +TRANS -5 5 2 +ROTAT 0 180 0 +SCALE 1 1 1 + +OBJECT 8 +sphere +material 8 +frame 0 +TRANS 3 3 1 +ROTAT 0 180 0 +SCALE 1 1 1 +frame 1 +TRANS 3 3 1 +ROTAT 0 180 0 +SCALE 1 1 1 diff --git a/scenes/pool.txt b/scenes/pool.txt new file mode 100644 index 0000000..7c324c0 --- /dev/null +++ b/scenes/pool.txt @@ -0,0 +1,735 @@ +MAP 0 +base +COL1 1 1 1 +COL2 1 1 1 +WIDTH1 1 +WIDTH2 1 +SMOOTH 0 + +MAP 1 +hstripe +COL1 0 1 1 +COL2 1 1 0 +WIDTH1 0.4 +WIDTH2 0.5 +SMOOTH 0 + +MAP 2 +vstripe +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 1.0 +WIDTH1 0.3 +WIDTH2 0.4 +SMOOTH 0 + +MAP 3 //Sphere checker +checkerboard +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 4 //Perlin +marble +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 5 //perlin red striped ball +perlin +COL1 1.0 0.0 0.0 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + +MAP 6 //perlin green striped ball +perlin +COL1 0.133333 0.545098 0.133333 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + + +MAP 7 //perlin yellow striped ball +perlin +COL1 1.0 1.0 0.0 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + + +MAP 8 //perlin blue striped ball +perlin +COL1 0.0 0.0 1.0 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + +MAP 9 //perlin orange striped ball +perlin +COL1 1 0.270588 0 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + +MAP 10 //perlin purple striped ball +perlin +COL1 0.556863 0.219608 0.556863 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + +MAP 11 //perlin maroon striped ball +perlin +COL1 0.545098 0 0 +COL2 1 1 1 +WIDTH1 0 +WIDTH2 0 +SMOOTH 0 + + + + +MATERIAL 0 //white diffuse +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 1 //red glossy +RGB 1 0 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 2 //green glossy +RGB 0.133333 0.545098 0.133333 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 3 //yellow glossy +RGB 1 1 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 4 //blue glossy +RGB 0 0 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 5 //glass +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 1 +REFRIOR 2.2 +SCATTER 0 +ABSCOEFF .02 5.1 5.7 +RSCTCOEFF 13 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 6 //orange glossy +RGB 1 0.270588 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 7 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 1 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 8 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 18 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 9 //purple glossy +RGB 0.556863 0.219608 0.556863 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 10 //black glossy +RGB 0 0 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + +MATERIAL 11 //maroon glossy +RGB 0.545098 0 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 0 + + +MATERIAL 12 //green diffuse +RGB 0 0.392157 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 13 //blue diffuse +RGB 0 0 0.501961 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 14 //red diffuse +RGB .63 .06 .04 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 15 //mirror +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0 +MAPID 0 + +MATERIAL 16 //white glossy +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.95 +MAPID 0 + + +MATERIAL 17 //red glossy +RGB 1 0 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 5 + +MATERIAL 18 //green glossy +RGB 0.133333 0.545098 0.133333 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 6 + +MATERIAL 19 //yellow glossy +RGB 1 1 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 7 + +MATERIAL 20 //blue glossy +RGB 0 0 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 8 + + +MATERIAL 21 //orange glossy +RGB 1 0.270588 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 9 + +MATERIAL 22 //purple glossy +RGB 0.556863 0.219608 0.556863 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 10 + +MATERIAL 23 //maroon glossy +RGB 0.545098 0 0 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.90 +MAPID 11 + + +CAMERA +RES 800 800 +FOVY 25 +ITERATIONS 5000 +FILE pool.bmp +FOCALDIST 1 +APERTURE 2.0 +frame 0 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 +frame 1 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 + +OBJECT 0 //floor +cube +material 12 +frame 0 +TRANS 0 0 -3 +ROTAT 0 0 90 +SCALE .01 15 15 +frame 1 +TRANS 0 0 -3 +ROTAT 0 0 90 +SCALE .01 15 15 + +OBJECT 1 // back wall +cube +material 0 +frame 0 +TRANS 0 5 -11 +ROTAT 0 90 0 +SCALE .01 20 20 +frame 1 +TRANS 0 5 -11 +ROTAT 0 90 0 +SCALE .01 20 20 + +OBJECT 2 //roof +cube +material 0 +frame 0 +TRANS 0 10 -3 +ROTAT 0 0 90 +SCALE .01 20 20 +frame 1 +TRANS 0 10 -3 +ROTAT 0 0 90 +SCALE .01 20 20 + +OBJECT 3 //right wall +cube +material 13 +frame 0 +TRANS -6 5 -3 +ROTAT 0 0 0 +SCALE .01 20 20 +frame 1 +TRANS -6 5 -3 +ROTAT 0 0 0 +SCALE .01 20 20 + +OBJECT 4 //left wall +cube +material 14 +frame 0 +TRANS 6 5 -3 +ROTAT 0 0 0 +SCALE .01 20 20 +frame 1 +TRANS 6 5 -3 +ROTAT 0 0 0 +SCALE .01 20 20 + + +OBJECT 5 +cube +material 8 +frame 0 +TRANS 0 10 -3 +ROTAT 0 0 90 +SCALE .3 3 3 +frame 1 +TRANS 0 10 -3 +ROTAT 0 0 90 +SCALE .3 3 3 + +OBJECT 6 //Ball 1 +sphere +material 1 +frame 0 +TRANS 0 1 0 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 0 1 0 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 7 //Ball 2 +sphere +material 23 +frame 0 +TRANS -1 1 -1.436 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -1 1 -1.436 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 8 //Ball 3 +sphere +material 2 +frame 0 +TRANS -2 1 -2.872 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -2 1 -2.872 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 9 //Ball 4 +sphere +material 10 +frame 0 +TRANS 0 1 -2.872 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 0 1 -2.872 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 10 //Ball 5 +sphere +material 3 +frame 0 +TRANS 2 1 -2.872 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 2 1 -2.872 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 11 //Ball 6 +sphere +material 21 +frame 0 +TRANS -3 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -3 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 12 //Ball 7 +sphere +material 4 +frame 0 +TRANS -1 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -1 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 + + +OBJECT 13 //Ball 8 +sphere +material 20 +frame 0 +TRANS 1 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 1 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 + + +OBJECT 14 //Ball 9 +sphere +material 6 +frame 0 +TRANS 3 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 3 1 -4.308 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 15 //Ball 10 +sphere +material 19 +frame 0 +TRANS 0 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 0 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 16 //Ball 11 +sphere +material 9 +frame 0 +TRANS -4 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -4 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 17 //Ball 12 +sphere +material 18 +frame 0 +TRANS -2 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -2 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 18 //Ball 13 +sphere +material 22 +frame 0 +TRANS 4 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 4 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 19 //Ball 14 +sphere +material 17 +frame 0 +TRANS 2 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 2 1 -7.180 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 20 //Ball between 2 and 3 +sphere +material 11 +frame 0 +TRANS 1 1 -1.436 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS 1 1 -1.436 +ROTAT 0 180 0 +SCALE 2 2 2 + +OBJECT 21 // front wall +cube +material 0 +frame 0 +TRANS 0 5 14 +ROTAT 0 90 0 +SCALE .01 20 20 +frame 1 +TRANS 0 5 14 +ROTAT 0 90 0 +SCALE .01 20 20 + +OBJECT 22 //Cue ball +sphere +material 16 +frame 0 +TRANS -3 1 3 +ROTAT 0 180 0 +SCALE 2 2 2 +frame 1 +TRANS -3 1 3 +ROTAT 0 180 0 +SCALE 2 2 2 \ No newline at end of file diff --git a/scenes/sampleScene.txt b/scenes/sampleScene.txt index 52d079e..8ac4926 100755 --- a/scenes/sampleScene.txt +++ b/scenes/sampleScene.txt @@ -1,3 +1,44 @@ +MAP 0 +base +COL1 1 1 1 +COL2 1 1 1 +WIDTH1 1 +WIDTH2 1 +SMOOTH 0 + +MAP 1 +hstripe +COL1 0 1 1 +COL2 1 1 0 +WIDTH1 0.4 +WIDTH2 0.5 +SMOOTH 0 + +MAP 2 +vstripe +COL1 0.9 0.9 0.9 +COL2 0.9 0.9 0.9 +WIDTH1 0.5 +WIDTH2 0.2 +SMOOTH 0 + +MAP 3 //Sphere checker +checkerboard +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 4 //Perlin +marble +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + + MATERIAL 0 //white diffuse RGB 0.9 0.9 0.9 SPECEX 0 @@ -9,6 +50,8 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 MATERIAL 1 //red diffuse RGB .63 .06 .04 @@ -21,6 +64,8 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 MATERIAL 2 //green diffuse RGB .15 .48 .09 @@ -33,6 +78,8 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 MATERIAL 3 //red glossy RGB .63 .26 .24 @@ -45,6 +92,8 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 MATERIAL 4 //white glossy RGB 1 1 1 @@ -57,30 +106,36 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 MATERIAL 5 //glass -RGB 0 0 0 +RGB 1 1 1 SPECEX 0 SPECRGB 1 1 1 REFL 0 REFR 1 -REFRIOR 2.2 +REFRIOR 2.2 SCATTER 0 ABSCOEFF .02 5.1 5.7 RSCTCOEFF 13 EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 MATERIAL 6 //green glossy RGB .35 .48 .29 SPECEX 0 SPECRGB 1 1 1 -REFL 0 +REFL 1 REFR 0 REFRIOR 2.6 SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 0 +DIFFCOEFF 0.7 +MAPID 0 MATERIAL 7 //light RGB 1 1 1 @@ -93,6 +148,8 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 1 +DIFFCOEFF 1 +MAPID 0 MATERIAL 8 //light RGB 1 1 1 @@ -105,12 +162,31 @@ SCATTER 0 ABSCOEFF 0 0 0 RSCTCOEFF 0 EMITTANCE 15 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 9 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1.0 +MAPID 4 + CAMERA RES 800 800 FOVY 25 ITERATIONS 5000 FILE test.bmp +FOCALDIST 1 +APERTURE 0.7 frame 0 EYE 0 4.5 12 VIEW 0 0 -1 @@ -182,7 +258,7 @@ SCALE .01 10 10 OBJECT 5 sphere -material 4 +material 5 frame 0 TRANS 0 2 0 ROTAT 0 180 0 @@ -196,11 +272,11 @@ OBJECT 6 sphere material 3 frame 0 -TRANS 2 5 2 +TRANS 3 5 1 ROTAT 0 180 0 SCALE 2.5 2.5 2.5 frame 1 -TRANS 2 5 2 +TRANS 0 5 1 ROTAT 0 180 0 SCALE 2.5 2.5 2.5 diff --git a/scenes/space.txt b/scenes/space.txt new file mode 100644 index 0000000..8b07f45 --- /dev/null +++ b/scenes/space.txt @@ -0,0 +1,428 @@ +MAP 0 +base +COL1 1 1 1 +COL2 1 1 1 +WIDTH1 1 +WIDTH2 1 +SMOOTH 0 + +MAP 1 +hstripe +COL1 0 1 1 +COL2 1 1 0 +WIDTH1 0.4 +WIDTH2 0.5 +SMOOTH 0 + +MAP 2 +vstripe +COL1 0.4 0.6 0.4 +COL2 0.3 0.2 0.8 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 3 //checker +checkerboard +COL1 0.1 0.2 0.1 +COL2 0.0 0.0 0.0 +WIDTH1 0.02 +WIDTH2 0.02 +SMOOTH 0 + +MAP 4 //Earth Perlin +marble +COL1 0.0 0.2 0.0 +COL2 0.5 0.1 2.5 +WIDTH1 0.6 +WIDTH2 0.95 +SMOOTH 0 + +MAP 5 //Wall Perlin +marble +COL1 0.5 0.5 0.5 +COL2 1.0 0.0 0.0 +WIDTH1 0.2 +WIDTH2 0.4 +SMOOTH 0 + +MAP 6 //Bump +bump +COL1 0.3 0.1 0.85 +COL2 1.0 1.0 1.0 +WIDTH1 0.4 +WIDTH2 0.85 +SMOOTH 0 + +MAP 7 //Floor Marble +marble +COL1 0 0.2 0.1 +COL2 0.2 0.4 0.4 +WIDTH1 0.85 +WIDTH2 0.95 +SMOOTH 0 + + +MAP 8 //Sky Back wall Perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.75 +WIDTH2 0.15 +SMOOTH 0 + +MAP 9 //Sky Left wall Perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.75 +WIDTH2 0.15 +SMOOTH 0 + +MAP 10 //Sky Right wall Perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.75 +WIDTH2 0.15 +SMOOTH 0 + + +MAP 11 //Floor sky perlin +marble +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.95 +WIDTH2 0.23 +SMOOTH 0 + + +MAP 12 //Roof sky plain +base +COL1 0.1 0.1 0.2 +COL2 1.0 1.0 1.0 +WIDTH1 0.45 +WIDTH2 0.23 +SMOOTH 0 + +MATERIAL 0 //white diffuse +RGB 0.1 0.1 0.2 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 11 + +MATERIAL 1 //red diffuse +RGB .63 .06 .04 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 9 + +MATERIAL 2 //green diffuse +RGB .15 .48 .09 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 10 + +MATERIAL 3 //red glossy +RGB .63 .26 .24 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 4 //white glossy +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 5 //glass +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 1 +REFRIOR 2.2 +SCATTER 0 +ABSCOEFF .02 5.1 5.7 +RSCTCOEFF 13 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 6 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.7 +MAPID 0 + +MATERIAL 7 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 5 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 8 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 15 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 9 //Earth perlin mtl +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 0.1 0.1 0.1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.95 +MAPID 4 + +MATERIAL 10 //bump mtl +RGB .45 .68 .89 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.95 +MAPID 6 + +MATERIAL 11 //marble mtl +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.9 +MAPID 11 + +MATERIAL 12 //back wall mtl +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1.0 +MAPID 8 + +MATERIAL 13 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 20 +DIFFCOEFF 1 +MAPID 0 + + +CAMERA +RES 800 800 +FOVY 25 +ITERATIONS 5000 +FILE test.bmp +FOCALDIST 1 +APERTURE 2.0 +frame 0 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 +frame 1 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 + +OBJECT 0 //Floor +cube +material 11 +frame 0 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 1 //Back wall +cube +material 12 +frame 0 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +frame 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 + +OBJECT 2 //Roof +cube +material 0 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 3 //Left wall +cube +material 1 +frame 0 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 4 //Right wall +cube +material 2 +frame 0 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 5 //Earth +sphere +material 9 +frame 0 +TRANS 0 5 -2 +ROTAT 0 180 0 +SCALE 5 5 5 +frame 1 +TRANS 0 5 -2 +ROTAT 0 180 0 +SCALE 6 6 6 + + +OBJECT 6 +cube +material 8 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 + +OBJECT 7 //LIGHT +sphere +material 13 +frame 0 +TRANS -3 5 2 +ROTAT 0 180 0 +SCALE 1 1 1 +frame 1 +TRANS -5 5 2 +ROTAT 0 180 0 +SCALE 1 1 1 + +OBJECT 8 //LIGHT +sphere +material 7 +frame 0 +TRANS 3 3 1 +ROTAT 0 180 0 +SCALE 1 1 1 +frame 1 +TRANS 3 3 1 +ROTAT 0 180 0 +SCALE 1 1 1 diff --git a/scenes/sphere.txt b/scenes/sphere.txt new file mode 100644 index 0000000..daf20e3 --- /dev/null +++ b/scenes/sphere.txt @@ -0,0 +1,322 @@ +MAP 0 +base +COL1 1 1 1 +COL2 1 1 1 +WIDTH1 1 +WIDTH2 1 +SMOOTH 0 + +MAP 1 +hstripe +COL1 0 1 1 +COL2 1 1 0 +WIDTH1 0.4 +WIDTH2 0.5 +SMOOTH 0 + +MAP 2 +vstripe +COL1 0 1 0 +COL2 0 0 1 +WIDTH1 0.5 +WIDTH2 0.2 +SMOOTH 0 + +MAP 3 //Sphere checker +checkerboard +COL1 1.0 0.0 0.0 +COL2 1.0 1.0 0.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MAP 4 //Marble +marble +COL1 1.0 0.0 1.0 +COL2 0.0 1.0 1.0 +WIDTH1 0.5 +WIDTH2 0.5 +SMOOTH 0 + + +MAP 5 //Fiery red yellow Perlin +perlin +COL1 1.0 0.0 0.0 +COL2 0.0 0.0 1.0 +WIDTH1 0.5 +WIDTH2 0.1 +SMOOTH 0 + + +MAP 6 //perlin striped ball +perlin +COL1 0.0 0.4 0.432 +COL2 0.34 0.23 0.24 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + + +MAP 7 //checker +checkerboard +COL1 1.0 0.0 1.0 +COL2 1.0 1.0 1.0 +WIDTH1 0.1 +WIDTH2 0.1 +SMOOTH 0 + +MATERIAL 0 //hstripe mtl +RGB 0.9 0.9 0.9 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 2 + +MATERIAL 1 //vstripe mtl +RGB .63 .06 .04 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 3 + +MATERIAL 2 //checkerboard +RGB .15 .48 .09 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 4 + +MATERIAL 3 //marble +RGB .63 .26 .24 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 5 + +MATERIAL 4 //white glossy +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 0 +REFRIOR 2 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 6 + +MATERIAL 5 //glass +RGB 1 1 1 +SPECEX 0 +SPECRGB 1 1 1 +REFL 0 +REFR 1 +REFRIOR 2.2 +SCATTER 0 +ABSCOEFF .02 5.1 5.7 +RSCTCOEFF 13 +EMITTANCE 0 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 6 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 0.7 +MAPID 7 + +MATERIAL 7 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 1 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 8 //light +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 15 +DIFFCOEFF 1 +MAPID 0 + +MATERIAL 9 //green glossy +RGB .35 .48 .29 +SPECEX 0 +SPECRGB 1 1 1 +REFL 1 +REFR 0 +REFRIOR 2.6 +SCATTER 0 +ABSCOEFF 0 0 0 +RSCTCOEFF 0 +EMITTANCE 0 +DIFFCOEFF 1.0 +MAPID 1 + + +CAMERA +RES 800 800 +FOVY 25 +ITERATIONS 1000 +FILE test.bmp +FOCALDIST 1 +APERTURE 2.0 +frame 0 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 +frame 1 +EYE 0 4.5 12 +VIEW 0 0 -1 +UP 0 1 0 + +OBJECT 0 +cube +material 0 +frame 0 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 0 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 1 +cube +material 1 +frame 0 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +frame 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 + +OBJECT 2 +cube +material 2 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 + +OBJECT 3 +cube +material 3 +frame 0 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 4 +cube +material 4 +frame 0 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +frame 1 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 + +OBJECT 5 +sphere +material 9 +frame 0 +TRANS 2 5 3 +ROTAT 0 180 0 +SCALE 4 4 4 +frame 1 +TRANS 2 5 3 +ROTAT 0 180 0 +SCALE 4 4 4 + + +OBJECT 6 +cube +material 8 +frame 0 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 +frame 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .3 3 3 + +OBJECT 7 +sphere +material 6 +frame 0 +TRANS 0 5 0 +ROTAT 0 180 0 +SCALE 4 4 4 +frame 1 +TRANS 0 5 0 +ROTAT 0 180 0 +SCALE 4 4 4 + + diff --git a/src/interactions.h b/src/interactions.h index 6561796..9941211 100755 --- a/src/interactions.h +++ b/src/interactions.h @@ -7,6 +7,7 @@ #define INTERACTIONS_H #include "intersections.h" +enum REFRSTAGE { REFR_ENTER, REFR_EXIT }; //forward declaration __host__ __device__ glm::vec3 getRandomDirectionInSphere(float xi1, float xi2); @@ -40,11 +41,141 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor } +//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION +__host__ __device__ glm::vec3 calculateReflectionDirection(glm::vec3 incident, glm::vec3 normal) { + //nothing fancy here + return glm::normalize(incident-2.0f*normal*glm::dot(incident,normal)); +} + +//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION +__host__ __device__ float calculateFresnel(glm::vec3 incident,glm::vec3 normal, float incidentIOR, float transmittedIOR) +{ + //referred http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf + + float n = incidentIOR/transmittedIOR; + float cosI = -glm::dot(incident, normal); + float sinT2 = n*n*(1.0 -cosI*cosI); + if(n > 1.0f) + return 1.0f; + + float cosT = sqrt(1.0 -sinT2); + float rorth = (incidentIOR*cosI - transmittedIOR*cosT)/(incidentIOR*cosI + transmittedIOR*cosT); + float rpar = (transmittedIOR*cosI - incidentIOR*cosT)/(transmittedIOR*cosI + incidentIOR*cosT); + + return (rorth*rorth + rpar*rpar)/2.0f; +} + +//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION +__host__ __device__ float calculateFresnelSchlick(glm::vec3 incident,glm::vec3 normal, float incidentIOR, float transmittedIOR) +{ + //referred http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf + + float r0 = (incidentIOR - transmittedIOR)/(incidentIOR+transmittedIOR); + float cosX = -glm::dot(normal,incident); + r0 *= r0; + if( incidentIOR>transmittedIOR) + { + float n = incidentIOR/transmittedIOR; + float sinT2 = n*n*(1.0f - cosX * cosX); + if ( sinT2 > 1.0f) + return 1.0f; + cosX = sqrtf(1.0f - sinT2); + } + float x = 1.0f - cosX; + return r0+(1.0f - r0) *x*x*x*x*x; +} + + +__host__ __device__ glm::vec3 calculateRefractionDirection(glm::vec3 incident,glm::vec3 normal,material m,REFRSTAGE stage) +{ + float iorRatio = 1.0f/m.indexOfRefraction; + if (stage == REFR_EXIT) + { + iorRatio = 1.0f/iorRatio; + normal = -1.0f*normal; + } + return glm::normalize(glm::refract( incident, normal,iorRatio)); +} + //TODO: IMPLEMENT THIS FUNCTION //Now that you know how cosine weighted direction generation works, try implementing non-cosine (uniform) weighted random direction generation. //This should be much easier than if you had to implement calculateRandomDirectionInHemisphere. __host__ __device__ glm::vec3 getRandomDirectionInSphere(float xi1, float xi2) { - return glm::vec3(0,0,0); + float up = xi1; + float over = sqrt(1 - up * up); // sin(theta) + float around = xi2 * TWO_PI; + return glm::vec3( cos(around)*over,sin(around)*over,xi1); } +//TODO (PARTIALLY OPTIONAL): IMPLEMENT THIS FUNCTION +//returns 0 if diffuse scatter, 1 if reflected, 2 if transmitted. +__host__ __device__ int calculateBSDF(ray& r, glm::vec3 intersect, glm::vec3 normal, glm::vec3 emittedColor, + glm::vec4& color, glm::vec3& unabsorbedColor, material m, float randomSeed){ + + r.origin = intersect; + normal = glm::normalize(normal); + thrust::default_random_engine rng(hash(randomSeed)); + thrust::uniform_real_distribution u01(0,1); + + + if (m.diffuseCoefficient>0.0f && m.hasReflective) + { + if (u01(rng) < m.diffuseCoefficient) + { + r.direction = calculateRandomDirectionInHemisphere(normal,u01(rng),u01(rng)); + return 0; + } + else + { + r.direction = calculateReflectionDirection(r.direction,normal); + return 1; + } + } + + else if(m.hasReflective) + { + r.direction = calculateReflectionDirection(normal,r.direction); + return 1; + } + + else if (m.hasRefractive) + { + REFRSTAGE stage; + float fresnelReflectance = 1.0f; + if (glm::dot(r.direction,normal)<0) + { + stage = REFR_ENTER; + fresnelReflectance = calculateFresnelSchlick(r.direction,normal,1.0f,m.indexOfRefraction); + } + else + { + stage = REFR_EXIT; + fresnelReflectance = calculateFresnelSchlick(r.direction,normal,m.indexOfRefraction,1.0f); + } + + if (u01(rng) < fresnelReflectance) + { + if(stage == REFR_EXIT) + { + normal = -1.0f*normal; + } + r.direction = calculateReflectionDirection(r.direction,normal); + return 1; + } + else + { + r.direction = calculateRefractionDirection(r.direction,normal,m,stage); + return 2; + } + + } + + else + { + r.direction = calculateRandomDirectionInHemisphere(normal,u01(rng),u01(rng)); + return 0; + } + +}; + #endif diff --git a/src/intersections.h b/src/intersections.h index a6b9469..6a2d24c 100755 --- a/src/intersections.h +++ b/src/intersections.h @@ -156,10 +156,18 @@ __host__ __device__ float boxIntersectionTest(glm::vec3 boxMin, glm::vec3 boxMa } intersectionPoint = multiplyMV(box.transform, glm::vec4(osintersect, 1.0)); - - - - normal = multiplyMV(box.transform, glm::vec4(currentNormal,0.0)); + glm::vec4 itX(box.inverseTransform.x.x,box.inverseTransform.y.x,box.inverseTransform.z.x,box.inverseTransform.w.x); + glm::vec4 itY(box.inverseTransform.x.y,box.inverseTransform.y.y,box.inverseTransform.z.y,box.inverseTransform.w.y); + glm::vec4 itZ(box.inverseTransform.x.z,box.inverseTransform.y.z,box.inverseTransform.z.z,box.inverseTransform.w.z); + glm::vec4 itW(box.inverseTransform.x.w,box.inverseTransform.y.w,box.inverseTransform.z.w,box.inverseTransform.w.w); + + cudaMat4 inverseTranspose; + inverseTranspose.x = itX; + inverseTranspose.y = itY; + inverseTranspose.z = itZ; + inverseTranspose.w = itW; + + normal = multiplyMV(inverseTranspose, glm::vec4(currentNormal,0.0)); return glm::length(intersectionPoint-ro.origin); } @@ -277,6 +285,47 @@ __host__ __device__ glm::vec3 getRandomPointOnSphere(staticGeom sphere, float ra return randPoint; } + +__host__ __device__ int findNearestGeometricIntersection(ray& r, glm::vec3& intersectionPoint, + glm::vec3& intersectionNormal, + staticGeom* geoms, int numberOfGeoms) +{ + int nearestIntersectionObject = -1; + float nearestIntersectionDist = FLT_MAX; + for(int i=0; iobjects.size()]; material* materials = new material[renderScene->materials.size()]; - + map* maps = new map[renderScene->maps.size()]; + for(int i=0; iobjects.size(); i++){ geoms[i] = renderScene->objects[i]; } @@ -121,29 +132,37 @@ void runCuda(){ materials[i] = renderScene->materials[i]; } - + for(int i=0; imaps.size(); i++){ + maps[i] = renderScene->maps[i]; + } // execute the kernel - cudaRaytraceCore(dptr, renderCam, targetFrame, iterations, materials, renderScene->materials.size(), geoms, renderScene->objects.size() ); - - // unmap buffer object + if(!textureMode) + cudaRaytraceCore(dptr, renderCam, targetFrame, iterations, materials, renderScene->materials.size(),maps,renderScene->maps.size(), geoms, renderScene->objects.size(), mblur,dof); + else + cudaRaytraceCoreT(dptr, renderCam, targetFrame, iterations, materials, renderScene->materials.size(),maps,renderScene->maps.size(), geoms, renderScene->objects.size(), mblur,dof); + + // unmap buffer object cudaGLUnmapBufferObject(pbo); }else{ if(!finishedRender){ //output image file image outputImage(renderCam->resolution.x, renderCam->resolution.y); - + image depthImage(renderCam->resolution.x, renderCam->resolution.y); for(int x=0; xresolution.x; x++){ for(int y=0; yresolution.y; y++){ int index = x + (y * renderCam->resolution.x); - outputImage.writePixelRGB(renderCam->resolution.x-1-x,y,renderCam->image[index]); + glm::vec3 justRGB(renderCam->image[index].x,renderCam->image[index].y,renderCam->image[index].z); + outputImage.writePixelRGB(renderCam->resolution.x-1-x,y,justRGB); + float d = abs(renderCam->image[index].w-renderCam->positions[targetFrame].z)/40.0f; + depthImage.writePixelRGB(renderCam->resolution.x-1-x,y, glm::vec3(d,d,d)); } } gammaSettings gamma; gamma.applyGamma = true; - gamma.gamma = 1.0; - gamma.divisor = 1.0; //renderCam->iterations; + gamma.gamma = 1.0/2.2; + gamma.divisor = renderCam->iterations; outputImage.setGammaSettings(gamma); string filename = renderCam->imageName; string s; @@ -153,10 +172,11 @@ void runCuda(){ utilityCore::replaceString(filename, ".bmp", "."+s+".bmp"); utilityCore::replaceString(filename, ".png", "."+s+".png"); outputImage.saveImageRGB(filename); + depthImage.saveImageRGB("depth."+s+".bmp"); cout << "Saved frame " << s << " to " << filename << endl; finishedRender = true; if(singleFrameMode==true){ - cudaDeviceReset(); + //cudaDeviceReset(); exit(0); } } @@ -166,9 +186,9 @@ void runCuda(){ targetFrame++; iterations = 0; for(int i=0; iresolution.x*renderCam->resolution.y; i++){ - renderCam->image[i] = glm::vec3(0,0,0); + renderCam->image[i] = glm::vec4(0,0,0,-1); } - cudaDeviceReset(); + //cudaDeviceReset(); finishedRender = false; } } @@ -218,14 +238,187 @@ void runCuda(){ glutSwapBuffers(); } + + void mouse(int button, int state, int x, int y) + { + if(button == GLUT_RIGHT_BUTTON && state== GLUT_DOWN && dof) + { + int pixelX = renderCam->resolution.x -1 - x; + int index = pixelX + renderCam->resolution.x*y; + float pixelDist = renderCam->image[index].w; + iterations = 0; + renderCam->focalDist = pixelDist; + resetImage(renderCam); + } + + else if(button == GLUT_LEFT_BUTTON && state== GLUT_DOWN) + { + int pixelX = renderCam->resolution.x -1 - x; + int index = pixelX + renderCam->resolution.x*y; + currentSelectedObjId = renderCam->objIdBuffer[index]; + } + } + + void keyboard(unsigned char key, int x, int y) { - std::cout << key << std::endl; switch (key) { case(27): exit(1); break; + + case 'w': + iterations = 0; + resetImage(renderCam); + renderCam->positions[targetFrame].z-=0.2f; + break; + + case 's': + iterations = 0; + resetImage(renderCam); + renderCam->positions[targetFrame].z+= 0.2f; + break; + + case 'a': + iterations = 0; + resetImage(renderCam); + renderCam->positions[targetFrame].x+=0.2f; + break; + + case 'd': + iterations = 0; + resetImage(renderCam); + renderCam->positions[targetFrame].x-=0.2f; + break; + + case 'x': + if(currentSelectedObjId != -1) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + g.translations[targetFrame].x+=0.2; + glm::mat4 transform = utilityCore::buildTransformationMatrix(g.translations[targetFrame],g.rotations[targetFrame],g.scales[targetFrame]); + g.transforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(transform); + g.inverseTransforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(glm::inverse(transform)); + } + break; + + case 'X': + if(currentSelectedObjId != -1) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + g.translations[targetFrame].x-=0.2; + glm::mat4 transform = utilityCore::buildTransformationMatrix(g.translations[targetFrame],g.rotations[targetFrame],g.scales[targetFrame]); + g.transforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(transform); + g.inverseTransforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(glm::inverse(transform)); + } + break; + + case 'y': + if(currentSelectedObjId != -1) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + g.translations[targetFrame].y+=0.2; + glm::mat4 transform = utilityCore::buildTransformationMatrix(g.translations[targetFrame],g.rotations[targetFrame],g.scales[targetFrame]); + g.transforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(transform); + g.inverseTransforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(glm::inverse(transform)); + } + break; + + case 'Y': + if(currentSelectedObjId != -1) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + g.translations[targetFrame].y-=0.2; + glm::mat4 transform = utilityCore::buildTransformationMatrix(g.translations[targetFrame],g.rotations[targetFrame],g.scales[targetFrame]); + g.transforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(transform); + g.inverseTransforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(glm::inverse(transform)); + } + break; + case 'z': + if(currentSelectedObjId != -1) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + g.translations[targetFrame].z+=0.2; + glm::mat4 transform = utilityCore::buildTransformationMatrix(g.translations[targetFrame],g.rotations[targetFrame],g.scales[targetFrame]); + g.transforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(transform); + g.inverseTransforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(glm::inverse(transform)); + } + break; + + case 'Z': + if(currentSelectedObjId != -1) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + g.translations[targetFrame].z-=0.2; + glm::mat4 transform = utilityCore::buildTransformationMatrix(g.translations[targetFrame],g.rotations[targetFrame],g.scales[targetFrame]); + g.transforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(transform); + g.inverseTransforms[targetFrame] = utilityCore::glmMat4ToCudaMat4(glm::inverse(transform)); + } + break; + + case 't': + textureMode = !textureMode; + iterations = 0; + resetImage(renderCam); + break; + + case 'h': + if(currentSelectedObjId != -1 && textureMode) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + material mtl = renderScene->materials[g.materialid]; + if ( (renderScene->maps[mtl.mapID].width1+0.1f) > 0); + renderScene->maps[mtl.mapID].width1+=0.1f; } + break; + case 'j': + if(currentSelectedObjId != -1 && textureMode) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + material mtl = renderScene->materials[g.materialid]; + if ( (renderScene->maps[mtl.mapID].width1-0.1f) > 0); + renderScene->maps[mtl.mapID].width1-=0.1f; + } + break; + case 'k': + if(currentSelectedObjId != -1 && textureMode) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + material mtl = renderScene->materials[g.materialid]; + if ( (renderScene->maps[mtl.mapID].width2+0.1f) > 0); + renderScene->maps[mtl.mapID].width2+=0.1f; + } + break; + case 'l': + if(currentSelectedObjId != -1 && textureMode) + { + iterations = 0; + resetImage(renderCam); + geom g = renderScene->objects[currentSelectedObjId]; + material mtl = renderScene->materials[g.materialid]; + if ( (renderScene->maps[mtl.mapID].width2-0.1f) > 0); + renderScene->maps[mtl.mapID].width2-=0.1f; + } + break; + } } @@ -233,7 +426,6 @@ void runCuda(){ - //------------------------------- //----------SETUP STUFF---------- //------------------------------- @@ -396,3 +588,14 @@ void shut_down(int return_code){ #endif exit(return_code); } + +void resetImage(camera* renderCam) +{ + for (int x=0; xresolution.x;++x) + for(int y=0; yresolution.y;++y) + { + int index = x + (renderCam->resolution.x*y); + renderCam->image[index] = glm::vec4(0,0,0,-1); + renderCam->objIdBuffer[index] = -1; + } +} \ No newline at end of file diff --git a/src/main.h b/src/main.h index 0bab7cb..75f3136 100755 --- a/src/main.h +++ b/src/main.h @@ -52,6 +52,10 @@ int targetFrame; int iterations; bool finishedRender; bool singleFrameMode; +int mblur=0; +int dof=0; +int currentSelectedObjId = -1; +int textureMode = 0; //------------------------------- //------------GL STUFF----------- @@ -86,6 +90,7 @@ void runCuda(); #else void display(); void keyboard(unsigned char key, int x, int y); + void mouse(int button, int state, int x, int y); #endif //------------------------------- @@ -113,4 +118,9 @@ void deletePBO(GLuint* pbo); void deleteTexture(GLuint* tex); void shut_down(int return_code); +//------------------------------- +//---------MY FUNCTIONS---------- +//------------------------------- +void resetImage(camera* renderCam); + #endif diff --git a/src/materials.h b/src/materials.h new file mode 100644 index 0000000..3014925 --- /dev/null +++ b/src/materials.h @@ -0,0 +1,165 @@ +#ifndef MATERIALS_H +#define MATERIALS_H + +#include "sceneStructs.h" +#include "cudaMat4.h" +#include "glm/glm.hpp" +#include "utilities.h" +#include "perlin.h" + + +__host__ __device__ glm::vec3 bumpColor( glm::vec3 pointObjSpace, map& m, glm::vec3& shadeNormal,int* perlinPerm) +{ + float sineValue = + m.width1 * sinf( (pointObjSpace.x + pointObjSpace.y) * 0.05f + turbulence(10,pointObjSpace.x, pointObjSpace.y,pointObjSpace.z,m.width2, perlinPerm)) + 0.5f; + glm::vec3 perturbation(sineValue,sineValue,sineValue); + shadeNormal = (1-m.width2)*shadeNormal + m.width2*perturbation; + shadeNormal = glm::normalize(shadeNormal); + return m.color1; +} + + +__host__ __device__ glm::vec3 perlin(glm::vec3 pointObjSpace, map& m, int* perlinPerm) +{ + //Copied from my project,volumetric renderer in CIS 560 + + float xPeriod = 0.3; //rotates defines repetition of marble lines in x direction + float yPeriod = 0.1; //defines repetition of marble lines in y direction + float zPeriod = 0; + float turbPower = m.width2; //makes twists + float turbSize = m.width1; //initial size of the turbulence + + float xyzValue = pointObjSpace.x * xPeriod + pointObjSpace.y * yPeriod + pointObjSpace.z*zPeriod + turbPower*turbulence(10,pointObjSpace.x, pointObjSpace.y,pointObjSpace.z,turbSize, perlinPerm); + float sineValue = fabs(sin(xyzValue * PI)); + + return sineValue*m.color1 + (1-sineValue)*m.color2; +} + + + +__host__ __device__ glm::vec3 marble(glm::vec3 pointObjSpace, map& m, int* perlinPerm) +{ + //From http://www.codermind.com/articles/Raytracer-in-C++-Part-III-Textures.html + float sineValue = + m.width1 * sinf( (pointObjSpace.x + pointObjSpace.y) * 0.05f + turbulence(10,pointObjSpace.x, pointObjSpace.y,pointObjSpace.z,m.width2, perlinPerm)) + 0.5f; + + + return sineValue*m.color1 + (1-sineValue)*m.color2; + +} + + +__host__ __device__ glm::vec3 checkerboardColor( glm::vec3 pointObjSpace, map& m) +{ + if(m.smooth) + { + float t = (2 + sinf(PI*pointObjSpace.x/m.width1)+sinf(PI*pointObjSpace.y/m.width2))/4; + return t*m.color1 + (1-t)*m.color2; + } + + if ( sinf(PI*pointObjSpace.x/m.width1) > 0 && sinf(PI*pointObjSpace.y/m.width2) > 0 ) + return m.color1; + else + return m.color2; +} + +__host__ __device__ glm::vec3 hStripesColor( glm::vec3 pointObjSpace, map& m) +{ + if(m.smooth) + { + float t = (1 + sinf(PI*pointObjSpace.y/m.width1))/2; + return t*m.color1 + (1-t)*m.color2; + } + + if ( sinf(PI*pointObjSpace.y/m.width1) > 0) + return m.color1; + else + return m.color2; +} + +__host__ __device__ glm::vec3 vStripesColor( glm::vec3 pointObjSpace, map& m) +{ + if(m.smooth) + { + float t = (1 + sinf(PI*pointObjSpace.x/m.width1))/2; + return t*m.color1 + (1-t)*m.color2; + } + + if ( sinf(PI*pointObjSpace.x/m.width1) > 0) + return m.color1; + else + return m.color2; +} + + +__host__ __device__ glm::vec3 getSurfaceColor(glm::vec3 shadePoint, glm::vec3& shadeNormal,material& mtl,int objId, staticGeom* geoms, map* maps,int* perlinData) +{ + glm::vec3 pointInObjSpace; + + if (geoms[objId].type == SPHERE) + { + glm::vec3 transformedCenter = multiplyMV( geoms[objId].transform, glm::vec4(0,0,0,1.0)); + //glm::vec3 northPoleDir = glm::normalize(multiplyMV( geoms[objId].transform, glm::vec4(0,1,0,0.0))); + //glm::vec3 equatorDir =glm::normalize(multiplyMV( geoms[objId].transform, glm::vec4(1,0,0,0.0))); + glm::vec3 centerToIntersection = glm::normalize(shadePoint - transformedCenter); + + float u = atan2(centerToIntersection.z,centerToIntersection.x)/(2*PI); + float v = asinf(centerToIntersection.y)/PI; + + //float r= acosf( -glm::dot( northPoleDir,centerToIntersection)); + //float v = r/PI; + //float theta = (0.5*acosf( glm::dot(equatorDir,centerToIntersection))/(sinf(r)*PI)); + //float u = v; + //if( glm::dot(glm::cross(northPoleDir,equatorDir),centerToIntersection)>0) + //{ + // u = theta; + //} + //else + // u = 1 - theta; + pointInObjSpace = glm::vec3(u,v,0); + } + else + { + pointInObjSpace = multiplyMV( geoms[objId].inverseTransform, glm::vec4(shadePoint,1.0)); + + float u = 0; + float v = 0; + if (fabs(pointInObjSpace.x)>=0.5f-0.001f && fabs(pointInObjSpace.x)<=0.5f+0.001f) + { + u = pointInObjSpace.y + 0.5f; + v = pointInObjSpace.z + 0.5f; + } + else if (fabs(pointInObjSpace.y)>=0.5f-0.001f && fabs(pointInObjSpace.y)<=0.5f+0.001f) + { + u = pointInObjSpace.x + 0.5f; + v = pointInObjSpace.z + 0.5f; + } + else + { + u = pointInObjSpace.x + 0.5f; + v = pointInObjSpace.y + 0.5f; + } + + pointInObjSpace = glm::vec3(u,v,0); + } + + map m = maps[mtl.mapID]; + + if (m.type == BASE) + return mtl.color; + if (m.type == CHECKERBOARD) + return checkerboardColor(pointInObjSpace,m); + else if (m.type == VSTRIPE) + return vStripesColor(pointInObjSpace,m); + else if (m.type == HSTRIPE) + return hStripesColor(pointInObjSpace,m); + else if (m.type == MARBLE) + return marble(shadePoint,m,perlinData); + else if (m.type == BUMP) + return bumpColor(shadePoint,m,shadeNormal,perlinData); + else if (m.type == PERLIN) + return perlin(shadePoint,m,perlinData); + return mtl.color; +} + +#endif diff --git a/src/perlin.h b/src/perlin.h new file mode 100644 index 0000000..3ceec32 --- /dev/null +++ b/src/perlin.h @@ -0,0 +1,78 @@ +#ifndef PERLIN_H +#define PERLIN_H + +#include "sceneStructs.h" +#include "cudaMat4.h" +#include "glm/glm.hpp" + + +#include +/* +The following code is copied from perlin noise +http://www.codermind.com/articles/Raytracer-in-C++-Part-III-Textures.html +*/ + + +__device__ __host__ float fade(float t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +__device__ __host__ float lerp_perlin(float t, float a, float b) { + return a + t * (b - a); +} + +__device__ __host__ float grad(int hash, float x, float y, float z) { + int h = hash & 15; + // CONVERT LO 4 BITS OF HASH CODE + float u = h<8||h==12||h==13 ? x : y, // INTO 12 GRADIENT DIRECTIONS. + v = h < 4||h == 12||h == 13 ? y : z; + return ((h & 1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v); +} + +__device__ __host__ float noise(float x, float y, float z, int* perlinPerm) { + int X = (int)floor(x) & 255, // FIND UNIT CUBE THAT + Y = (int)floor(y) & 255, // CONTAINS POINT. + Z = (int)floor(z) & 255; + x -= floor(x); // FIND RELATIVE X,Y,Z + y -= floor(y); // OF POINT IN CUBE. + z -= floor(z); + float u = fade(x), // COMPUTE FADE CURVES + v = fade(y), // FOR EACH OF X,Y,Z. + w = fade(z); + int A = perlinPerm[X]+Y, // HASH COORDINATES OF + AA = perlinPerm[A]+Z, // THE 8 CUBE CORNERS, + AB = perlinPerm[A+1]+Z, + B = perlinPerm[X+1]+Y, + BA = perlinPerm[B]+Z, + BB = perlinPerm[B+1]+Z; + + + return + lerp_perlin(w, lerp_perlin(v, lerp_perlin(u, grad(perlinPerm[AA], x, y, z), // AND ADD + grad(perlinPerm[BA], x-1, y, z)), // BLENDED + lerp_perlin(u, grad(perlinPerm[AB], x, y-1, z), // RESULTS + grad(perlinPerm[BB], x-1, y-1, z))), // FROM 8 + lerp_perlin(v, lerp_perlin(u, grad(perlinPerm[AA+1], x, y, z-1), // CORNERS + grad(perlinPerm[BA+1], x-1, y, z-1)),// OF CUBE + lerp_perlin(u, grad(perlinPerm[AB+1], x, y-1, z-1 ), + grad(perlinPerm[BB+1], x-1, y-1, z-1 )))); +} + + +__host__ __device__ float turbulence(int l,float x, float y, float z, float turbPower, int* perlinPerm) +{ + float turb = 0.0f; + for (int level = 1; level < l; level ++) + { + turb += (1.0f / level ) + * fabsf(float(noise(level * turbPower *x, + level * turbPower *y, + level * turbPower *z,perlinPerm))); + } + return turb; +} + + + +#endif \ No newline at end of file diff --git a/src/raytraceKernel.cu b/src/raytraceKernel.cu index 87a65a6..1f09e36 100755 --- a/src/raytraceKernel.cu +++ b/src/raytraceKernel.cu @@ -15,6 +15,13 @@ #include "interactions.h" #include #include "glm/glm.hpp" +#include +#include +#include +#include "glm/gtc/matrix_transform.hpp" +#include "glm/gtc/matrix_inverse.hpp" +#include "materials.h" + void checkCUDAError(const char *msg) { cudaError_t err = cudaGetLastError(); @@ -35,67 +42,76 @@ __host__ __device__ glm::vec3 generateRandomNumberFromThread(glm::vec2 resolutio return glm::vec3((float) u01(rng), (float) u01(rng), (float) u01(rng)); } -//Kernel that does the initial raycast from the camera. -__host__ __device__ ray raycastFromCameraKernel(glm::vec2 resolution, float time, int x, int y, glm::vec3 eye, glm::vec3 view, glm::vec3 up, glm::vec2 fov){ - - int index = x + (y * resolution.x); - - thrust::default_random_engine rng(hash(index*time)); - thrust::uniform_real_distribution u01(0,1); - - //standard camera raycast stuff - glm::vec3 E = eye; - glm::vec3 C = view; - glm::vec3 U = up; - float fovx = fov.x; - float fovy = fov.y; - - float CD = glm::length(C); - - glm::vec3 A = glm::cross(C, U); - glm::vec3 B = glm::cross(A, C); - glm::vec3 M = E+C; - glm::vec3 H = (A*float(CD*tan(fovx*(PI/180))))/float(glm::length(A)); - glm::vec3 V = (B*float(CD*tan(-fovy*(PI/180))))/float(glm::length(B)); + +//Function that does the initial raycast from the camera +__host__ __device__ ray raycastFromCameraKernel(glm::vec2 resolution, float time, int x, int y, glm::vec3 eye, glm::vec3 view, glm::vec3 up, glm::vec2 fov,float focalDist,float aperture, int dof){ - float sx = (x)/(resolution.x-1); - float sy = (y)/(resolution.y-1); + ray r; + float theta = fov.x*PI/180.0f; + float phi = fov.y*PI/180.0f; + + glm::vec3 A = glm::cross(view,up); + glm::vec3 B = glm::cross(A,view); + glm::vec3 M = eye+view; + glm::vec3 H = glm::normalize(A)*glm::length(view)*tan(theta); + glm::vec3 V = glm::normalize(B)*glm::length(view)*tan(phi); + + float sx= -1.0f; //(float)x/(resolution.x-1); + float sy = -1.0f;//1.0 - (float)y/(resolution.y-1); - glm::vec3 P = M + (((2*sx)-1)*H) + (((2*sy)-1)*V); - glm::vec3 PmE = P-E; - glm::vec3 R = E + (float(200)*(PmE))/float(glm::length(PmE)); + thrust::default_random_engine rng(hash(43231*time)); + thrust::uniform_real_distribution u01(-0.95,0.95); + thrust::uniform_real_distribution u02(-1.0,1.0); + + while( sx<=0.0f || sx>=1.0f || sx<=0.0f || sy>=1.0f) + { + float xrand = x + u01(rng); + float yrand = y + u01(rng); + sx = xrand/(resolution.x-1); + sy = 1.0f - yrand/ (resolution.y-1); + } + + glm::vec3 P = M + (2*sx-1)*H + (2*sy - 1)*V; - glm::vec3 direction = glm::normalize(R); - //major performance cliff at this point, TODO: find out why! - ray r; r.origin = eye; - r.direction = direction; + r.direction = glm::normalize(P-r.origin); + + if(dof && focalDist!=0) + { + float t = (focalDist-r.origin.z)/r.direction.z; + P = r.origin + t*r.direction; + glm::vec3 xaperture = aperture*H; + glm::vec3 yaperture = aperture*V; + r.origin= r.origin + u02(rng)*xaperture + u02(rng)*yaperture; + r.direction = glm::normalize(P-r.origin); + } + r.direction = glm::normalize(P-r.origin); return r; } + //Kernel that blacks out a given image buffer -__global__ void clearImage(glm::vec2 resolution, glm::vec3* image){ - int x = (blockIdx.x * blockDim.x) + threadIdx.x; - int y = (blockIdx.y * blockDim.y) + threadIdx.y; - int index = x + (y * resolution.x); - if(x<=resolution.x && y<=resolution.y){ - image[index] = glm::vec3(0,0,0); +__global__ void clearImage(glm::vec2 resolution, glm::vec4* image){ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if(index<= resolution.x*resolution.y){ + image[index] = glm::vec4(0,0,0,-1); } } //Kernel that writes the image to the OpenGL PBO directly. -__global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3* image){ +__global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec4* image, ray* rays,int iterations){ - int x = (blockIdx.x * blockDim.x) + threadIdx.x; - int y = (blockIdx.y * blockDim.y) + threadIdx.y; - int index = x + (y * resolution.x); + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + int x = rays[index].pixelIndex.x; + int y = rays[index].pixelIndex.y; + int pixelIndex = x + (y * resolution.x); if(x<=resolution.x && y<=resolution.y){ - glm::vec3 color; - color.x = image[index].x*255.0; - color.y = image[index].y*255.0; - color.z = image[index].z*255.0; + glm::vec3 color; + color.x = image[pixelIndex].x*255.0/iterations; + color.y = image[pixelIndex].y*255.0/iterations; + color.z = image[pixelIndex].z*255.0/iterations; if(color.x>255){ color.x = 255; @@ -110,74 +126,356 @@ __global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3* } // Each thread writes one pixel location in the texture (textel) - PBOpos[index].w = 0; - PBOpos[index].x = color.x; - PBOpos[index].y = color.y; - PBOpos[index].z = color.z; + PBOpos[pixelIndex].w = 0; + PBOpos[pixelIndex].x = color.x; + PBOpos[pixelIndex].y = color.y; + PBOpos[pixelIndex].z = color.z; + } } +__device__ bool isLight(int objId, int* lights, int numberOfLights) +{ + for (int i=0; i-EPSILON){ - MAX_DEPTH = depth; - colors[index] = materials[geoms[i].materialid].color; - } - } +/* USED FOR SHARED MEMORY PERFORMANCE TESTS +SOMEHOW THIS CRASHED ON ME AFTER A FEW ITERATIONS + __shared__ int sPerlinData[512]; + if(threadIdx.x<512) + { + sPerlinData[threadIdx.x] = perlinData[threadIdx.x]; + } + __syncthreads(); + */ + if (bounce==1) + { + y = (int) (index/(int)resolution.x); + x = (int) (index%(int)resolution.x); + pixelIndex = index; + r = raycastFromCameraKernel(resolution, time, x, y, cam.position, cam.view, cam.up, cam.fov,cam.focalDist,cam.aperture,dof); + r.active = true; + r.pixelIndex = glm::vec2(x,y); + r.rayColor = glm::vec3(1,1,1); + rays[index].rayColor = r.rayColor; + rays[index].pixelIndex = r.pixelIndex; + } + else + { + r = rays[index]; + x = r.pixelIndex.x; + y = r.pixelIndex.y; + pixelIndex = x + (y*resolution.x); + } + if((x<=resolution.x && y<=resolution.y && r.active)){ + glm::vec3 intersectionPoint; + glm::vec3 intersectionNormal; + int objId = findNearestGeometricIntersection(r,intersectionPoint,intersectionNormal,geoms,numberOfGeoms); - //colors[index] = generateRandomNumberFromThread(resolution, time, x, y); + if (bounce==1 && time< 1.5f) + { + colors[pixelIndex].w = intersectionPoint.z; + objidbuffer[pixelIndex] = objId; + } + if (objId == -1) + { + rays[index].active = false; + rays[index].rayColor = glm::vec3(0,0,0); + return; + } + material mtl = materials[geoms[objId].materialid]; + if (isLight(objId,lights,numberOfLights)) + { + rays[index].active = false; + rays[index].rayColor.x *= mtl.color.x*mtl.emittance; + rays[index].rayColor.y *= mtl.color.y*mtl.emittance; + rays[index].rayColor.z *= mtl.color.z*mtl.emittance; + colors[pixelIndex].x += rays[index].rayColor.x; + colors[pixelIndex].y += rays[index].rayColor.y; + colors[pixelIndex].z += rays[index].rayColor.z; + return; + } + + glm::vec3 emittedColor; + glm::vec3 unabsorbedColor; + int bsdf = calculateBSDF(r,intersectionPoint,intersectionNormal,emittedColor,colors[index],unabsorbedColor,mtl,bounce*time*index); + + if (bsdf == 0) + { + glm::vec3 surfaceColor = getSurfaceColor(intersectionPoint,intersectionNormal,mtl,objId,geoms,maps,perlinData); + r.rayColor.x *= surfaceColor.x; + r.rayColor.y *= surfaceColor.y; + r.rayColor.z *= surfaceColor.z; + } + else if(bsdf == 1) + { + r.rayColor.x *= mtl.specularColor.x; + r.rayColor.y *= mtl.specularColor.y; + r.rayColor.z *= mtl.specularColor.z; + } + else if (bsdf == 2) + { + glm::vec3 surfaceColor = getSurfaceColor(intersectionPoint,intersectionNormal,mtl,objId,geoms,maps,perlinData); + r.rayColor.x *= surfaceColor.x; + r.rayColor.y *= surfaceColor.y; + r.rayColor.z *= surfaceColor.z; + } + + rays[index].origin = r.origin + 0.001f*r.direction; + rays[index].direction = r.direction; + rays[index].active = r.active; + rays[index].pixelIndex = r.pixelIndex; + rays[index].rayColor = r.rayColor; } + +} + +__global__ void createBinaryActiveArray(glm::vec2 resolution,ray* rays,int* activeRaysArray, int* dNumActive) +{ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + + if (index < *dNumActive) + { + activeRaysArray[index] = rays[index].active?1:0; + } } +__global__ void parallelScanOnGPU(int* cudaActiveArray, int* gpuParallelScanTempArray, int* dNumActive,int d) +{ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + + int exponent = powf(2,d-1); + if (index< (*dNumActive) ) + { + if( index>= exponent) + gpuParallelScanTempArray[index] = cudaActiveArray[index-exponent] + cudaActiveArray[index]; + else + gpuParallelScanTempArray[index] = cudaActiveArray[index]; + } + +} + +__host__ void parallelScanActiveArray(int* cudaActiveArray,int* gpuParallelScanTempArray,int* hNumActive,int* dNumActive) +{ + int numberOfThreads = *hNumActive; + float logN = logf(numberOfThreads); + int tileSize = 8; + dim3 threadsPerBlock(tileSize*tileSize); + dim3 fullBlocksPerGrid ( (int) ceil( (float)numberOfThreads/(tileSize*tileSize))); + int* cudaActiveArrayCopy = NULL; + cudaMalloc((void**)&cudaActiveArrayCopy,numberOfThreads*sizeof(int)); + cudaMemcpy(cudaActiveArrayCopy,cudaActiveArray,numberOfThreads*sizeof(int),cudaMemcpyDeviceToDevice); + int* activeArray = cudaActiveArrayCopy; + int* tempArray = gpuParallelScanTempArray; + int dmax = ceil(logN)+3; + + for(int d=1; d<= dmax; ++d) + { + parallelScanOnGPU<<>>(activeArray,tempArray,dNumActive,d); + int *swapTemp = activeArray; + activeArray = tempArray; + tempArray = swapTemp; + } + + if (tempArray != gpuParallelScanTempArray) + cudaMemcpy(activeArray,tempArray,numberOfThreads*sizeof(int),cudaMemcpyDeviceToDevice); + + cudaMemcpy(dNumActive,&gpuParallelScanTempArray[numberOfThreads-1],sizeof(int),cudaMemcpyDeviceToDevice); + + cudaFree(cudaActiveArrayCopy); +} + +__global__ void streamCompact(ray* rays, ray* tempRays, int* rayActiveArray, int* scannedArray,int* dNumActive) +{ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + + if (index < *dNumActive && rayActiveArray[index]) + { + rays[scannedArray[index]-1] = tempRays[index]; + } +} + +__global__ void duplicateRaysArray(ray* dest, ray* src, int* dNumActive) +{ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + + if (index < *dNumActive) + { + dest[index] = src[index]; + } +} + +struct is_not_active +{ + __device__ bool operator() (const ray r) + { + return !r.active; + } +}; + +struct is_active +{ + __device__ bool operator() (const ray r) + { + return r.active; + } +}; + + +__global__ void moveWorld( staticGeom* geoms, staticGeom* prevGeoms, float t,int numberOfGeoms) +{ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + + if(index < numberOfGeoms) + { + t = 1 - t*t; + glm::vec3 newTranslation = t*geoms[index].translation + (1-t)*prevGeoms[index].translation; + glm::mat4 translationMat = glm::translate(glm::mat4(), newTranslation); + glm::mat4 rotationMat = glm::rotate(glm::mat4(), geoms[index].rotation.x, glm::vec3(1,0,0)); + rotationMat = rotationMat*glm::rotate(glm::mat4(), geoms[index].rotation.y, glm::vec3(0,1,0)); + rotationMat = rotationMat*glm::rotate(glm::mat4(), geoms[index].rotation.z, glm::vec3(0,0,1)); + glm::mat4 scaleMat = glm::scale(glm::mat4(), geoms[index].scale); + glm::mat4 a = translationMat*rotationMat*scaleMat; + cudaMat4 m; + glm::mat4 b = glm::transpose(a); + m.x = b[0]; + m.y = b[1]; + m.z = b[2]; + m.w = b[3]; + geoms[index].transform = m; + + a = glm::transpose(glm::inverse(a)); + m.x = a[0]; + m.y = a[1]; + m.z = a[2]; + m.w = a[3]; + geoms[index].inverseTransform = m; + } +} //TODO: FINISH THIS FUNCTION // Wrapper for the __global__ call that sets up the kernel calls and does a ton of memory management -void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iterations, material* materials, int numberOfMaterials, geom* geoms, int numberOfGeoms){ +void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iterations, material* materials, int numberOfMaterials,map* maps,int numberOfMaps, geom* geoms, int numberOfGeoms,int mblur,int dof){ int traceDepth = 1; //determines how many bounces the raytracer traces + int perlinNumbers[512] = { 151,160,137,91,90,15, + 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, + 190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, + 88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166, + 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, + 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208,89,18,169,200,196, + 135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123, + 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, + 23,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167,43,172,9, + 129,22,39,253,19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, + 251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107, + 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127,4,150,254, + 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, + 151,160,137,91,90,15, + 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, + 190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, + 88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166, + 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, + 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208,89,18,169,200,196, + 135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123, + 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, + 23,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167,43,172,9, + 129,22,39,253,19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, + 251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107, + 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127,4,150,254, + 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 + }; + // set up crucial magic + int numberOfThreads = (int)(renderCam->resolution.x)*(int)(renderCam->resolution.y); int tileSize = 8; - dim3 threadsPerBlock(tileSize, tileSize); - dim3 fullBlocksPerGrid((int)ceil(float(renderCam->resolution.x)/float(tileSize)), (int)ceil(float(renderCam->resolution.y)/float(tileSize))); - + dim3 threadsPerBlock(tileSize*tileSize); + dim3 fullBlocksPerGrid ( (int) ceil( (float)numberOfThreads/(tileSize*tileSize))); + //send image to GPU - glm::vec3* cudaimage = NULL; - cudaMalloc((void**)&cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3)); - cudaMemcpy( cudaimage, renderCam->image, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3), cudaMemcpyHostToDevice); + glm::vec4* cudaimage = NULL; + cudaMalloc((void**)&cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec4)); + cudaMemcpy( cudaimage, renderCam->image, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec4), cudaMemcpyHostToDevice); + + int* cudaobjidbuffer = NULL; + cudaMalloc((void**)&cudaobjidbuffer, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(int)); + + //package lights + std::vector lightsVector; + + ray* cudarays = NULL; + cudaMalloc((void**)&cudarays, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(ray)); + + int* cudaperlindata = NULL; + cudaMalloc((void**)&cudaperlindata, 512*sizeof(int)); + cudaMemcpy( cudaperlindata, perlinNumbers, 512*sizeof(int), cudaMemcpyHostToDevice); + + /*ALL STUFF FOR MANUAL STREAM COMPACTION + ray* cudatemprays = NULL; + cudaMalloc((void**)&cudatemprays, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(ray)); + + ////TEST SCAN + //const int testNum = 2048; + //int test[testNum]; + //for(int i=0; iresolution.x*(int)renderCam->resolution.y*sizeof(int)); + ////TEST SCAN + //cudaMalloc((void**)&cudaActiveArray, testNum*sizeof(int)); + //cudaMemcpy( cudaActiveArray,test, testNum*sizeof(int), cudaMemcpyHostToDevice); + + int* dParallelScanTempArray = NULL; + cudaMalloc((void**)&dParallelScanTempArray, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(int)); + + ////TEST SCAN + //cudaMalloc((void**)&dParallelScanTempArray, testNum*sizeof(int)); + + ////TEST SCAN + //numberOfThreads = testNum; + + int* dNumActiveRays = NULL; + cudaMalloc((void**)&dNumActiveRays,sizeof(int)); + cudaMemcpy( dNumActiveRays,&numberOfThreads, sizeof(int), cudaMemcpyHostToDevice); + */ + //package geometry and materials and sent to GPU staticGeom* geomList = new staticGeom[numberOfGeoms]; + staticGeom* geomListPrevFrame = new staticGeom[numberOfGeoms]; + for(int i=0; i 0.0f) + lightsVector.push_back(i); } + staticGeom* cudageoms = NULL; cudaMalloc((void**)&cudageoms, numberOfGeoms*sizeof(staticGeom)); cudaMemcpy( cudageoms, geomList, numberOfGeoms*sizeof(staticGeom), cudaMemcpyHostToDevice); - + + staticGeom* cudageomsPrevFrame = NULL; + cudaMalloc((void**)&cudageomsPrevFrame, numberOfGeoms*sizeof(staticGeom)); + cudaMemcpy( cudageomsPrevFrame, geomListPrevFrame, numberOfGeoms*sizeof(staticGeom), cudaMemcpyHostToDevice); + material* cudamaterials = NULL; cudaMalloc((void**)&cudamaterials, numberOfMaterials*sizeof(material)); cudaMemcpy( cudamaterials, materials, numberOfMaterials*sizeof(material), cudaMemcpyHostToDevice); + map* cudamaps = NULL; + cudaMalloc((void**)&cudamaps, numberOfMaps*sizeof(map)); + cudaMemcpy( cudamaps, maps, numberOfMaps*sizeof(map), cudaMemcpyHostToDevice); + + + int numberOfLights = lightsVector.size(); + int* cudalights = NULL; + cudaMalloc( (void**)&cudalights, numberOfLights*sizeof(int)); + cudaMemcpy(cudalights,&lightsVector[0],numberOfLights*sizeof(int),cudaMemcpyHostToDevice); + //package camera cameraData cam; cam.resolution = renderCam->resolution; @@ -203,21 +532,297 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio cam.view = renderCam->views[frame]; cam.up = renderCam->ups[frame]; cam.fov = renderCam->fov; + cam.aperture = renderCam->aperture; + cam.focalDist = renderCam->focalDist; + + /*TESTING STREAM COMPACTION + int t = numberOfThreads; + for(int k=1; k<=t; k++) + { + cudaMemcpy( dNumActiveRays, &k, sizeof(int),cudaMemcpyHostToDevice); + parallelScanActiveArray(cudaActiveArray,dParallelScanTempArray,&k,dNumActiveRays); + cudaMemcpy(&numberOfThreads,dNumActiveRays,sizeof(int),cudaMemcpyDeviceToHost); + std::cout<<"NUM OF ACTIVE THREADS: "< u01(0,1); + float interpolant = u01(rng); + moveWorld<<>>(cudageoms, cudageomsPrevFrame, interpolant,numberOfGeoms); + } + + thrust::device_ptr thrustRaysArray = thrust::device_pointer_cast(cudarays); + + /* FOR PERFORMANCE TESTING + cudaEvent_t start,stop; + float elapsedTime = 0.0f; + cudaEventCreate(&start); + cudaEventRecord(start,0); + */ + //Following line was used when i did tests with constant memory + //cudaMemcpyToSymbol(perlinData,perlinNumbers,512*sizeof(int),0,cudaMemcpyHostToDevice); + //kernel launches - for(int bounce = 1; bounce <= 1; ++bounce) + for(int bounce = 1; bounce <= 8; ++bounce) { - raytraceRay<<>>(renderCam->resolution, (float)iterations, (float)bounce, cam, traceDepth, cudaimage, cudageoms, numberOfGeoms, cudamaterials, numberOfMaterials); + dim3 compactedBlocksPerGrid ( (int) ceil( (float)numberOfThreads/(tileSize*tileSize))); + raytraceRay<<>>(renderCam->resolution, (float)iterations, (float)bounce, cam, traceDepth, cudaimage,cudaobjidbuffer, cudageoms, numberOfGeoms, cudamaterials, numberOfMaterials,cudamaps,numberOfMaps, cudalights,numberOfLights,cudarays,dof,cudaperlindata); + numberOfThreads = thrust::partition(thrustRaysArray,thrustRaysArray+numberOfThreads,is_active()) - thrustRaysArray; + //numberOfThreads = thrust::remove_if(thrustRaysArray,thrustRaysArray+numberOfThreads,is_not_active()) - thrustRaysArray; + + //MANUAL STREAM COMPACTION ATTEMPT + //duplicateRaysArray<<>>(cudatemprays,cudarays,dNumActiveRays); + //createBinaryActiveArray<<>>(renderCam->resolution,cudarays,cudaActiveArray,dNumActiveRays); + //thrust::inclusive_scan(thrustActiveArray,thrustActiveArray+numberOfThreads,thrustTempScanArray); + //streamCompact<<>>(cudarays,cudatemprays,cudaActiveArray,dParallelScanTempArray,dNumActiveRays); + //cudaMemcpy(dNumActiveRays,&dParallelScanTempArray[numberOfThreads-1],sizeof(int),cudaMemcpyDeviceToDevice); + //numberOfThreads = thrustTempScanArray[numberOfThreads-1]; + //parallelScanActiveArray(cudaActiveArray,dParallelScanTempArray,&numberOfThreads,dNumActiveRays); + //cudaMemcpy(&numberOfThreads,dNumActiveRays,sizeof(int),cudaMemcpyDeviceToHost); + //streamCompact<<>>(cudarays,cudatemprays,cudaActiveArray,dParallelScanTempArray,dNumActiveRays); } - sendImageToPBO<<>>(PBOpos, renderCam->resolution, cudaimage); + sendImageToPBO<<>>(PBOpos, renderCam->resolution, cudaimage,cudarays,iterations); + + + + //retrieve image from GPU + cudaMemcpy( renderCam->image, cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec4), cudaMemcpyDeviceToHost); + if(iterations == 1) + cudaMemcpy( renderCam->objIdBuffer, cudaobjidbuffer, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(int), cudaMemcpyDeviceToHost); + + //free up stuff, or else we'll leak memory like a madman + cudaFree( cudaimage ); + cudaFree( cudageoms ); + cudaFree( cudamaterials ); + cudaFree(cudamaps); + cudaFree(cudalights); + cudaFree(cudarays); + /*CLEANUP FOR MANUAL STREAM COMPACTION DATA + cudaFree(cudatemprays); + cudaFree(cudaActiveArray); + cudaFree(dParallelScanTempArray); + cudaFree(dNumActiveRays);*/ + cudaFree(cudaobjidbuffer); + cudaFree(cudaperlindata); + delete [] geomList; + delete [] geomListPrevFrame; + + // make certain the kernel has completed + cudaThreadSynchronize(); + + /* PERFORMANCE TEST + cudaEventCreate(&stop); + cudaEventRecord(stop,0); + cudaEventSynchronize(stop); + cudaEventElapsedTime(&elapsedTime, start,stop); + std::cout<resolution.x)*(int)(renderCam->resolution.y); + int tileSize = 8; + dim3 threadsPerBlock(tileSize*tileSize); + dim3 fullBlocksPerGrid ( (int) ceil( (float)numberOfThreads/(tileSize*tileSize))); + + //send image to GPU + glm::vec4* cudaimage = NULL; + cudaMalloc((void**)&cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec4)); + cudaMemcpy( cudaimage, renderCam->image, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec4), cudaMemcpyHostToDevice); + + int* cudaobjidbuffer = NULL; + cudaMalloc((void**)&cudaobjidbuffer, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(int)); + + //package lights + std::vector lightsVector; + + ray* cudarays = NULL; + cudaMalloc((void**)&cudarays, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(ray)); + + int* cudaperlindata = NULL; + cudaMalloc((void**)&cudaperlindata, 512*sizeof(int)); + cudaMemcpy( cudaperlindata, perlinNumbers, 512*sizeof(int), cudaMemcpyHostToDevice); + + + //package geometry and materials and sent to GPU + staticGeom* geomList = new staticGeom[numberOfGeoms]; + + for(int i=0; i 0.0f) + lightsVector.push_back(i); + } + + + staticGeom* cudageoms = NULL; + cudaMalloc((void**)&cudageoms, numberOfGeoms*sizeof(staticGeom)); + cudaMemcpy( cudageoms, geomList, numberOfGeoms*sizeof(staticGeom), cudaMemcpyHostToDevice); + + + material* cudamaterials = NULL; + cudaMalloc((void**)&cudamaterials, numberOfMaterials*sizeof(material)); + cudaMemcpy( cudamaterials, materials, numberOfMaterials*sizeof(material), cudaMemcpyHostToDevice); + + map* cudamaps = NULL; + cudaMalloc((void**)&cudamaps, numberOfMaps*sizeof(map)); + cudaMemcpy( cudamaps, maps, numberOfMaps*sizeof(map), cudaMemcpyHostToDevice); + + + int numberOfLights = lightsVector.size(); + int* cudalights = NULL; + cudaMalloc( (void**)&cudalights, numberOfLights*sizeof(int)); + cudaMemcpy(cudalights,&lightsVector[0],numberOfLights*sizeof(int),cudaMemcpyHostToDevice); + + //package camera + cameraData cam; + cam.resolution = renderCam->resolution; + cam.position = renderCam->positions[frame]; + cam.view = renderCam->views[frame]; + cam.up = renderCam->ups[frame]; + cam.fov = renderCam->fov; + cam.aperture = renderCam->aperture; + cam.focalDist = renderCam->focalDist; + + + //kernel launches + + dim3 compactedBlocksPerGrid ( (int) ceil( (float)numberOfThreads/(tileSize*tileSize))); + raytraceRayT<<>>(renderCam->resolution, (float)iterations, cam, traceDepth, cudaimage,cudaobjidbuffer, cudageoms, numberOfGeoms, cudamaterials, numberOfMaterials,cudamaps,numberOfMaps, cudalights,numberOfLights,cudarays,dof,cudaperlindata); + + sendImageToPBO<<>>(PBOpos, renderCam->resolution, cudaimage,cudarays,iterations); + //retrieve image from GPU - cudaMemcpy( renderCam->image, cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3), cudaMemcpyDeviceToHost); + cudaMemcpy( renderCam->image, cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec4), cudaMemcpyDeviceToHost); + if(iterations == 1) + cudaMemcpy( renderCam->objIdBuffer, cudaobjidbuffer, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(int), cudaMemcpyDeviceToHost); //free up stuff, or else we'll leak memory like a madman cudaFree( cudaimage ); cudaFree( cudageoms ); cudaFree( cudamaterials ); + cudaFree(cudamaps); + cudaFree(cudalights); + cudaFree(cudarays); + cudaFree(cudaobjidbuffer); + cudaFree(cudaperlindata); delete [] geomList; // make certain the kernel has completed diff --git a/src/raytraceKernel.h b/src/raytraceKernel.h index 5fcf5a3..d7c7fae 100755 --- a/src/raytraceKernel.h +++ b/src/raytraceKernel.h @@ -20,6 +20,9 @@ #include #endif -void cudaRaytraceCore(uchar4* pos, camera* renderCam, int frame, int iterations, material* materials, int numberOfMaterials, geom* geoms, int numberOfGeoms); +void cudaRaytraceCore(uchar4* pos, camera* renderCam, int frame, int iterations, material* materials, int numberOfMaterials,map* maps,int numberOfMaps, geom* geoms, int numberOfGeoms, int mblur,int dof); + +//FOR TEXTURE MODE +void cudaRaytraceCoreT(uchar4* pos, camera* renderCam, int frame, int iterations, material* materials, int numberOfMaterials,map* maps,int numberOfMaps, geom* geoms, int numberOfGeoms, int mblur,int dof); #endif diff --git a/src/scene.cpp b/src/scene.cpp index 415d627..9955675 100755 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -28,6 +28,9 @@ scene::scene(string filename){ }else if(strcmp(tokens[0].c_str(), "CAMERA")==0){ loadCamera(); cout << " " << endl; + }else if(strcmp(tokens[0].c_str(), "MAP")==0){ + loadMap(tokens[1]); + cout << " " << endl; } } } @@ -140,7 +143,7 @@ int scene::loadCamera(){ float fovy; //load static properties - for(int i=0; i<4; i++){ + for(int i=0; i<6; i++){ string line; utilityCore::safeGetline(fp_in,line); vector tokens = utilityCore::tokenizeString(line); @@ -152,6 +155,10 @@ int scene::loadCamera(){ newCamera.iterations = atoi(tokens[1].c_str()); }else if(strcmp(tokens[0].c_str(), "FILE")==0){ newCamera.imageName = tokens[1]; + }else if(strcmp(tokens[0].c_str(), "FOCALDIST")==0){ + newCamera.focalDist = atof(tokens[1].c_str()); + }else if(strcmp(tokens[0].c_str(), "APERTURE")==0){ + newCamera.aperture = atof(tokens[1].c_str());; } } @@ -209,10 +216,12 @@ int scene::loadCamera(){ renderCam = newCamera; //set up render camera stuff - renderCam.image = new glm::vec3[(int)renderCam.resolution.x*(int)renderCam.resolution.y]; + renderCam.image = new glm::vec4[(int)renderCam.resolution.x*(int)renderCam.resolution.y]; renderCam.rayList = new ray[(int)renderCam.resolution.x*(int)renderCam.resolution.y]; + renderCam.objIdBuffer = new int[(int)renderCam.resolution.x*(int)renderCam.resolution.y]; for(int i=0; i tokens = utilityCore::tokenizeString(line); @@ -257,9 +266,67 @@ int scene::loadMaterial(string materialid){ }else if(strcmp(tokens[0].c_str(), "EMITTANCE")==0){ newMaterial.emittance = atof(tokens[1].c_str()); + }else if(strcmp(tokens[0].c_str(), "DIFFCOEFF")==0){ + newMaterial.diffuseCoefficient = atof(tokens[1].c_str()); + }else if(strcmp(tokens[0].c_str(), "MAPID")==0){ + newMaterial.mapID = atoi(tokens[1].c_str()); } } materials.push_back(newMaterial); return 1; } } + +int scene::loadMap(string mapid){ + int id = atoi(mapid.c_str()); + if(id!=maps.size()){ + cout << "ERROR: MAP ID does not match expected number of maps" << endl; + return -1; + }else{ + cout << "Loading Map " << id << "..." << endl; + map newMap; + + //load static properties + for(int i=0; i<5; i++){ + string line; + utilityCore::safeGetline(fp_in,line); + vector tokens = utilityCore::tokenizeString(line); + if(strcmp(line.c_str(), "base")==0){ + cout << "Creating new base map..." << endl; + newMap.type = BASE; + }else if(strcmp(line.c_str(), "hstripe")==0){ + cout << "Creating new hstripe map..." << endl; + newMap.type = HSTRIPE; + }else if(strcmp(line.c_str(), "vstripe")==0){ + cout << "Creating new vstripe map..." << endl; + newMap.type = VSTRIPE; + }else if(strcmp(line.c_str(), "checkerboard")==0){ + cout << "Creating new checkerboard map..." << endl; + newMap.type = CHECKERBOARD; + }else if(strcmp(line.c_str(), "marble")==0){ + cout << "Creating new marble map..." << endl; + newMap.type = MARBLE; + }else if(strcmp(line.c_str(), "perlin")==0){ + cout << "Creating new perlin map..." << endl; + newMap.type = PERLIN; + }else if(strcmp(line.c_str(), "bump")==0){ + cout << "Creating new bump map..." << endl; + newMap.type = BUMP; + }else if(strcmp(tokens[0].c_str(), "COL1")==0){ + glm::vec3 color( atof(tokens[1].c_str()), atof(tokens[2].c_str()), atof(tokens[3].c_str()) ); + newMap.color1 = color; + }else if(strcmp(tokens[0].c_str(), "WIDTH1")==0){ + newMap.width1 = atof(tokens[1].c_str()); + }else if(strcmp(tokens[0].c_str(), "COL2")==0){ + glm::vec3 color( atof(tokens[1].c_str()), atof(tokens[2].c_str()), atof(tokens[3].c_str()) ); + newMap.color2 = color; + }else if(strcmp(tokens[0].c_str(), "WIDTH2")==0){ + newMap.width2 = atof(tokens[1].c_str()); + }else if(strcmp(tokens[0].c_str(), "SMOOTH")==0){ + newMap.smooth = atoi(tokens[1].c_str()); + } + } + maps.push_back(newMap); + return 1; + } +} \ No newline at end of file diff --git a/src/scene.h b/src/scene.h index 9bfa71f..e0029f6 100755 --- a/src/scene.h +++ b/src/scene.h @@ -21,6 +21,7 @@ class scene{ ifstream fp_in; int loadMaterial(string materialid); int loadObject(string objectid); + int loadMap(string mapid); int loadCamera(); public: scene(string filename); @@ -28,6 +29,7 @@ class scene{ vector objects; vector materials; + vector maps; camera renderCam; }; diff --git a/src/sceneStructs.h b/src/sceneStructs.h index b10f1cf..f2fd287 100755 --- a/src/sceneStructs.h +++ b/src/sceneStructs.h @@ -12,10 +12,14 @@ #include enum GEOMTYPE{ SPHERE, CUBE, MESH }; +enum MAPTYPE{ BASE,CHECKERBOARD,VSTRIPE,HSTRIPE,MARBLE,BUMP,PERLIN}; struct ray { glm::vec3 origin; glm::vec3 direction; + bool active; + glm::vec2 pixelIndex; + glm::vec3 rayColor; }; struct geom { @@ -45,6 +49,8 @@ struct cameraData { glm::vec3 view; glm::vec3 up; glm::vec2 fov; + float focalDist; + float aperture; }; struct camera { @@ -52,15 +58,19 @@ struct camera { glm::vec3* positions; glm::vec3* views; glm::vec3* ups; + int* objIdBuffer; int frames; glm::vec2 fov; unsigned int iterations; - glm::vec3* image; + glm::vec4* image; ray* rayList; std::string imageName; + float focalDist; + float aperture; }; struct material{ + int mapID; glm::vec3 color; float specularExponent; glm::vec3 specularColor; @@ -71,6 +81,17 @@ struct material{ glm::vec3 absorptionCoefficient; float reducedScatterCoefficient; float emittance; + float diffuseCoefficient; +}; + +struct map +{ + enum MAPTYPE type; + glm::vec3 color1; + glm::vec3 color2; + float width1; + float width2; + int smooth; }; #endif //CUDASTRUCTS_H