Custom shaders

Discuss artwork in all of its forms here, from level design to GUI button themes. New MODs planning, work-in-progress and other samples are welcome in this forum as well.
Post Reply
scott
Posts:173
Joined:2004-08-23, 09:11
Custom shaders

Post by scott » 2010-04-24, 14:28

Are custom shaders possible in Cafu yet? I notice there's headings in the Wiki for shader authoring but no articles.

I'm assuming that Cafu uses Cg shaders (Judging by the cg dll file).
I cant actually program myself but I thought I'd try out some of the free ones lying around on the net.
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Custom shaders

Post by Carsten » 2010-04-25, 10:54

Dear Scott,

yes, two of the Cafu renderers use Cg shaders internally (one in the NV2X profile, the other in the NV3X profile), and one Cafu renderer uses OpenGL with the "ARB vertex and fragment programs" extension (and another one uses OpenGL 1.2, which works with no shaders at all).

Adding your own custom (Cg) shaders such as those described at Shader Specifications requires some C++ programming however. This is because shaders typically require custom, shader-specific setup of the OpenGL state that cannot be handled in shader or material scripts. You can see examples of such C++ shaders at e.g. http://trac.cafu.de/browser/cafu/trunk/ ... B1/Shaders

However, I hope and expect that the situation will improve soon: Implementing an OpenGL 4.0 renderer is among the future features, and then it will become possible to specify the entire GPU shader in script as well.
Best regards,
Carsten
scott
Posts:173
Joined:2004-08-23, 09:11

Re: Custom shaders

Post by scott » 2010-04-25, 13:18

Ok thanks for the clarification Carsten, using c++ is just way over my head, one day I'll get off my lazy behind and learn some (I have 2 books on the subject, its just a matter of making the time).
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Custom shaders

Post by Carsten » 2010-04-26, 11:34

Ok, great to know that. Let us know on your progress, and don't hesitate to ask if you have any questions! C++ can be overwhelming at first, but it's worthwhile to learn. :up:
Best regards,
Carsten
afgho
Posts:14
Joined:2012-06-12, 13:08

Re: Custom shaders

Post by afgho » 2012-06-15, 14:39

I want to make some custom shaders however it seem that i need to transcribe the shader for all renderers?

How can i force a renderer? Also, how to get from the code that set up a shader a camera/light position defined for example in CaWe?
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Custom shaders

Post by Carsten » 2012-06-16, 01:13

Hi afgho,
How can i force a renderer?
For forcing a specific renderer, use the -clRenderer command line option.
See the console log in order to learn which renderers are available and which one has been loaded automatically (if you're on Windows, where the console log is not shown at the Windows command prompt, use the -log command line option.

Here is an example session demonstrating this:

Code: Select all

d:\Dev\Cafu> build\win32\vc10\x86\debug\Ca3DE\Cafu.exe --help
Usage: Cafu [-con <str>] [-svGame <str>] [-svWorld <str>] [-svPort <num>] [-noFS] [-clPort <num>] [-clRemoteName <str>] [-clRemotePort <num>] [-clTexDetail <num>] [-clWinSizeX <num>] [-clWinSizeY <num>] [-clRenderer <str>] [-clSoundSystem <str>] [-clPlayerName <str>] [-clModelName <str>] [-log <str>] [-h] [--verbose] [worldname]
  -con:<str>                    Runs the given commands in the console. -con "x=3;" is equivalent to appending x=3; to the end of the config.lua file.
  -svGame:<str>                 Name of the MOD / game the server should run [DeathMatch]. Case sensitive!
  -svWorld:<str>                Name of the world the server should run [TechDemo]. Case sensitive!
  -svPort:<num>                 Server port number [30000].
  -noFS, --clNoFullscreen       Don't run full-screen, but rather in a window.
  -clPort:<num>                 Client port number [33000].
  -clRemoteName:<str>           Name or IP of the server we connect to [192.168.1.1].
  -clRemotePort:<num>           Port number of the remote server [30000].
  -clTexDetail:<num>            0 high detail, 1 medium detail, 2 low detail [0].
  -clWinSizeX:<num>             If not full-screen, this is the width  of the window [1024].
  -clWinSizeY:<num>             If not full-screen, this is the height of the window [768].
  -clRenderer:<str>             Override the auto-selection of the best available renderer [auto].
  -clSoundSystem:<str>          Override the auto-selection of the best available sound system [auto].
  -clPlayerName:<str>           Player name [Player].
  -clModelName:<str>            Name of the players model [Punisher].
  -log:<str>                    Logs all console message into the specified file.
  -h, --help                    show this help message
  --verbose                     generate verbose log messages

Default values are enclosed in [brackets].
It is also ok to omit the "-svWorld" option for specifying a world name: "Cafu MyWorld" is the same as "Cafu -svWorld MyWorld".


d:\Dev\Cafu> build\win32\vc10\x86\debug\Ca3DE\Cafu.exe -log console-log.txt

d:\Dev\Cafu> type console-log.txt
Cafu Engine, May 22 2012
config.lua processed.
Warning: Failed to open ZIP archive Games/DeathMatch/Textures/TechDemo.zip
Registering archive "Games/DeathMatch/Textures/SkyDomes.zip".

Scanning cwd for all available renderers...
Scanning Libs/build/win32/vc10/x86/debug/MaterialSystem for all available renderers...
Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererARBprogs.dll ... SUCCESS - first supported renderer (Pref# 2200).
Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererCgARB1.dll ... SUCCESS - but no higher preference (Pref# 2100).
Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererCgNV2X.dll ... SUCCESS - but no higher preference (Pref# 2000).
Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererNull.dll ... SUCCESS - but excluded from auto-selection (Pref# 1).
Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererOpenGL12.dll ...
Libs\MaterialSystem\RendererOpenGL12\RendererImpl.cpp (90): Entering RendererImplT::IsSupported().
Libs\MaterialSystem\RendererOpenGL12\RendererImpl.cpp (106): GL_VERSION string is "4.2.0".
Libs\MaterialSystem\RendererOpenGL12\RendererImpl.cpp (114): GL_ARB_multitexture_AVAIL==1.
SUCCESS - but no higher preference (Pref# 1000).
Reloading previously auto-selected renderer Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererARBprogs.dll ...

Scanning cwd for all available sound systems...
Scanning Libs/build/win32/vc10/x86/debug/SoundSystem for all available sound systems...
Libs/build/win32/vc10/x86/debug/SoundSystem/SoundSysFMOD3.dll ... SUCCESS - first supported sound system (Pref# 1000).
Libs/build/win32/vc10/x86/debug/SoundSystem/SoundSysNull.dll ... SUCCESS - but excluded from auto-selection (Pref# 1).
Libs/build/win32/vc10/x86/debug/SoundSystem/SoundSysOpenAL.dll ... SUCCESS - higher preference sound system (Pref# 1500).
Reloading previously auto-selected sound system Libs/build/win32/vc10/x86/debug/SoundSystem/SoundSysOpenAL.dll ...
Warning: The call to method OnKeyPress() of window with name "ReallyQuitDialog" yielded (expected return values matching signature "i>b" instead).

d:\Dev\Cafu> build\win32\vc10\x86\debug\Ca3DE\Cafu.exe -clRenderer Libs/build/win32/vc10/x86/debug/MaterialSystem/RendererARBprogs.dll

d:\Dev\Cafu>
Also, how to get from the code that set up a shader a camera/light position defined for example in CaWe?
We don't support dynamic lighting in CaWE at this time. (It's a real pity, of course, because we should. Any help with implementing this would very much be appreciated!)

In the Cafu Engine itself, the position of the camera and the light source is automatically set up and passed to the shader code. The quickest way to see this is probably to check out a few of the example shaders of the CgARB1 or ARBprogs renderer.
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests