Include custom functions in shader


photo

Recommended Posts

Hi all,

I am currently trying to create a custom shader and want to define an overall header file with custom functions that are used for multiple shaders. When creating an custom shader and using the #include-directive for my custom header file in a .basemat-material, the editor crashes with the fatal error "RenderManager::createTexture2d(): can't create texture". The header file is for now mostly empty, just implemented the #ifndef/#define directive. Also, this happens with an already working material by just using the #include-directive.

Second: Is it possible to store such header files only in the project directory and not in the main folder of the Unigine SDK?

Thanks

Christian

Link to post

Hello!

23 hours ago, christian.wolf2 said:

When creating an custom shader and using the #include-directive for my custom header file in a .basemat-material, the editor crashes with the fatal error

Could you share those files with us? This will help more quickly locate the problem before we can submit the problem to the developers.

Thanks!

Link to post

Hi @bmyagkov,

nevermind I got it working. What solves my issue (and answers my second question) is, putting the header file into the local project folder, starting within the data-folder, the editor doesn't crash any more. The main misunderstanding is, that custom include directives still needs to be started with "<path/to/your/shader/functions.h>" instead of ""path/to/your/shader/functions.h"".

Still one bug remains, editor does crash if the file couldn't be found. To reproduce the issue:

  1. Create your own shader file and include it into your project. (I use that one attached).
  2. Within the .basemat file, add an #include-directive with wrong data path. Save the file.
  3. Let the opened editor reload the shader, stating in the console-log, that the file you want to include was not found.
  4. Switch to materials-tab and select the .basemat-file. The editor crashes with "RenderManager::createTexture2d(): can't create texture".

Best

Christian

deferred_material_sample.basemat

Edited by christian.wolf2
Link to post

Dear @christian.wolf2,

I think I caught one point in your discussion.

Quote

Second: Is it possible to store such header files only in the project directory and not in the main folder of the UNIGINE SDK?

For Custom implementation I am using separate folder. Then In project I just create a Mount point in editor. All your textures, materials, properties, plugins and other things are taken up by UNIGINE asset management. This is helpful because when New UNIGINE SDK comes. Just define mount point in project. 

The custom implementation will remain reusable and updating them for new SDK is simple that pushing it in UNIGINE SDK folders or every Project Folder.

I hope this helps for this second point.

Rohit

  • Thanks 1
Link to post
15 hours ago, christian.wolf2 said:

Still one bug remains, editor does crash if the file couldn't be found. To reproduce the issue:

  1. Create your own shader file and include it into your project. (I use that one attached).
  2. Within the .basemat file, add an #include-directive with wrong data path. Save the file.
  3. Let the opened editor reload the shader, stating in the console-log, that the file you want to include was not found.
  4. Switch to materials-tab and select the .basemat-file. The editor crashes with "RenderManager::createTexture2d(): can't create texture".

Best

Christian

deferred_material_sample.basemat 4.06 kB · 1 download

No success to reproduce issue on my side. There is a lot of warnings but editor still running strong.

Which one SDK are you using?

изображение.png

Link to post

Hi @rohit.gonsalves

thanks for your input. Indeed an seperate mount point is a very good idea. Will try to get it work from here. The main issue for me was that I thought using own header files (like in C++) have to use quotation marks instead of angle brackets. Using first one resulting in an editor crash as well, but with different error code than current one.

 

@bmyagkov

I attached you a short video but didn't do any different.

I am using the latest engineering version and an NVIDIA 1080TI as a graphic card.

Link to post