About Store Forum Documentation Contact



Post Reply 
ShaderParamChange problem
Author Message
Pherael Offline
Member

Post: #1
ShaderParamChange problem
Hi, when I use LinkShaderParamChanges with more than one mesh in single drawing function it affect drawing other unrelated objects.

I have class Wall, with drawing function with code like this:
PHP Code:
LinkShaderParamChanges(changes); 
mesh->draw(_matrix_scaled);
UnlinkShaderParamChanges(changes);

LinkShaderParamChanges(changes); 
extraMesh->draw(_matrix_scaled);
UnlinkShaderParamChanges(changes); 
Its draw mesh of wall and additional mesh, both meshes are affected by ShaderParamChanges. Problem don't occure if I draw extra mesh without ShaderParamChanges.

I link, draw, then unlink ShaderParamChanges for each one. Yet, it affect some others object (these object don't use any ShaderParamChanges)



P.S I tried do something like this, effect is the same.
PHP Code:
LinkShaderParamChanges(changes); 
mesh->draw(_matrix_scaled);
extraMesh->draw(_matrix_scaled);
UnlinkShaderParamChanges(changes); 
05-28-2018 01:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: ShaderParamChange problem
Investigating now.
05-29-2018 01:09 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: ShaderParamChange problem
Hi,

So to confirm, the walls use LinkShaderParamChanges, and the green plant-like object doesn't use LinkShaderParamChanges? However the green plant is affected by the LinkShaderParamChanges from the walls?

First look at engine rendering codes look OK.
So I have to do some more tests.
It would help if you could provide some test case, a small mini project.

Edit:
When you call this method:
Code:
ShaderParamChange& ShaderParamChange::set(ShaderParam *param, Bool restore=false) {T.param=param; T.restore=restore; return T;}
if you set "restore=true" does it help?
05-29-2018 01:48 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: ShaderParamChange problem
I've made this commit in the Beta branch:
https://github.com/Esenthel/EsenthelEngi...9ad9a80dfc

To remove this parameter, and always restore the values.
Dooes setting "restore=true" or patching the engine with the commit help?
05-29-2018 02:21 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #5
RE: ShaderParamChange problem
Esenthel Wrote:So to confirm, the walls use LinkShaderParamChanges, and the green plant-like object doesn't use LinkShaderParamChanges? However the green plant is affected by the LinkShaderParamChanges from the walls?
Yes, that was the problem.

Quote:if you set "restore=true" does it help?
It's acctually the oposite. I was using "restore=true" all the time. I just for curiosity change to"restore=false" and somehow it fix the problem!

Code:
changes.clear();
changes.New().set(Renderer.material_color, false) // create a new change and initialize it for changing the 'Material.color' shader parameter
                  .set(Vec4(1, 1, 1, visability)); // set its value
  
   if(mesh && level<=tavern.viewLevel)if(Frustum(mesh->box, _matrix_scaled))
   {
         if(highlightFrame)
         {
            SetHighlight(Color(25, 125, 25)); highlightFrame=false;
         }
                
         if(visability>EPS)
         {
            LinkShaderParamChanges(changes);
            mesh->draw(_matrix_scaled);    
            UnlinkShaderParamChanges(changes);      
         }                
            
         SetVariation(var1);
         if(visability>EPS)
         {
            LinkShaderParamChanges(changes);
            extraMesh->draw(_matrix_scaled);
            UnlinkShaderParamChanges(changes);
         }
[...]
With code like that everything looks working ok! I will make few more test to be sure.

I didn't test Beta branch yet.
(This post was last modified: 05-29-2018 08:22 AM by Pherael.)
05-29-2018 08:16 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: ShaderParamChange problem
OK, I think I know what's the problem.

"restore=true" is needed, however it doesn't work correctly.

Just a note: the "restore" parameter will be completely removed in next release.

The fix will be uploaded tomorrow.
05-29-2018 08:46 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: ShaderParamChange problem
Please check the latest version, I think it should be fine now.
Both Source and Binary editions have been updated.
05-30-2018 03:13 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #8
RE: ShaderParamChange problem
Thank you,
I made few test and everything works great.
(This post was last modified: 05-30-2018 10:40 AM by Pherael.)
05-30-2018 10:28 AM
Find all posts by this user Quote this message in a reply
Post Reply