Insert a shaderpiece from code

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Insert a shaderpiece from code

Post by white_waluigi »

Im currently working on my Matetial System For my deferred shading implementation, which will allow User to create custom shadercode. The Problem Im having right now is that there is no way to insert a piece defined in a glsl File into a shader from with c++ code. I can create a custom string shader piece from within code, but this code doesnt work if it has insertpiece inside it. So how can I insert a shaderpiece into a shader for a Datablock from within c++?

Something like this would be ideal:

Code: Select all

Main (){
   Vec4 Final=vec4 (0);
   
   @insertpiece (CUSTOM)
   Retun final;
}

@Piece (RED)
 Final=vec4(1,0,0)
@end

Code: Select all

datablock.setCustomPiece (RED)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Insert a shaderpiece from code

Post by dark_sylinc »

When calculateHashForPreCreate/calculateHashForPreCaster is called, it gives you a PiecesMap *inOutPieces parameter. That's where you defined your pieces from C++ code:

Code: Select all

inOutPieces[VertexShader]["MyPieceName"] = "string of code to insert";
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Insert a shaderpiece from code

Post by white_waluigi »

Yeah, I saw that and have used it for a while now. Problem is, that this doesn't accept any further @insertpieces and the User would have to write their shadercode withtin a JSON file, which I think is very ugly. I need a solution where people can write custom shader code (which theortherically could also be produced by a tool, similar to how UE4 handels things), which can then be inserted into specific positions inside the default shadercode (which would be mostly empty)
I would like to reimplement the entire Deferred Shading code for LIghts and Materials inside such a JSON Material file, from which all other Materials would inherit. (Or they don't, if they want to write their one code or don't want to inherit the entire code). Basicly like blender where you always start with the default configuration
Post Reply