Alpha map materials
It is possible to use separate alpha maps for the materials? If so, what is the keyword used in that case? If not, which is the right way to make textures with alpha colors (like magenta, blue, or black). I looked at the Material System documentation but it didn't work. It is also possible to use transparent PNGs instead of alpha maps?
Oh, and also how can I change the red cross cursor in the main menu? (I would like to have the default pointer system cursor)
Oh, and also how can I change the red cross cursor in the main menu? (I would like to have the default pointer system cursor)
Last edited by BRabbit on 2010-11-30, 19:05, edited 1 time in total.
Re: Alpha map materials
The alpha channel is normally provided by the diffuse-map, which not only stores the RGB channels, but also alpha (only possible with .png or .tga bitmap formats).BRabbit wrote:It is possible to use separate alpha maps for the materials? If so, what is the keyboard used in that case? If not, which is the right way to make textures with alpha colors (like magenta, blue, or black). I looked at the Material System documentation but it didn't work. It is also possible to use transparent PNGs instead of alpha maps?
For examples where the diffuse-map also stores alpha, see
http://trac.cafu.de/browser/cafu/trunk/ ... lants.cmat
Note that you see nothing special, it's all in a single line, e.g.
Code: Select all
diffusemap Plants/Ahorn/AhornLeaves.png
http://trac.cafu.de/browser/cafu/trunk/ ... s/Kai.cmat
blue2alpha() inserts the alpha values into the specified bitmap as an afterthought.
Note that you can also set an alpha value for the entire texture; for examples see
http://trac.cafu.de/browser/cafu/trunk/ ... quids.cmat
The second important step how the alpha channel is used / activated:
- You can either use alphaTest, examples for which are in the above mentioned Kai.cmat file.
- Or use blendFunc src_alpha one_minus_src_alpha, this blends the texture according to alpha channel and is probably what you want.
Well, yes, the pointer is not particularly fancy, its rendering code is in GuiImplT::Render().Oh, and also how can I change the red cross cursor in the main menu? (I would like to have the default pointer system cursor)
Note however that the GUI cursors do not only work in the main menu, but they are used for 3D world GUIs as well. Thus you cannot simply remove the mouse cursor rendering code in the function above and "un-hide" the true system pointer.
What you can do though is replace the above code with rendering a rectangle that shows a nice mouse pointer image (ideally with alpha channel
![Cheesy Grin :cheesy:](./images/smilies/icon_cheesygrin.gif)
(To make it perfect, it's size might e.g. depend on GuiImplT::EntityName=="", so that the pointer is larger for 3D world GUIs.)
![Thumb Up :up:](./images/smilies/thumbup.gif)
Best regards,
Carsten
Carsten
Re: Alpha map materials
I have done it!
.
Here's it, you Carsten could put this in Cafu or maybe some other user wants to change the cursor too:
Code: (GuiImpl.cpp)
Then also add a definition in Games/DeathMatch/Materials/gui.cmat (it could be in any cmat too) at the end for the Gui/Cursor material:
And finally copy this cursor.png file in Games/DeathMatch/GUIs/MainMenu/.
That's it!
(Should this be moved to a new different topic?)
![Group Wave :groupwave2:](./images/smilies/groupwave1.gif)
Here's it, you Carsten could put this in Cafu or maybe some other user wants to change the cursor too:
Code: (GuiImpl.cpp)
Code: Select all
void GuiImplT::Render()
{
RootWindow->Render();
if (MouseIsShown)
{
// TODO !!!!!!!!!!!
// All meshes should be setup ONCE in the constructor!!
// (Should they? Even if we plan to add scripting? Yes, I think they should, Render() is called far more often than anything else.)
// Render the background.
// MatSys::Renderer->SetCurrentAmbientLightColor(BackColor);
MatSys::Renderer->SetCurrentMaterial(Renderer->RegisterMaterial(MaterialManager->GetMaterial("Gui/Cursor")));
static MeshT CrossMesh(MatSys::MeshT::Polygon);
CrossMesh.Vertices.Overwrite();
CrossMesh.Vertices.PushBackEmpty(4); // Just a single quad for the background rectangle.
/*for (unsigned long VertexNr=0; VertexNr<CrossMesh.Vertices.Size(); VertexNr++)
{
CrossMesh.Vertices[VertexNr].Color[0]=0.0f;
CrossMesh.Vertices[VertexNr].Color[1]=0.0f;
CrossMesh.Vertices[VertexNr].Color[2]=0.0f;
CrossMesh.Vertices[VertexNr].Color[3]=0.0f; // This is the alpha I guess
}*/
float b; // The cursor size.
if(this->EntityName != "") // Carsten's suggestion
{
b = 18.0f; // This an in-game GUI
}
else
{
b = 9.0f;
}
// The tex-coord currently don't make much sense... Now it does!
CrossMesh.Vertices[0].SetOrigin(MousePosX, MousePosY); CrossMesh.Vertices[0].SetTextureCoord(0.0f, 0.0f);
CrossMesh.Vertices[1].SetOrigin(MousePosX+b, MousePosY); CrossMesh.Vertices[1].SetTextureCoord(1.0f, 0.0f);
CrossMesh.Vertices[2].SetOrigin(MousePosX+b, MousePosY+b); CrossMesh.Vertices[2].SetTextureCoord(1.0f, 1.0f);
CrossMesh.Vertices[3].SetOrigin(MousePosX, MousePosY+b); CrossMesh.Vertices[3].SetTextureCoord(0.0f, 1.0f);
MatSys:: Renderer->RenderMesh(CrossMesh);
}
}
Code: Select all
Gui/Cursor
{
diffusemap GUIs/MainMenu/cursor.png, noCompression, wrapS clampToEdge, wrapT clampToEdge, noScaleDown
blendFunc src_alpha one_minus_src_alpha
}
![Thumb Up :up:](./images/smilies/thumbup.gif)
Re: Alpha map materials
Hi,
![Very Happy :-D](./images/smilies/icon_biggrin.gif)
I've just implemented this in Cafu as well (with some variations to the code and pointer image though), see http://trac.cafu.de/changeset/195 for the details.
I'd recommend that you use the Cafu implementation, too, because your line causes a major resource leak.
Many thanks, the Cafu GUIs certainly look a lot better this way!BRabbit wrote:Here's it, you Carsten could put this in Cafu or maybe some other user wants to change the cursor too:
![Very Happy :-D](./images/smilies/icon_biggrin.gif)
I've just implemented this in Cafu as well (with some variations to the code and pointer image though), see http://trac.cafu.de/changeset/195 for the details.
I'd recommend that you use the Cafu implementation, too, because your line
Code: Select all
MatSys::Renderer->SetCurrentMaterial(Renderer->RegisterMaterial(...));
I guess it's ok, as it still has a strong relation to (as a use-case of) making use of the alpha channel.That's it!(Should this be moved to a new different topic?)
Best regards,
Carsten
Carsten
Re: Alpha map materials
Your implementation is certainly better!
Anyway, thanks for giving it a shot!
![Wink :wink:](./images/smilies/icon_wink.gif)
Oh, I thought that the MaterialManager automatically removed the registered materials...Carsten wrote:I'd recommend that you use the Cafu implementation, too, because your line causes a major resource leak.
Anyway, thanks for giving it a shot!
Re: Alpha map materials
Not the MatSys::RenderMaterialT's, which require that each call toBRabbit wrote:Oh, I thought that the MaterialManager automatically removed the registered materials...
Code: Select all
X = MatSys::Renderer->RegisterMaterial(...)
Code: Select all
MatSys::Renderer->FreeMaterial(X)
You could try to keep the RenderMaterialT pointers in boost::shared_ptr<T>'s though. For example:
Code: Select all
boost::shared_ptr<MatSys::RenderMaterialT> RM(MatSys::Renderer->RegisterMaterial(...), MatSys::Renderer->FreeMaterial);
I think that this should work, but I've not tried - Cafu does currently not employ boost.
Best regards,
Carsten
Carsten
Who is online
Users browsing this forum: No registered users and 12 guests