Replies: 10 comments 12 replies
-
I am now at my development machine right now so just browsing source online, the ViewDependentSate.cpp is where the raversal mask would need be set up for casting/not casting shadows. Looking at the code there is a hardware mask of 0x1 that's set at: https://github.com/vsg-dev/VulkanSceneGraph/blob/master/src/vsg/state/ViewDependentState.cpp#L395 Mask shadowMask = 0x1; // TODO: do we inherit from main scene? how?
auto viewportState = ViewportState::create(VkExtent2D{shadowWidth, shadowHeight});
ref_ptr<View> first_view;
shadowMaps.resize(maxShadowMaps);
for (auto& shadowMap : shadowMaps)
{
if (first_view)
{
shadowMap.view = View::create(*first_view);
}
else
{
first_view = View::create(ViewFeatures(INHERIT_VIEWPOINT));
shadowMap.view = first_view;
}
shadowMap.view->mask = shadowMask;
shadowMap.view->camera = Camera::create();
shadowMap.view->addChild(tcon);
shadowMap.view->camera->viewportState = viewportState;
shadowMap.renderGraph = RenderGraph::create();
shadowMap.renderGraph->addChild(shadowMap.view);
preRenderSwitch->addChild(MASK_ALL, shadowMap.renderGraph);
} As I've added a TODO it'se clearly something I've added locally but didn't come across a requirement to make the control puiblic - I think you're the first peson to ask since I wrote these calsses. What would be required is public ViewDependentState member for setting the shadowMask rather than the use of local variable. With the shadowMask set you then would decorate subgraphs that you want to toggle on/off by deocrating them with a vsg::Switch node with the corresponding bits of the traversal mask set. Switching off recieving shadows would be more awkward as you'd need to extend the shaders to have a uniform for toggling on/off use of shadow maps. The vsgcustomshaderset would be the place to look for guidance on extending shader sets with custom uniforms and shaders. |
Beta Was this translation helpful? Give feedback.
-
Very informative, thanks. I had been using your OSG library for over a decade and this is my first foray into the VSG API. I'm a bit lost because in OSG shaders were an optional thing, but here they permeate the API and the framework. My real issue is going to be the receiving of shadows because it turns out - it's the flat earth below that I don't want the shadows. That is, I want to add them manually myself (for a variety of reasons), and use the normal VSG shadowing for the self-shadowing aspect. So, according to you above, I need to add a uniform and change the logic to the vsgcustomshaderset. I'll have a look at it. There are so many differences in the API that it's a bit daunting to try to find the counterpart in VSG for OSG tasks. For example, I want to draw my custom flat terrain shadows after the flat terrain, but before the objects on top of it with their self shadowing. Normally I'd use render bins. I didn't see render bins in VSG, so I'm spending a lot of time poking around examples. Ah well, this new API, and will take a bit of a learning curve. Thanks for your hard work! |
Beta Was this translation helpful? Give feedback.
-
Vulkan is so different from OpenGL that a scene graph written specifically for it's strengths ends up being quite different in places. Modern OpenGL is pure shader based like Vulkan is, so it's really just old OpenGL 1.x style fixed function pipeline scene graphs that will be significantly different. The VulkanSceneGraph has mechanisms in place for making life with a purely shader based workflow easier - this is where vsg::ShaderSet and vsg::GraphicsPipelineConfiguration come up, and there isn't an equivalent on the OSG side, one ends up having doing things manually and hardwired with shaders in the OSG. So in the domain of shaders the VSG should be easier. However, as much as the VSG tries to make things simpler to use Vulkan and shaders it's still a relatively large API and will require new ways of thinking about particular problems. For you usage case it may be best to take a step back and rather than try to recreate what you did with the OSG, perhaps aim for where you want your software to be in terms of features. It might be that things that were workarounds for OSG/OpenGL limitations might not be relevant today and you can just go straight towards a better quality solution without so many compromises. |
Beta Was this translation helpful? Give feedback.
-
I am using the ConstVisitor and it indeed is an expanded search with a far wider range of classes. I was trying to to gather up the source triangles for manually computing the terrain flat shadow triangles . I didn't see anything like OSG's TriangleFunctor, so I just derived from the vsg::ComputeBounds and override the applyDraw and applyDrawIndexed virtual methods. Even this didn't work right away because several of your ComputeBounds methods don't traverse downwards if they don't have to (bounds is already valid) - so I had to override them too! I'll get there. This project isn't that complex, and performance is not going to be an issue with the rendering in VSG that I'm seeing. The real reason why I wanted to manually produce the flat ground shadows is that very long shadows would degrade the shadow quality given that the shadow map would have to be spread over a potentially huge area. The self-shadowing areas are very confined and should be well defined for most objects. And, if I compose flat black terrain shadow triangles, it could go forever without having a texture size involved at all. So, using the native shadows for self-shadowing, and using a black flat triangle collection for the ground shadows would make sense. Thus the turning-off of the shadows on the terrain first so your shaders let me handle the ground shadows. It's a pity, I had everything working in OSG but WITHOUT the self-shadowing because we have the fixed pipeline for most things in our older software. I took a look at your VSG, and clearly - as they say - this is the way. I think this is the best time to get my feet wet and dive into your new API. Everyone seems heading in this direction! |
Beta Was this translation helpful? Give feedback.
-
I've only been using VSG for a month, and even with a good strong OSG background, there is a big learning curve with this API. I basically began with the shadows example and went from there. The shadows are a bit of magic for me. Your example allows me to activate the hard shadows, and then models that I read_cast into the scene are indeed rendered with shadows. If I play around with the light position and compile some of the graph, the shadows change on the objects correctly. I also generally know what the switch node does (all or just some of the children can be considered at will. But in this case, it's not binary like I'm showing a "cover" of a box, or not. I don't even know what and when I would be switching anything for the shadows. I placed the terrain and a vehicle in the scene. I want BOTH to be visualized. I don't want to switch them on or off. Just some of the shadow casting (don't want the terrain to have a shadow on it, just the self-shadows). How could the Switch be used to do this? |
Beta Was this translation helpful? Give feedback.
-
You shouldn't need to compile the scene graph elements when you add/remove or move lights as they are managed dynamically by vsg::ViewDependentState for you. It's only new subgraphs that don't yet have Vulkan objects ceated for them that you'll need to compile. The casting of shadows for the text will have to managed by decorating with a vsg::Switch node and using the same traversal mask bit as the ViewDependentState is currently hardwired to use - 0x1 so bit zero is one you'd need to switch off for the Swtich node above the text. |
Beta Was this translation helpful? Give feedback.
-
Wow, that works great! This will easily allow me to stop certain things from casting shadows. I did the following which is what I think you are describing:
I tried this with and without the switch and it definitely makes a difference. I thought vsg::Switch was only an enable/disable child kind of node, but I see there is a different addChild with a value. Didn't see this. Thanks! |
Beta Was this translation helpful? Give feedback.
-
My MatrixTransforms for each model are placed under a vsg::Group, which is then placed under a single switch. I perform: m_placed_models_switch->children[0].mask = vsg::MASK_ALL & ~1; In visual studio, I can see not only that the mask goes from 0xffffffffffffffff to 0xfffffffffffffffe, but I can see that there is only one child of the switch, the parent group, and it in-turn has the four children MatrixTransforms. I must be missing something. The self-shadows are still there. |
Beta Was this translation helpful? Give feedback.
-
Ok, so your insight pointed me the way. I have indeed set up the switch, the group, and the children exactly as above. And, that switch was added to the scene directly. But, like your shadow example where you set up the "scene", but later add that as a sibling of a group that includes the lighting, I added the models group (not the switch) there as well. Looks like I just need to add the switch with models into the scene once. Does it matter if the switch with the models is a parent or sibling to the directional lighting node? |
Beta Was this translation helpful? Give feedback.
-
Very cool. There is code, there are examples, there are header files, and there are discussion groups. Is there a short document that has these nuggets of information (e.g. lights are collected for each vsg::View and stored in a light uniform). Especially with those parts of VSG where there is something being done for you beyond normal vulkan stuff (e.g. shadows, etc.) and were specific design choices made under the hood that have to be "kept in mind" ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm playing around with the vsgExamples and the vsgshadows project in particular. With only a few options it can depict hard shadows very nicely on four different shapes sitting on a flat sheet. I'd like to find a way to prevent just ONE of the four shapes from participating in both casting and receiving shadows. I did not see another example that does this, and I've tried several approaches to no avail. Anyone know of a simple approach to prevent just one shape/subgraph of the scene from participating in the shadow process?
Beta Was this translation helpful? Give feedback.
All reactions