Jump to content
  • Advertisement
Sign in to follow this  
AxeGuywithanAxe

Shader Node Graph

This topic is 937 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Guys, So I am currently working on a shader graph editor and I wanted to get an opinion from those that are more experienced than I. How does one handle drastically different vertex layouts. For example, lets say that you create a shader that can work on static meshes, skinned meshes, both cpu and gpu skinned, and fft oceans. Those methods of computing have drastically different ways of accessing vertex data to pass to their shared shader, and parameter binding on the c++ side. Do you create a separate hlsl file per "render element" and provide common functions a la "GetElementVertexWorldPosition" and etc? Do you just categorize this as another "shader permutation" and take an uber shader approach"? On the cpu side, do you create subclasses to handle specific rendering logic? Or possibly bind vertex buffer data based on usage, i.e streams with "VertexElementUsage_Position" may be only bound to slot 0? The only full example source I have is UE3/UE4's vertex factory implementation, some frostbite publications, and snippets of code from Naughty Dog's GDC Vault discussion of their particle system , http://www.gdcvault.com/play/1015898/The-Tricks-Up-Our-Sleeves , and I'd rather get more opinions on the matter so that I could learn of the benefits and pitfalls of different solutions. Thank You. 

Share this post


Link to post
Share on other sites
Advertisement

Hey AThompson,

 

Im working on something similar for my Game Engine using C# Tools for the node editing with the option to switch from node based editing into source code editing as well and back. Therefore I first wrote an own Parser/Preprocessor for the Shader (GLSL in my case) and generated the nodes from that or took the nodes and generated the code from it to edit. The Preprocessor was needed to handle #include and namespace tags as it is possible to build shader libraries including given namespaces to use precompiled functions from there.

 

I already worked with Unreals editing tool but decided to leave the fixed function style out rather than presenting a main node (the main function in GLSL) and let anything work from that node.

 

It is not the classic approach of how engines do this today but I think that anything should be exposed to the developer. In my pipeline there are keywords assuming that these identifiers are targets for several functions (like your skel animation shader example) or are set over the layout id where engine assumes that certain layout id is used for a fixed attribute.

//debug output glsl

#version 450
vertex layout (location = 0) in vec4 Vertex; //vertex attrib id
vertex layout (location = 1) in vec2 TexCoord; //tex coord id
vertex uniform mat4 viewMatrix, projMatrix;
vertex out vec2 texture;

vertex void main()
{
  gl_Position = projMatrix * viewMatrix * Vertex;
  texture = TexCoord;
}

fragment in vec2 texture;
fragment uniform sampler2D Font;
fragment uniform vec3 TextColor;
fragment uniform float Char;
fragment out vec4 Color;

fragment
{
  const float hBase = (8 / 128.0);
  const float vBase = (13 / 128.0);
}

fragment void main()
{
  float row = float(int(Char / 16.0f));
  float color = texture2D(Font, vec2(texture.x + (hBase * (Char - (row * 16.0f))), texture.y + (row * vBase))).r;

  if(color == 0)
    discard;

  Color = vec4(TextColor, 1);
}

Share this post


Link to post
Share on other sites

 

 

Do you just categorize this as another "shader permutation" and take an uber shader approach"?

 

Yes, mostly. If you notice in UE4, the uber shader is represented as a single node, and the user can create a node network to provide inputs for the main uber shader functions. I wrote a short blog post about such a system here. However, I think it doesn't go into enough details to be very useful to you, and also it was just a prototype rather than a real-world solution.

Edited by Amr0

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!