opengl - GLSL shader for each situation -


in game want create seperate glsl shaders each situation. in example if have 3 models character, shiny sword , blury ghost set rendershader, animationshader , lightingshader character, rendershader, lightingshader , specularshader shiny sword, , set rendershader, lightingshader , blurshader blury ghost.

the rendershader should multiply positions of vertices projection, world , other matrices, , it's fragmet shader should set texture model.

animationshader should transform vertices given bone transforms.

lightingshader should lighting , specularlighting should specular lighting.

blurshader should blur effect.

now first of how can multiple vertex transforms on different shaders? because animationshader should calculate animated positions of vertices , rendershader should position , trasform matrices.

secondly how can change color of fragments on different shader?

the basic idea want able use different shaders each sutuations/effects, , don't know how achieve it.

i need know how should use these shaders in opengl, , how should use glsl shaders complete each other , shaders not care if shader used or not.

what you're asking decidedly non-trivial, , extreme overkill relatively limited number of "shader" types describe.

doing want require developing own shading language. may highly #defined version of glsl, shaders write not pure glsl. have specialized hooks , written in ways code expected flow other code.

you'll need have own way of specifying inputs , outputs of language. when want connect shaders together, have who's outputs go shader's inputs. inputs can come actual shader stage inputs, while others come other shaders. outputs written shader actual shader stage outputs, while others feed other shaders.

therefore, shader needs input shader must execute after other shader. system have work out dependency graph.

once you've figured out of inputs , outputs specific sequence of shaders, have take of shader text files , compile them glsl, appropriate. obviously, non-trivial process.

your shader language might this:

input vec4 modelspaceposition; output vec4 clipspaceposition;  uniform mat4 modeltoclipmatrix;  void main() {   clipspaceposition = modeltoclipmatrix * modelspaceposition; } 

your "compiler" need textual transformations on this, converting references modelspaceposition actual vertex shader input or variable written shader, appropriate. similarly, if clipspaceposition written gl_position, need convert uses of clipspaceposition gl_position. also, need remove explicit output declaration.

in short, lot of work.

if you're going this, urge avoid trying merge concept of vertex , fragment shaders. keep shader system working within well-defined shader stages. "lightingshader" need either vertex shader or fragment shader. if it's fragment shader, 1 of shaders in vertex shader feeds need provide normal in way, or you'll need fragment shader component compute normal via mechanism.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -