photo

Custom Deferred Material Problem

Recommended Posts

Hi There,

It was easy to understand and implement the behavior as defined at 

https://developer.unigine.com/en/docs/2.11/code/uusl/create_deferred?rlang=cpp

I have attached the ULON material file. XML material file, Vertex and Fragment shader. Mostly copied from the above tutorial.

But when I did the same with ULON and material file formats, I receive  two problems.

  1. The object renders black. So I though gbufferdefault is setting black color. But setting color to gbuffer.albedo = vec3(1.0, 0.0, 0.0); didn't work. It renders black.
  2. I can not create a child material out of this. Nothing happens.

Here is the screen shot.

image.thumb.png.5466d9e73339f5d108a6f89746f4b637.png

Please advise,

Regards,

Rohit

 

 

Share this post


Link to post

Hello Rohit,

17 hours ago, rohit.gonsalves said:

I have attached the ULON material file. XML material file, Vertex and Fragment shader.

I don't see the files. Have you sent them in a PM or just forgot to drop here?

Thanks.

Share this post


Link to post

Hello Rohit,

When working with GBuffer you need other macros. Instead of MAIN_BEGIN(FRAGMENT_OUT,FRAGMENT_IN) use MAIN_BEGIN_DEFERRED(FRAGMENT_IN) in the fragment shader.

MAIN_BEGIN can be used in fragment shader only if you're not filling GBuffer.

Thanks!

  • Like 1

Share this post


Link to post

Thanks Morbid,

Understood the problem and solution provided, answered the question.

The second issue is still there. I can not create a child material out of it.

Please advise.

Rohit

 

Share this post


Link to post

You're welcome, Rohit.

As for the other issue I'm not sure I follow you. I put the shaders and materials into data folder, changed paths to the shaders. After running the editor I'm free to inherit your material. Is the code the same you're using? Nothing changed?

Is your material packed in UNG archive?

image.png

Share this post


Link to post
Posted (edited)

Dear Morbid,

You are right. When I put this material in data folder and changed the path for vertex and pixel shader. It did work and I could able to inherit the materiel child.

image.png.b1909fd3f071a3ae19c2aa9c570d81b4.png

But I found two material Gotchas.........

1] I put the material to the mount point, I couldn't able to inherit it. I mean nothing happens.

2] I put the material to SDK\data\core\materials and shaders at respective places. and then created a new project for UNG packaging. No inheritance.

3] But with data folder it works.

Now in case of 3rd point, If I assign a child material of custom material to material_ball and use Shift + Translate; I have transparent material ball. This is some kind of an issue.

image.thumb.png.b580a1e5ee08c060063f8161d11f0714.png

These are the cases. I think probably a fix is needed for this.

Regards,

Rohit

Edited by rohit.gonsalves

Share this post


Link to post

Rohit, inheritance works for me every time. How I tested:

  1. Put your basemat and shaders into <sdk>/data/core and created a project
  2. Put the same files in data folder
  3. Made manually UNG archive with your material
  4. Created a mount point (make sure you're making a Read/Write mount) with custom material

Inherit worked in every case. Can you send me core.ung where I can reproduce this issue?

On 7/24/2020 at 11:54 PM, rohit.gonsalves said:

Now in case of 3rd point, If I assign a child material of custom material to material_ball and use Shift + Translate; I have transparent material ball. This is some kind of an issue.

Reproduced this. We'll take a look at this closer this week.

Thanks.

Share this post


Link to post

Got feedback regarding clone issue. It's because you should've used material instancing. Engine has built-in optimization for similar materials rendering.

Replace this part

float4 row_0 = s_transform[0];
float4 row_1 = s_transform[1];
float4 row_2 = s_transform[2];

With:

float4x4 transform = getObjectTransform(IN_INSTANCE);
float4 row_0 = getRow(transform, 0);
float4 row_1 = getRow(transform, 1);
float4 row_2 = getRow(transform, 2);

Also you'll need to manifest this:

STRUCT(VERTEX_IN)
	INIT_ATTRIBUTE(float4,0,POSITION)	// Vertex position
	INIT_ATTRIBUTE(float4,1,TEXCOORD0)	// Vertex texcoord (uv)
	INIT_ATTRIBUTE(float4,2,TEXCOORD1)	// Vertex basis tangent
	INIT_ATTRIBUTE(float4,3,TEXCOORD2)	// Vertex color
	INIT_INSTANCE
END

And add 

INIT_INSTANCE

Hope this helps.

Share this post


Link to post

Rohit, do you store metafiles of your materials in core folder or ung archive? If no, please try with them. This should solve your inherit issue.

Share this post


Link to post

Dear @morbid,

Thanks for looking into these issue. Did not able to check INIT_INSTANCE yet. 

Will do tomorrow and update regarding that too.

Quote

do you store meta files of your materials in core folder or ung archive?

No. Actually, I am mounting the path from external directory. When this happens, Editor is not creating any meta file for it. 

 Editor internally checks this .meta files for inheritance, doesn't it?

If this is the case then I will create meta files by placing it in data folder first and then will copy the same meta file to mount point too. Lets see if that would work. Will keep you posted.

Rohit

Share this post


Link to post

Editor works with assets only, a file without *.meta is not an asset.

Editor also uses core folder as read only, so if you manually place some files in core meta won't be created automatically. As for the mounting point — please check if it's not read only.

Thanks!

Share this post


Link to post

Dear @morbid,

There is no more clone issue after the INIT_INSTANCE and other changes. This is done. :-) Thank you.

I am still not able to create a child material from mounted path. I will surely give it a another take with fresh mind. Please allow some time for this test.

Will keep you posted.

Rohit

Share this post


Link to post