Jump to content

Creating child material of "mesh_base" and write custom ambient Shader


photo

Recommended Posts

Hello ,

 I have written a material

 

<material name="my_custom_material" parent="mesh_base" >
    <options object="mesh_dynamic" transparent="2" order="1"/>
    <state name="workflow">1</state>
    <state name="auxiliary" defines="name" pass_defines="auxiliary"/>
    <blend src="src_alpha" dest="one_minus_src_alpha"/>
    <state name="deferred">0</state>
    <state name="ambient"  type="switch" items="none,opacity,transparent" transparent="2">2</state>
    <parameter name="auxiliary_color" auxiliary="1" type="color">1.0 1.0 1.0 1.0</parameter>
    <parameter name="my_param_a"    workflow="1" shared="1" type="slider">1</parameter>
    <parameter name="my_param_b"      workflow="1" shared="1" type="slider">0</parameter>
    <parameter name="my_param_c"        workflow="1" shared="1" type="slider">0.0</parameter>
    <parameter name="my_param_d"      workflow="1" shared="1" type="slider">0</parameter>
    <shader pass="ambient"  ambient="2" object="mesh_dynamic" defines="BASE_AMBIENT,AMBIENT,ZERO_DEPTH" vertex="shaders/my_custom_material.vert" fragment="shaders/my_custom_material.frag" geometry="shaders/my_custom_material.geom"/>
</material>
 
But my shader specified in shader tag are not used while rendering , but when i
remove the parent material "mesh_base" they are used in rendering .
 
Can you help me ?
Can we override the shaders in child material ?
 
Link to comment

Hi Akshay.Patil,

 

Basically, overriding shaders in child materials shouldn't be a problem.

Seems like in this particular case You were trying to use a reserved state name "ambient", which is used by "Environment and emission" light pass. Try renaming Your "ambient" state to "ambient1" (See below), and let us know about the result.

<material name="my_custom_material" parent="mesh_base" >
    <options object="mesh_dynamic" transparent="2" order="1"/>
    <state name="workflow">1</state>
    <state name="auxiliary" defines="name" pass_defines="auxiliary"/>
    <blend src="src_alpha" dest="one_minus_src_alpha"/>
    <state name="deferred">0</state>
    <state name="ambient1"  type="switch" items="none,opacity,transparent" transparent="2">2</state>
    <parameter name="auxiliary_color" auxiliary="1" type="color">1.0 1.0 1.0 1.0</parameter>
    <parameter name="my_param_a"    workflow="1" shared="1" type="slider">1</parameter>
    <parameter name="my_param_b"      workflow="1" shared="1" type="slider">0</parameter>
    <parameter name="my_param_c"        workflow="1" shared="1" type="slider">0.0</parameter>
    <parameter name="my_param_d"      workflow="1" shared="1" type="slider">0</parameter>
    <shader pass="ambient"  ambient1="2" object="mesh_dynamic" defines="BASE_AMBIENT,AMBIENT,ZERO_DEPTH" vertex="shaders/my_custom_material.vert" fragment="shaders/my_custom_material.frag" geometry="shaders/my_custom_material.geom"/>
</material>
Link to comment

Thanks for Quick reply,

 

I have removed now the ambient state tag completely and also the ambient attribute from "shader" tag.

and i am observing same issue.

 

My shaders are invoked when there is no parent material , but they aren't when i set parent material to "mesh_base".

Link to comment

I reproduced Your issue using the material You provided, the only difference was in shaders. I could check Yours if You wish. Please send Your shaders to fox@unigine.com and I'll try to help You!

 

Sincerely,

Alex

Link to comment

Hello Alex , thanks,

Mine are custom shaders which work with provided param only .

 

 

 

Can you test the material by pasting ambient  mesh_base shaders  in new path and using them in child material.

With some modification like fix color or transparency to differentiate ?

 

Can you also confirm once where the actual issue is Material file , shader or Ungine lib ? 

Link to comment

Hello Priyank.Jain2,

 

I tested Your material (see code below) by modifying a standard mesh_base ambient shader (ambient.shader) and copying it to "data/shaders" folder of my project and renaming it as "ambient_blue.shader". The modification included the following replacements:

line 122: gbuffer.albedo -> float3(0.0f, 0.0f, 1.0f).

line 96: OUT_COLOR.a = gbuffer.transparent -> OUT_COLOR.a = 0.5f;

Everything seems to work fine. Check it out and let me know about the result!

	<material name="my_custom_material" parent="mesh_base">
		<blend src="src_alpha" dest="one_minus_src_alpha"/>
		<options object="mesh_dynamic" order="1" transparent="2"/>
				<shader pass="ambient" object="mesh_static"
					ambient="1"
					ambient1="2"
					defines="BASE_AMBIENT,AMBIENT,TRANSPARENT,SPECULAR,VERTEX_ATTRIBUTE_GEOMETRY,ZERO_DEPTH"
					vertex="shaders/ambient_blue.shader"
					fragment="shaders/ambient_blue.shader"/>
		<state name="workflow">1</state>
		<state name="auxiliary" defines="name" pass_defines="auxiliary"/>
		<state name="deferred">0</state>
		<state name="ambient1" type="switch" transparent="2" items="none,opacity,transparent">2</state>
		<parameter name="auxiliary_color" auxiliary="1" type="color">1.0 1.0 1.0 1.0</parameter>
		<parameter name="my_param_a" type="slider" workflow="1">1</parameter>
		<parameter name="my_param_b" type="slider" workflow="1">0</parameter>
		<parameter name="my_param_c" type="slider" workflow="1">0</parameter>
		<parameter name="my_param_d" type="slider" workflow="1">0</parameter>
	</material>

Sincerely,

Alex

Link to comment

Are you also facing some issue? If not, can you please upload your test project.

 

In the first case (with Your material and my simple shaders, which can be found https://developer.unigine.com/en/docs/2.4/code/uusl/create_forward) I faced the same issue as Yours and it was caused by using a reserved state name "ambient". After changing it to "ambient1" everything was ok. As for the second case (with Your material and standard shaders from the core), I've modified a standard ambient shader for the mesh_base material from the core and placed it to another location as You asked - everything worked fine. Please try to do the same, and let me know about the result.

 

If the problem persists, please send Your shaders to fox@unigine.com so I could check what's wrong.

 

Sincerely,

Alex

Link to comment
×
×
  • Create New...