Combining shaders

I know this topic has been discussed here already, but it has been a year ago, so maybe something has changed.



Is there any way to create a “combined” shader? For example, I want to create a tron-like world many objects with glow maps. That means that I cannot use the “global” glow shader and need to use materials with the glowing capability. Those objects also must have other shaders applied. So can I somehow use a single glow map shader on every of this object with another custom shader being applied to any of them if needed? I mean that I would like to avoid putting glow functionality in every shader that these objects must be with.

Post-effect? This is a sheder too…



Or glsl-filter…



Have a look at Glow filter in JME.

1 Like

@mifth that what I actually meant under the “global” glow shader (excuse me for my noob wording). I cannot use it because I need much more control over what is glowing - that control which is given by the glow shader, not filter. That is why I am wondering…

But anyway you will need to apply glowmap texture to the glowing material.



Or you can apply Glow filter to a screen. This way you do not need a glow texture at all.

@mifth yes, I do not mind applying glowmaps to every material, I just do not want to copy the glowing routine into every material’s shaders… Like i have a MovingTexture, Glass and Glow shaders. And I want to get these materials:



MovingTexture + Glow,

Glass + Glow



And i do not want to copy the “glowing” code into both the MovingTexture and Glass shaders, I just want to use the existing shader, so that the material, basically, has 2 shaders? Maybe I even misunderstand that all… but I think I want it that way… I know about the glow screen filter - it just makes everything glow and I think that it can be used in many cases, and in tron-like worlds, but in my particular case I need a fine control over what glows and what not… so glowmaps are necessary…

We had a similar conversation with oxplay here.

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/shader-techniques/#post-184702



However in your case you wouldn’t have to put the “glow code” in your shader, because the only thing you need so that your material supports glow is to add the technique and material parameters into the j3md. It’s just a copy/paste operation.



it’s detailed in the glow documentation https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:bloom_and_glow

search for “Making your home brewed material definition support Glow”

1 Like

@nehon Thanks for clarifying that! Not quite as modular as I would like to see it but still easier than I originally thought… I have prepared everything, however, I get the error:



[java]Aug 7, 2012 2:54:00 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.UnsupportedOperationException: In material: Common/MatDefs/Post/BloomExtract.j3md

The ‘FixedFunc’ technique name no longer has any special meanining.

To support fixed pipeline mode, remove that technique’s name entirely.

at com.jme3.material.plugins.J3MLoader.readTechnique(J3MLoader.java:411)

at com.jme3.material.plugins.J3MLoader.loadFromRoot(J3MLoader.java:506)

at com.jme3.material.plugins.J3MLoader.load(J3MLoader.java:522)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:282)

at com.jme3.material.Material.<init>(Material.java:116)

at com.jme3.post.filters.BloomFilter.initFilter(BloomFilter.java:124)

at com.jme3.post.Filter.init(Filter.java:233)

at com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:167)

at com.jme3.post.FilterPostProcessor.reshape(FilterPostProcessor.java:441)

at com.jme3.post.FilterPostProcessor.initialize(FilterPostProcessor.java:148)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:946)

at com.jme3.renderer.RenderManager.render(RenderManager.java:1016)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:251)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:184)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)

at java.lang.Thread.run(Unknown Source)[/java]



I remember having this error some time before… searching the forums recommended updating to the latest nightly, and that solved the issue. Now updating does not work… I see the problem is inside the default resources library… can it be fixed so that I could update and resolve this again?

mhhh what do you mean by updating does not work?

@nehon I mean that when updating the SDK there comes no update that fixes this problem (nightly updates enabled). And actually I have just verified that I am using the latest version. However, this file:



“…/jmonkeyplatform/libs/jMonkeyEngine3.jar/Common/MatDefs/Post/BloomExtract.j3md”



Aside from other things, has this inside:

[java]

Technique FixedFunc {

}

[/java]



And apparently, the asset manager tries to load that very file. At the same time, there is this file:



“…/jmonkeyplatform/libs/jME3-effects.jar/Common/MatDefs/Post/BloomExtract.j3md”



which is completely the same except that it has no mention of the “FixedFunc” technique. This is a little mystery for me - why there are two similar files with that only difference and what to do now…

@noncom and @nehon , @mifth

Just want to tell you guys that after playing silently with @mifth GLSL library and coding with test and fail. I come up with something like this, a Node based generation can almost generate GLSL code. The secret behind it is quite complex… but in short I use Groovy’s text template system to pre-define the code block.



Here is UI of that ultility, which must have a lot of improvements , tell me if you guy find that interesting, althogh I heard that Blender soon release a plugin that can generate GLSL too , :stuck_out_tongue:



http://farm9.staticflickr.com/8282/7732457688_f267da8cb6_c.jpg

5 Likes

@atomix That is quite interesting, I would like to know more of what you did. The screenshot you have put in the post does not tell much, since it is a plain graph creator simple example. If you could, it would be more useful if you post a screenshot of the tool in action, like when editing a glsl file. So that it could be seen in action to understand what is going on there.



Nice that you have used some advanced Groovy-based system for realizing that functional btw.



What is the glsl library made by mifth you are talking about?

Looks cool. But where can you use it? In what cases?

I guess he means this: http://code.google.com/p/jme-glsl-shaders/

Haven’t played with it myself but it is on my todo-list, rather impressive collection of code @mifth has written/gathered from the community.

@atomix:



yeah, if you plan to make contribution to JME, then please make it same like in blender :slight_smile:

@noncom :

It’s a few day ago screenshot, sorry not the lastest.

Now the tool just only a general code generation and no preview, and can procedure the simple code like :

a= b+ c.

or may be more interesting things like :

uv = texcoord;

diffuse = tex2d(tex1,uv);



But I need more time to think about the template thing, what functions should be in GLSL library and what is the name, give me some time and I back with more clearly example

@atomix ok, tell us when you come up with something!



@nehon do you have any ideas on what to do with that? I think that I can delete the wrong j3md - the one with the FixedFunc technique and it will work, picking the right one. What I am more worried about is why does not it work out of the box? I use jME3 libraries with Eclipse, maybe I should investigate into linkage problems? (although I did not find any).

@noncom:

This is the current UI, as you can see

http://farm9.staticflickr.com/8432/7738357328_035d2aa95b_c.jpg

Nodes input value procedure the Result by an “default” Operation “plus”.

Groovy provide a very advanced way to handle this kind of DSL language and template, so benefit.

So if the template is like this : c = a + b

the result text :

varC=varA + varB … or diffuse = texColor + highlight

the result preview pixel :

pixelC = pixelA + pixelB ( groovy can override operation)

=> output to Graphics2D



@mifth: I decide to organize your library into smaller GLSL libraries, and then write a ultility to automatic roll in that library and bring out all the customable parameter for user to change… It’s pretty much like Uniform in the official Material Editor but in the Shader level.



The plan for this Shader Tool:

1)First thing I want to do is The generated Shader has a fixed End,

in which we compute the input :

diffuse, normal, specular,… as in UDK or in blender . Then…

→ (Gourrad shading Template) fragColor = diffuse * normal …

→ ( Rimlight Shading Template)…



2)Now the Preview not working yet because I’m learning how to generate a MatDef with my VertexShader and FragmentShader on the fly. May be @normen can help me please!

3) Integrate into the SDK, yes of course. Further I want this tool to perfectly integrated with NeoTexture and SDK MaterialEditor but I still thinking about how to do that :stuck_out_tongue:

@atomix said:
3) Integrate into the SDK, yes of course. Further I want this tool to perfectly integrated with NeoTexture and SDK MaterialEditor but I still thinking about how to do that :p

Well..that's not something to consider once everything else is done IMO...You should have start with this...
You may have to go through huge refactoring to integrate it afterward.

@noncom

I don’t know your SDK install seems fucked up, the jMonkeyEngine3.jar should not contain anything.

Try to delete it maybe, but you’d better go for a SDK fresh install.

@nehon I have just wiped out everything, through uninstall and then manually - and made a clean install + all updates (including nightly). The jMonkeyEngine3.jar still has it. And after recompiling the project the error is the same. That is not surprising because searching through the filesystem, I find the “wrong” BloomExtract.j3md file with the “FixedFunc”. So it cannot be my mistake. It comes in like this. My platform is Windows if that matters…