[SOLVED]access material flags in glsl

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ritti
Posts: 90
Joined: Tue Apr 10, 2012 12:09 pm

[SOLVED]access material flags in glsl

Post by ritti »

Hiho everybody,
as the title says, I'm trying to access material flags in my opengl shader.
The reason why I'm trying this is as follows:

I have a shader for making an effect from completely invisible --> transparent --> visible for multiple objects.
But now I want to use the same shader for the inverted effect (visible --> transparent --> completly invisible)

Well the problem here is:
I have a variable alpha in MyShaderCallBack with

Code: Select all

 
services->setPixelShaderConstant("alpha", &alpha, 1);
if(lower)
  alpha -= 0.025;
else
  alpha += 0.025;
If I use the shader at the same time for all objects for the same effect, it works without any problem.
But if I want to make one object become visible, while the other one becomes invisible, well I would need an object specific flag to pass to the shader.
So I would be able to set the alpha or the inverse of the alpha value.

Code: Select all

if(flag)
alpha = xy;
else alpha = 1 - xy;  
Thats the reason why I thought about material flags, but I don't know if it is even possible to pass object specifig variables to the shader apart of color and position.

But maybe somebody knows a better method to acchieve what I want.
I would like to put this two effects in one shader because I read about limitations from the graphics card, something with 64 shaders per card.
Well, I don't know if I'll need that much, but who knows :)

I hope somebody can help me.
Thanks in advance and best regards
Ritti
Last edited by ritti on Wed Sep 04, 2013 6:20 pm, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: access material flags in glsl

Post by mongoose7 »

You usually set the uniform just before rendering the object. Therefore, by setting it to different values depending on the object to be rendered, you can achieve the result you want.
ritti
Posts: 90
Joined: Tue Apr 10, 2012 12:09 pm

Re: access material flags in glsl

Post by ritti »

Thank you for your reply,
but if I have multiple objects, how can I set a uniform between the rendering of the first object, and the second one?

There isn't any place in the code that says, render object1, render object2, render object3 and so on
Do you know what I mean?

Best regards
Ritti
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: access material flags in glsl

Post by mongoose7 »

There is a callback before an object is rendered. onSetConstants() or something. Look at Example 10.
ritti
Posts: 90
Joined: Tue Apr 10, 2012 12:09 pm

Re: access material flags in glsl

Post by ritti »

Ok so you mean that I can somehow distinguish between the different rendered objects in this callback?
And depending on which object it is, i set the variable?

Because I really dont know how to get the object which is just rendered.

So if I have 3 cubes and want them to look all different but with the same shader, I would change a uniform in dependance of the rendered cube in the OnSetConstants function.
But how do I see in this callback which of the 3 cubes is rendered at the moment to set the appropriate value?

Best regards
Ritti
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: access material flags in glsl

Post by mongoose7 »

Maybe use the userdata parameter?
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: access material flags in glsl

Post by vivekSivamRP »

its simple ritti,
in ur callback class use the below method

void OnSetMaterial(const SMaterial& material)
{
curMaterial = material; // this line gives the material of the object for which it is going to set uniforms
}
use the objects material values to differentiate the alpha values of each object while setting the uniforms.
ritti
Posts: 90
Joined: Tue Apr 10, 2012 12:09 pm

Re: access material flags in glsl

Post by ritti »

Nice, thank you for your answers, it works great now :)
Post Reply