Jump to content

Passing parameter to custom post material


photo

Recommended Posts

Posted

Hi, I'm having trouble passing a parameter to a custom post-processing shader. I've narrowed the issue down by creating a new project and adding the example material from [1] to this project.The material is added correctly, and the slider for the parameter is added to the GUI as well. The value passed to the shader seems to always be 0, however. I can verify that the shader is otherwise running correctly by substituting the parameter with a constant.

You can find the created project at https://www.libavg.de/owncloud/index.php/s/0NaWHFNuwEx6nKr

Have I made an error in following the instructions or is this a bug?

Regards,

  Uli

[1] https://developer.unigine.com/en/docs/2.7.1/code/uusl/create_post

 

Posted

Hi Uli,

Try removing the parameters_prefix element from the material file, should look like this:

<?xml version="1.0" encoding="utf-8"?>
<base_material version="2.0" name="custom_post" editable="0">

	<!-- Post-effect shaders -->
	<shader pass="post"
		defines="BASE_POST"
		vertex="shaders/vertex/post.vert"
		fragment="shaders/fragment/post.frag"/>
	
	<!-- Textures -->
	<texture name="color" pass="post" unit="0" type="procedural"/>
	
	<!-- Parameters -->
	<parameter name="grayscale_power" type="slider" shared="1" min="0.0" max="1.0"
	flags="max_expand">0.5</parameter>
	
</base_material>

Or you can  add an "m_" prefix to the parameter name, this should also save this issue.

Seems like a bug in documentation, that was fixed in 2.7.2 (looks like it remains in 2.7.1), I'll make sure to fix it in 2.7.1 also.

We are sorry for the inconvenience caused!

Thank you!

  • Like 1
Posted

Thanks for the quick reply, that fixes it.

However, I do have to ask: Don't you check if your samples work?

Posted (edited)

Ok, so that fixed it in the scene editor, but I'm not sure how to set the same parameter in code. It seems that

Materials *pMaterials = Materials::get();
pMaterial = pMaterials->findMaterial("chromakey_post_0");
pMaterial->setParameterSlider(m_pMaterial->findParameter("key_hue", val);

is not enough, because after this, the parameter is always set to 0. Can you give me a tip?

Thanks!

Edited by uzadow
Posted

Hi Uli, 

Yes, we do check our samples, but sometimes bugs do appear, we're sorry for the inconvenience caused!

When setting parameter values for materials please make sure they're not read-only (like in case of a base material).

Try this code to see the difference, the second part (for chromakey_post_0 inherited material) should work for your case:

	Materials *pMaterials = Materials::get();
	MaterialPtr pMaterial;

	float val = 0.5f;
	// 1) Trying to change the value of the key_hue parameter of the non-editable base material
	pMaterial = pMaterials->findMaterial("chromakey_post");
	pMaterial->setParameterSlider(pMaterial->findParameter("key_hue"), val);
	Log::message("Parameter value:%f (editable = %d)\n", pMaterial->getParameterSlider(pMaterial->findParameter("key_hue")), pMaterial->isEditable());
	
	// 2) Trying to change the value of the key_hue parameter of the inherited editable material
	pMaterial = pMaterials->findMaterial("chromakey_post_0");
	pMaterial->setParameterSlider(pMaterial->findParameter("key_hue"), val);
	Log::message("Parameter value:%f (editable = %d)\n", pMaterial->getParameterSlider(pMaterial->findParameter("key_hue")), pMaterial->isEditable());

 

Hope this helps!

Thank you!

 

  • Like 1
×
×
  • Create New...