Shader architecture question.

Started by
3 comments, last by swiftcoder 14 years, 10 months ago
Hey all. I decided that I needed a hobby programing project again ;) So I started reading up on shaders and was left with a question when it comes to multiple shaders. Say I have 2 materials Ma and Mb, now in my scene I want to have pp-lights as well as using Ma and Mb, (The light shader can be called ML) Do I need to just copy-paste the lightcode so that they both contains the same code + there unique characteristics. (Ma + ML) Or is there someway to link more shaders (and have them running) at the same time, or is it normal to have some kind of code generator that generate these shaders runtime so that they contain the light code as well? cheers
- Me
Advertisement
I know it's pretty common to build your shaders out of building blocks. Often a graphical editor is used to link the different shader modules together. Alternatively you can just use a naming convention and then compose modules with simply a list.

I have not build my uber system yet, so i dont have much more advice. But this is something i've always wanted and arguably needed.
If you want to combine 2 effects there are a few ways to do it:
1 - you sit down and type
2 - you do multipass rendering (first pass uses shader 1, second pass uses shader 2)
3 - you have code to generate the complex shader you need
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
There's also Cg interfaces, which let you combine shader "snippits" in an object oriented way at runtime.

DX11 is introducing what looks to be basically the same thing to HLSL-SM5.
Quote:Original post by V-man
If you want to combine 2 effects there are a few ways to do it:
3 - you have code to generate the complex shader you need
I use this third method, and it works pretty well. However, I am working in Python, so string manipulations are a lot simpler than in C/C++.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement