About Store Forum Documentation Contact



Post Reply 
Material Ambient
Author Message
fatcoder Offline
Member

Post: #1
Material Ambient
Just wondering if it is possible to enable the ambient on a material in code?

In the Material Editor, there are sliders for the AmbRed, AmbGreen and AmbBlue, which works fine. However if I leave them at zero and then try and set the material's ambient in code, it doesn't work. Even after calling validate on the material.

The only way I can get it to work is to set the ambient in the material editor to something other than zero. That seems to "enable" the ambient on the material. I can then freely change the ambient in the code and it works fine. The problem with this is the requirement to set an ambient in the material editor, which I don't want on the material by default. Only want it on when I set it in code.

Is this a bug or am I doing something wrong?

Here's the code that doesn't work, just to be clear.

Code:
MaterialLock = Materials("test.mtrl");
MaterialLock->ambient = Vec(1,0,0);
MaterialLock->validate();
01-01-2013 02:20 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Material Ambient
after doing above please reupdate shaders for meshes using this material
Mesh.setShader for specific mesh
or
D.setShader(&material) for all meshes at once
01-06-2013 10:50 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Material Ambient
Hmm... setShader appears to partly solve the problem. I changed the code like this. Note that "red" is set by the object to determine the amount of red to use in the ambient (either 0 off or 1 on).

Code:
MaterialLock = Materials("test.mtrl");
MaterialLock->ambient = Vec(red,0,0);
mesh->setShader();

If mesh A (red=1) is the only mesh in the view frustum, then it works correctly and mesh A draws with a red ambient. However, if I rotate the camera so mesh B (red=0) comes into view, then both meshes change to draw with no red ambient??
01-07-2013 01:54 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Material Ambient
Probably they share the same material.
I recommend using SetHighlight for highlighting meshes
SetHighlight(value); mesh.draw();
SetHighlight(TRANSPARENT); // disable
01-19-2013 09:59 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #5
RE: Material Ambient
I thought they might have been sharing the same material too, but I created separate materials for each object.

Anyway, I have a mesh drawn with a Blend material and I need to highlight it. I'm experimenting with SetHighlight however it doesn't seem to work with materials that use any of the Blend techs? Is that right, or am I doing something wrong?
01-27-2013 08:08 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #6
RE: Material Ambient
Sorry to bump this, but really want to find out if SetHighlight is supposed to work with Blend tech materials or not? If not, is there any other way to highlight a mesh bar writing a custom shader?
01-30-2013 03:00 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Material Ambient
Will work in next SDK
02-05-2013 12:09 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #8
RE: Material Ambient
Thank you very much.
02-06-2013 07:28 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #9
RE: Material Ambient
Just tested out using SetHighlight with a blend tech material. It works when drawing the mesh with a matrix, but not with a skeleton.

Just to be specific, SetHighlight with blend tech material works with this.

Code:
mesh>draw(matrix);

But not with this.

Code:
mesh->draw(skeleton);

Is this a limitation, bug, or am I doing something wrong?
02-24-2013 03:43 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Material Ambient
Thanks for reporting the issue, indeed higlight was ignored for skinned blended meshes, I am just making it work, will be ok in next sdk.
02-27-2013 03:22 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #11
RE: Material Ambient
Brilliant!
02-27-2013 03:23 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #12
RE: Material Ambient
Just got this through on the latest update and it now works for blended meshes, which is great.

However, any of my meshes drawn with a custom shader are obviously not affected by SetHighlight. So I'm just wondering, is the SetHighlight color passed into any accessible shader parameter somewhere, so it can be used in custom shaders? I know I could pass it into my own parameter, but just want to check that there isn't already one there that I'm missing.
04-14-2013 11:16 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #13
RE: Material Ambient
Searching for highlight or sethighlight in the shader headers would have given you this:
Code:
lVec4 Highlight; // this can be modified by engine's 'SetHighlight' function
wink
04-17-2013 01:04 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #14
RE: Material Ambient
Oh wow. I'm normally so careful about checking the headers before posting. Not sure how I missed that.
Sorry for wasting your time. lol
04-18-2013 11:13 AM
Find all posts by this user Quote this message in a reply
Post Reply