eugeneloza / decoherence

Project moved to https://gitlab.com/EugeneLoza/decoherence
GNU General Public License v3.0
10 stars 7 forks source link

Add some ready-to-use shaders #264

Open eugeneloza opened 7 years ago

eugeneloza commented 7 years ago

I need shaders for:

example how shaders are composed is here: https://github.com/eugeneloza/decoherence/tree/master/data/shaders information on using shaders in Castle Game Engine: https://castle-engine.sourceforge.io/compositing_shaders.php and https://castle-engine.sourceforge.io/x3d_implementation_shaders.php (however, I rather need only the shaders, so you might skip this)

For Hacktoberfest: You don't need to know pascal to do this. Just check examples and make the stand-alone shaders (GLSL) accordingly. You may adapt shaders taken from the Internet, however in that case be very careful about license of the code and link back to original author/license in the code comment.

michaliskambi commented 7 years ago

I can provide some more advises from the Castle Game Engine side :)

There are 3 approaches to writing GLSL shaders in Castle Game Engine:

  1. Using Effect and EffectPart nodes (within Shape.effects and some other places), documented on https://castle-engine.sourceforge.io/compositing_shaders.php .

  2. Using ComposedShader and ShaderPart nodes within Shape.shaders field, documented on https://castle-engine.sourceforge.io/x3d_implementation_shaders.php , standard in X3D.

  3. Writing screen effects using ScreenEffect nodes, with ComposedShader and ShaderPart nodes inside ScreenEffect.shaders : https://castle-engine.sourceforge.io/x3d_extensions_screen_effects.php .

For screen effects I advice approach 3 (ComposedShader inside ScreenEffect), it's very straightforward for this use-case. For all other effects, I advice approach 1 (Effect and EffectPart).

I do not advice the approach 2 (ComposedShader in Shape.shaders). It may seem straightforward (it allows to often copy-paste shader code from the Internet), but it requires that you implement in shaders everything related to rendering this particular shape. So e.g. if you want to implement some fancy thing (like different fog equation), you need to reimplement also the lighting, texturing etc. (unless your shape is unlit, untextured...).

In contrast, my extension nodes documented on https://castle-engine.sourceforge.io/compositing_shaders.php allow to "extend" the existing shaders. E.g. you can implement your own fog equation by defining a GLSL function called PLUG_fog_apply, and it will "magically" be inserted into the standard engine shaders. The example on https://github.com/castle-engine/demo-models/blob/master/compositing_shaders/volumetric_animated_fog.x3dv shows a cool "volumetric" fog from a 3D texture that can be easily added to any 3D level.

For people coming from Unity3d, you may have used "surface shaders" in Unity3d. Their core idea is similar to CGE Effect nodes -- they allow to extend the standard engine shaders, not simply to replace the engine shaders.

For all 1-3 approaches:

michaliskambi commented 7 years ago

Most of the examples @eugeneloza mentioned in this issue fit best the ScreenEffect description. The two fog ideas are probably best done as Effect with PLUG_fog_apply, see pointers in my above comment :)