Horde3D
http://horde3d.org/forums/

See-through objects.
http://horde3d.org/forums/viewtopic.php?f=1&t=2316
Page 1 of 1

Author:  Midnightas [ 14.05.2019, 11:00 ]
Post subject:  See-through objects.

Hi, it's me again.. I want some objects to always be in front, and they should be seen through walls.
Currently, this is how it does it: Render everything except for the wallhack objects, and then hide everything except the wallhack objects and render again.

As you can see, this sucks, because if I defined any postprocessing in the pipeline, it also has to happen twice.
What I'm thinking right now is to edit Horde3D to allow the DrawGeometry tag to specify classes for scenegraph nodes as well. Then I could do something like:
Code:
<DrawGeometry context="AMBIENT" nodeClass="~ALWAYS_ON_TOP" />
<ClearTarget depthBuf="true" />
<DrawGeometry context="AMBIENT" nodeClass="ALWAYS_ON_TOP" />


Before I do that, though, I'd like to know if there's already maybe a way to do this cleanly, I don't actually want to make such a massive change, but I also don't want to use a different rendering engine.

Author:  Irdis [ 14.05.2019, 16:23 ]
Post subject:  Re: See-through objects.

Hello. Can't you just modify the pipeline to render all other objects with material class "AMBIENT" and then render objects with material class "WALL"? Horde has classes, but for materials.
Something like it is currently done for transparent objects?
Or maybe I did not understand your goal completely.

Author:  Midnightas [ 14.05.2019, 16:30 ]
Post subject:  Re: See-through objects.

Irdis wrote:
Hello. Can't you just modify the pipeline to render all other objects with material class "AMBIENT" and then render objects with material class "WALL"? Horde has classes, but for materials.
Something like it is currently done for transparent objects?
Or maybe I did not understand your goal completely.


Yeah that could be done, but I don't really want to enforce certain materials to always be in front. My goal is to have something like an ability to make some specific entity visible through walls, as a superpower. Well, okay, it's not actually my goal, but that is an effect I want to be able to do. It shouldn't apply to all nodes. Cloning materials also seems like a hack (so I'm very thankful h3dSetNodeUniforms exists :P ).

Author:  Irdis [ 14.05.2019, 17:00 ]
Post subject:  Re: See-through objects.

You can link several materials and, as far as I remember, it is available from code. So you can dynamically link another material with needed class to you objects when they are seen through you wall hack.

Author:  Midnightas [ 14.05.2019, 17:35 ]
Post subject:  Re: See-through objects.

Irdis wrote:
You can link several materials and, as far as I remember, it is available from code. So you can dynamically link another material with needed class to you objects when they are seen through you wall hack.


Yes, but it's still global for all meshes using said material, I'm pretty sure, when I need it to be node-specific. I'd really rather not clone materials for each mesh in each model (But of course, I might if I have no other choice).

Author:  Irdis [ 14.05.2019, 20:22 ]
Post subject:  Re: See-through objects.

Maybe you can create another context? So you would draw context Ambient for all objects and something like ALWAYSVISIBLE.
Code:
<DrawGeometry context="AMBIENT"  />
<ClearTarget depthBuf="true" />
<DrawGeometry context="ALWAYSVISIBLE" />


And judging on camera position the number of nodes that are using ALWAYSVISIBLE context changes. Probably the shader in ALWAYSVISIBLE will be similar for many types of objects. Can this suit your needs?
I have a feeling that the effect you try to achieve can be made with the current Horde's functionality, but probably I cannot convey it in a nice way.

Author:  Midnightas [ 14.05.2019, 20:55 ]
Post subject:  Re: See-through objects.

Wouldn't that still be global? The idea with my original plan above was that I could do something like h3dSetNodeClass(node, "ALWAYS_ON_TOP", true) and it would be set only for that one node.

Author:  Irdis [ 14.05.2019, 21:57 ]
Post subject:  Re: See-through objects.

Horde also has per-node id and custom model data that can be passed to shaders.
I've rechecked the source, it seems that material linking would add new samplers and uniforms to your current material, but will not change material class or shader. I don't know if it helps you.

Can't this be solved by setting another material to node when you need it? Maybe it can even be solved by the practically same material, but with additional ShaderFlag in it that triggers another shader path? Or it can even be solved by additional uniform?

Previously I used material changing for mesh in Horde, it worked quite well. You just clone the material and change it for selected mesh when you need it and revert back when you no longer need changed material. I think that if I had a similar problem I would first try dynamic cloning/changing the materials for the needed mesh.

Author:  Irdis [ 14.05.2019, 22:06 ]
Post subject:  Re: See-through objects.

So, it should probably look something like that:
In pipeline you have both ambient draw and ALLVISIBLE draw. By default there are no ALLVISIBLE objects in the scene.
You have a shader with ALLVISIBLE context that renders you objects in front of others.
You have a standard shader for your objects and standard material.
During loading you clone the material with new name. In the cloned material you change the used shader to the one that has ALLVISIBLE context.
In runtime, when you should display objects in front of others, you select the node you need and change its material to cloned one - object now uses ALLVISIBLE context and is rendered as needed.
Then, camera moves away, node no longer needs to draw in front of others - revert the mesh material back to original one.

EDIT: or it can be even easier. You don't need cloning the materials and having other shader. You have one shader with both AMBIENT and ALLVISIBLE contexts. Then, your node has a default material that does not have a class. When the time comes you set the material class to AllVisible or something like that. If you don't want it to be global you would probably have to use material cloning as I mentioned earlier.

EDIT 2: Your approach would require rather large modifications. You would have to modify scenenode class, probably scene manager and maybe spatial graph class, pipeline class, and mostly renderer class.

Author:  Midnightas [ 15.05.2019, 10:44 ]
Post subject:  Re: See-through objects.

Irdis wrote:
So, it should probably look something like that:
In pipeline you have both ambient draw and ALLVISIBLE draw. By default there are no ALLVISIBLE objects in the scene.
You have a shader with ALLVISIBLE context that renders you objects in front of others.
You have a standard shader for your objects and standard material.
During loading you clone the material with new name. In the cloned material you change the used shader to the one that has ALLVISIBLE context.
In runtime, when you should display objects in front of others, you select the node you need and change its material to cloned one - object now uses ALLVISIBLE context and is rendered as needed.
Then, camera moves away, node no longer needs to draw in front of others - revert the mesh material back to original one.

EDIT: or it can be even easier. You don't need cloning the materials and having other shader. You have one shader with both AMBIENT and ALLVISIBLE contexts. Then, your node has a default material that does not have a class. When the time comes you set the material class to AllVisible or something like that. If you don't want it to be global you would probably have to use material cloning as I mentioned earlier.

EDIT 2: Your approach would require rather large modifications. You would have to modify scenenode class, probably scene manager and maybe spatial graph class, pipeline class, and mostly renderer class.


Yeah, I hoped that cloning materials wasn't the cleanest solution. Is there a simple way to clone the material for every mesh in a model?

Author:  Irdis [ 15.05.2019, 11:44 ]
Post subject:  Re: See-through objects.

Well, it should probably be something like this:
Code:
int modelID = h3dAddNodes(H3DRootNode, modelRes);
int childNodeID = 0;
int nodeCounter = 0;
bool childAvailable = true;

while( childAvailable )
{
    childNodeID = h3dGetNodeChild( modelID, nodeCounter );
    if ( !childNodeID )
    { childAvailable = false; continue; }

    nodeCounter++;

    if ( h3dGetNodeType( childNodeID ) != H3DNodeTypes::Mesh ) continue;

    int matID = h3dGetNodeParamI( childNodeID, H3DMesh::MatResI ) ;
    std::string matName = std::string( h3dGetResName( matID ) );
    matName.append( "_" + to_string( nodeCounter ) );
    int clonedMatID = h3dCloneResource( matID, matName.c_str() );

    h3dSetNodeParamI( childNodeID, H3DMesh::MatResI, clonedMatID );

    // store matID and clonedMatID somewhere
}


I haven't compiled the code, but it should be pretty reliable.

Author:  Midnightas [ 15.05.2019, 12:57 ]
Post subject:  Re: See-through objects.

Works for me, I suppose. Thanks again!

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/