How can I make a renderer from Optix?

Thanks a lot.
I use Optix 4.1.1 now. Haha~

Hi, Detlef, I have a question about this forum. How can I insert a picture into my reply?

I just paint the a red cow by Optix.
I’m quite excited.
So I want to upload the picture. But when I click on the “image” icon, just “” come out. Quite confusing…

I have a new problem.
I want to attach a glass material onto the cow. But I failed.
I just replace the closest hit function. But it seems that the closest hit function doesn’t work. The cow is totally black without any color on it.

The code is as follows.

Program glass_closest_hit = context->createProgramFromPTXFile(ptxPath(""), "glass_closest_hit_radiance");
Program glass_any_hit = context->createProgramFromPTXFile(ptxPath(""), "any_hit_shadow");

	std::vector< optix::Material > optix_materials;

//	for (int i = 0; i < mesh.num_materials; ++i)
		optix::Material material = context->createMaterial();
//		if (mesh.mat_params[i].dissolve < 0.9999f)
			material->setClosestHitProgram(0u, glass_closest_hit);
			material->setAnyHitProgram(1u, glass_any_hit);
	std::cout << "test code " << std::endl;
	mesh.material = optix_materials[0];
	mesh.material["cutoff_color"]->setFloat(0.34f, 0.55f, 0.85f);
	mesh.material["refraction_color"]->setFloat(1.0f, 1.0f, 1.0f);
	mesh.material["reflection_color"]->setFloat(1.0f, 1.0f, 1.0f);
	float3 extinction = make_float3(.80f, .89f, .75f);
	mesh.material["extinction_constant"]->setFloat(log(extinction.x), log(extinction.y), log(extinction.z));
	mesh.material["shadow_attenuation"]->setFloat(0.4f, 0.7f, 0.4f);/**/

	loadMesh( filename, mesh );

I’m quite confused. Why the glass_closest_hit_radiance function doesn’t work?

I used a similar way to modify the OptixTutorial project. I can make the box semitransparent. But I cann’t make the cow in OptixMeshViewer semitransparent. Can you give me some reminder? Thanks a lot!

Let me take a wild guess and say its the variable: “max_depth” wich is initialized in your tutorial.cpp code but not in your MeshViewer.cpp

Yes! You are so smart! I initialize the max_depth=2, and this time the closest_hit function seems work! Thank you very much!!!

Detlef Roettger
I have a problem about mapping. I changed the hdr file in the sample OptixTutorial (Environment: Win10 64bit + VS2017 Community + CUDA v9 + Optix 4.1.1). The hdr file is attached in this reply.
But the program report a runtime error “Scanline width inconsistent”. I debugged this. I found that the ReadScanline function in HDRLoader.cpp made the check and report the error. The reason seems have some relationship with the c3 variable in this function.I changed these variable to unsigned char. And the result seems to be right.
If you have time,you may have a try. (2.04 MB)

Thanks, I’ve reproduced this and filed a bug report against the OptiX samples.

I also tried loading the file into my renderer which uses DevIL to load and store images and saw no problem in there. For actual products I would recommend to use some image library for these kind of tasks instead of the few individual image handling routines of the OptiX examples which just reduce third party library dependencies there.

Thank you very much!

I’m trying to use OpenCV to do these kind of task now.

I’m still working on the renderer. And recently I noticed a problem with my program. When the renderer process some planes, there is much noise or bad points on the plane. I’m quite confused with the phenomenon. I attach a picture which can show the noise. Does anyone know the reason? And how can I solve the problem? Thank you!

That is shadow acne from shadow ray self-intersections of that plane.
Means the shadow rays failed the visibility test because they hit the plane itself.
The radial rings are typical for that kind of artifact.

The simplest way to get rid of this is to increase the scene_epsilon used to offset these rays from their starting geometry until this artifact is gone.
As the name implies, it’s scene (-size) dependent. Try playing with the scene_epsilon value, esp. try 0.0 to experience the full beauty of these artifacts.

There exist more robust ways to prevent such self intersections.


I use OptiX 5.0.0 and CUDA 9.1.85 (on driver 390.65) Is there a reason why you still use 4.1.1 and CUDA 9.0 ?

Detlef Roettger
I tried your advice. Thank you very much! Your approach is quite powerful.
After I increased the “scene_epsilon” in function createContext() , the noise disappered. And I’m still learning your reply.

Dear @m1
I’m new to computer graphics. Numerical analysis by CUDA was my research direction in past few years. The problem you met is quite confusing to me. Now I only know Photon Mapper is a good algorithm in rendering. Actually I can’t understanding the problem you met because my lack of knowledge on computer graphic.
I will learn photon mapper algorithm soon. And after that, I will try to help you solve your problem.

And in your post, you mentioned that you were confusing on Cmake. My project used Cmake list and I think it’s a quite good cross-platform tool to generate makefile or VS project. You can download the software on , open the cmake-gui.exe, and then configure the location of library or compiler. And then click the “Configure”, “generate” button. The VS project will be generated by Cmake.

Many open source library also provide the guide on how to use the library by Cmake. For example I use OpenCV to load the texture file in JPG or PNG format. And the following official page shows the way . And then you can follow the guide to use third-part library in your Optix project.

Dear tonycdy1991,

my main current problem is more related to CMAKE and setting a source project up, so that Detlef can run it on his system. I already provided him a full VS2017 project. And OAC files. But unfortunately he said, that its too hardcoded, so that he cannot use it on his alternative platform.

I have only knowledge about DirectX, Windows and Visual Studio.
yet before I had no need for any CMAKE or similar.
How would you configure such a project?

For example:

#pragma comment( lib, "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/lib/x64/nvrtc.lib")

how do I have to change it, that CMAKE recognizes it?

And where the CMAKElist.txt file must be located. I don’t understand the entire concept. I see its interpreter-like syntax as in a Windows/DOS .bat file. But at which time does it run? Does VS override MSBuild with it?
I would prefer, when there’s a button in VS, where I can press to “Generate CMAKE files”. But that button is in the CMAKE GUI. Does that, what I want? I really don’t know.

Dear m1,
Because I only came into computer graphic less than two months, I thought that learning some books to me is quite necessary. I also do programming.

About my knowledge background, I never used DirectX before and I know nothing about rasterization. I only know it’s the most common approach in CG.

And you mentioned about your confusion on Cmake. Cmake is a cross-platform tool to generate project file on different operation systems. CMAKE on UNIX/Linux can generate MAKEFILE projects. And the CMAKE on Windows can generate Visual Studio projects. The input file which CMAKE uses is “CMakeList.txt”. And the Optix SDK also uses CMAKE. So you can find out a “CMakeList.txt” in Optix SDK.
The total process is as follows:
1, Open cmake-gui.exe and point out that the location where your code and CMakeList.txt are saved. For my Optix SDK, it is D:\ProgramData\NVIDIA Corporation\OptiX SDK 5.0.0\SDK
2, Press the “configure” button and choose the right VS version you use(it is “Visual Studio 15 2017 Win64” for me) and wait a few minutes. CMAKE may fail this step. The common reason for the failure is the wrong path for some library or compiler. So you may need to point out the right location for CMAKE. For example, CMAKE may say it can’t find “CUDA host compiler”, it means that it can’t find the compiler of Visual Studio 2017 community. So you may write the right path for CMAKE. For me, I write “D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe”
3, After configuring, the cmake-gui should report “Configuring done”. And then you can click on the “generate” button to generate Visual Studio project file(*.sln) for your project.
4, And the last step is click on “Open project”. And you can use Visual Studio to do your work.

In CMakeList.txt for Optix SDK, the CUDA library has been included. In my case, CMAKE find out my CUDA automatically. And I guess it will find out the CUDA on your computer too. If not, you may need point out your CUDA installation path for CMAKE.
If you use third-part library, you need add some lines in CMakeList.txt. For example, I used OpenCV. And my CMakeList.txt is attached as an example.
CMakeLists.txt (15.2 KB)

Thank you for the explanation.

To start from zero I deinstalled the OptiX SDK and reinstalled it to have a clean installation
of the original OptiX 5.0.0 SDK; then I used CMAKE GUI with the steps you told me.
I used the default location in C:\ProgramData\NVIDIA Corporation\OptiX SDK 5.0.0\SDK

Then I opened the project. (see screen shot VS_CMakeList0.jpg)
i removed all other sample projects than “optixMeshViewer”

then I opened “CMakeLists.txt” of that project. But its located in the SDK:
…\ProgramData\NVIDIA Corporation\OptiX SDK 5.0.0\SDK\optixMeshViewer\CMakeLists.txt

also optixMeshViewer.cpp is there:
…\ProgramData\NVIDIA Corporation\OptiX SDK 5.0.0\SDK\optixMeshViewer\optixMeshViewer.cpp

these files are not in my build project folder.

Normally now I would copy these files to my project folder, cause I don’t want to modify the original SDK files!
They should remain untouched in the SDK.

But how do I tell CMAKE, that these files have moved ?
That is what I really don’t know.
Do I have to change “CMAKE_CURRENT_SOURCE_DIR” ? But where it is defined?

And I want to change the intermediate directory to
yet its in a sub folder called “optixMeshViewer.dir”

I also looked into CMakeCache.txt where a lot of hard-coded Windows-related path information is present :
CUDA_CUDART_LIBRARY:FILEPATH=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/lib/x64/cudart.lib
CUDA_CUDA_LIBRARY:FILEPATH=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/lib/x64/cuda.lib
CUDA_NVCC_EXECUTABLE:FILEPATH=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/bin/nvcc.exe
CUDA_TOOLKIT_INCLUDE:PATH=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/include
CUDA_TOOLKIT_ROOT_DIR:PATH=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1
CUDA_VS_DIR:STRING=C:/Program Files (x86)/Microsoft Visual Studio 14.0

How should I change that ? CMAKE GUI built it this way. And that is now even more hard-coded than
in my project, which did not use CMAKE at all…

However, maybe Detlef can replace this CMakeCache.txt file on his system.
I don’t see an advantage here: CMAKE builds also hard-coded path information as VS in the .sln and .vcxproj files.

I also don’t understand for what ALL_BUILD and ZERO_CHECK projects are needed. Normally I deleted them;
But now I let them “alive”, maybe CMAKE needs them?

VS2017’s Ctrl-T option obviously also don’t work on identifiers of CMAKE. Its a pain to search
for them manually.

All this is time consuming and for me and I don’t really see any advantages of this, cause
.sln files already contain all data of the project and when CMAKE is so portable,
why can’t it simply convert the .sln and .vcxproj files to its make lists?
CMAKE can write these .sln files but cannot read them?

I then reloaded the VS solution Ray3D.sln and unfortunately again all the deleted projects are “not available” although I already deleted them. This was the main reason why I always removed CMAKE in the past, cause only if all this CMAKE stuff is gone, the project loads correctly.
I again also don’t want to overwrite the original SDK files. And I don’t know where I should remove the other projects from CMAKE.

I also renamed project(OptiX-Samples) into project(Ray3D)
but unfortunately that’s already a change in the original version of the SDK files. I don’t want that.

I also searched in the created project for my project folder name. its present many times!
So which of these files I can delete in my project, that I would submit to another user on
another platform?


Dear m1,

Let me explain. Cmake is a tool to help you produce the project files on different operation systems. It means that you can generate project files by one same CMakeList.txt on different OS. The advantages is cross-platform. If you use VS, the *.sln file can not be recognized by Linux. But CMAKE can help you produce a MAKEFILE for your project on Linux. So you can use Nsight or other IDE to do programming(Nsight can use MAKEFILE). That is the advantage.

I also thought that the original file in Optix SDK should be locked. So I copied the whole file folder to another path. And the steps are as follows:
1, I installed the Optix SDK. The path is “D:\ProgramData\NVIDIA Corporation\OptiX SDK 4.1.1” (I use Optix 4 to explain, Optix 5 is similar. Never mind.). The picture “pic1” shows the result.
2, I copied all the files under “D:\ProgramData\NVIDIA Corporation\OptiX SDK 4.1.1\SDK” to “E:\Project\Optix-Test”. And “E:\Project\Optix-Test” will be my workspace path. I shows this step in “pic2”.
3, Click on cmake-gui.exe. And figure out where the source code are and where your workspace are. Sometimes the path for VS compiler and third-part library are also needed. This step is shown in “pic3”.
4, Press the “Configure” button and wait a few seconds. “pic4” shows this. You see, there is a report which says “Configuring done” at last.
5, Press the “Generate” button. cmake-gui reports “Generating Done” then. “pic5” shows this step.
6, Press the “Open Project” button.

And are you from German? Nice to meet you. I’m from China.

And I think I may add something. The CMakeList.txt in “E:\Project\Optix-Test” have all the configuring information for whole Optix SDK solution. When cmake-gui reads the CMakeList.txt, cmake will run into the child folders under “E:\Project\Optix-Test”. For example, cmake will run into “E:\Project\Optix-Test\optixMeshViewer” and find out there is another CMakeList.txt in “E:\Project\Optix-Test\optixMeshViewer”. And this CMakeList.txt contains the information for optixMeshViewer project. These two CMakeList.txt have a priority. When you produce the VS project file(*.sln) of Optix by Cmake, the CMakeList.txt you use should be the first one which is in “E:\Project\Optix-Test”.

Dear tonycdy1991,

Thank you very much!

It’s very nice to meet you as well.

Tomorrow I will try the 6 steps you told me.

Dear tonycdy1991,

Finally I built it with your help. Thank you.
However, I had to manually setup many folders in that CMAKE GUI and
after building in VS I also had to copy all the DLLs from my old installation.

I only kept the project “optixMeshViewer” and I finally found a description how to do that all
within the CMAKElist.txt file which I would have expected within the INSTALL-WIN.txt
But I’m glad you could help mee to solve this!

I hope, that I can submit a working project to Detlef within the next few days.

Please feel free to contact me for your questions. Now also I want to help/assist you.

If you’re interested in the NVIDIA Denoiser, here is a great video:
This also is a good reason to upgrade to OptiX 5.0