NEW: State inhertance support and custom ShaderSet's example #1026
robertosfield
started this conversation in
General
Replies: 1 comment
-
One of the features the new vsgcustomshaderset example illustrates is how to create a uniform struct that is passed to the GPU along with serialization support (so your can read/write to .osgb and .vsgt file formats). The code for the Fog struct is: namespace custom
{
// OpenGL style fog struct to pass to the GPU
struct Fog
{
vsg::vec3 color = {1.0, 1.0, 1.0};
float density = 0.05; // OpenGL default is 1.0!
float start = 0.0;
float end = 1.0;
float exponent = 1.0;
void read(vsg::Input& input)
{
input.read("color", color);
input.read("density", density);
input.read("start", start);
input.read("end", end);
input.read("exponent", exponent);
}
void write(vsg::Output& output) const
{
output.write("color", color);
output.write("density", density);
output.write("start", start);
output.write("end", end);
output.write("exponent", exponent);
}
};
using FogValue = vsg::Value<Fog>;
extern vsg::ref_ptr<vsg::ShaderSet> pbr_ShaderSet(vsg::ref_ptr<const vsg::Options> options);
}
template<>
constexpr bool vsg::has_read_write<custom::Fog>() { return true; }
EVSG_type_name(custom::FogValue); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
Through last week I was working on adding the ability hint the vsg::ShaderSet that we want to specify state high up in the scene graph that will be inherited down to the subgraphs being constructed by the likes of vsg::Builder and vsgXchange::assimp, so that those subgraphs can skip assigning the associated BindDescriptorSet. This work is checked in to VSG, vsgXchange and vsgExamples master:
This improves users control over how state is setup in scene graphs that are created for them by loaders/builders as well offer a little more performance by just binding the most commonly used DescriptorSet once and avoiding binding this descriptors sets multiple times in the subgraphs. A good example of this in the BindViewDescriptorSet which can be place in a StateGroup just below a vsg::View, but now needed by applied to all the subgraphs.
There are two ways we can tell scene graph builders that it can assume that the state will be applied from above:
To illustrate how that state inheritance is explicitly set up I have added --inherit command line option and associated setup code the vsgbuilder, vsgshadow and a new example vsgcustomshaderset.
The implicit state inheritance is something that vsgCs utilizes in it's ShaderSet's with the DescriptorSet's bound to set 0, 1 and 2 provided by upper nodes in the scene graph and the material DescriptoSet (model textures and material uniforms) on set 3.
As part of these changes I have adopted the vsgCs style ordering of DescriptorSet so that the ViewDependentState is now assigned to set 0, where previously it was by default found on set 1, and the DescriptorSet used by vsg::Builder and vsg::Xchange::assimp for textures and material uniforms is now found on set 1, whereas previously it was set 0.
If you application assumes that the DescriptorSet's are on a particular set number then you may need to update your code with an update to VSG master.
--
The new example vsgcustomshaderset does have a state inheritance code path, a bit like the modifications to vsgbuilder and vsgshadow that is triggered by a --inheritance command line options, it's main purpose is to illustrate how users can add their own layout of DescriptorSet and their own DescriptorSet and use them in place of ShaderSets used by the loaders.
This example chooses to create it's own version of PBR ShaderSet assigning it in place of the default PBR ShaderSet by assign the ShaderSet it creates to Options::shaderSet["pbr"], the loader then uses this ShaderSet as a guide to how to set up the state where generating subgraphs. The custom PBR ShaderSet in this example add a new DescriptorSet at set = 0 for assigning a custom::Fog uniform struct loosely follow the OpenGL glFog capabilities. The original ViewDependentState and texture/materials DescriptorSet and then places on set = 0 and 1 respectively.
The end result in the ability to add OpenGL fixed function style fog to a PBR scene:
Beta Was this translation helpful? Give feedback.
All reactions