1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

How to add custom shaders

Discussion in 'Modding Help' started by Koi_, Dec 9, 2016.

  1. Koi_

    Koi_ Bison Rider

    Messages:
    16
    I am trying to write a custom shader in a mod and I am wondering:
    1. If it's actually possible to run more than one shader at a time.
    2. How to implement it.

    I tried it but there are some problems:
    1. It wont find the vert and frag files in the mod folder (it finds them if I put them in Base)
    2. It fails to find the shader if there is another one running (I use the hq2x shader, too)

    I added the shader in a custom rules script as such:
    Code:
    void onInit(CRules@ this)
    {
        Driver@ driver = getDriver();
    
        driver.AddShader("myshader", 1.0f);
        driver.SetShader("myshader", true);
        print("init shader");
    }
    As I found in the KAG.as script.

    And these are the shader files:

    Vertex:
    Code:
    void main()
    {
      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
      gl_TexCoord[0] = gl_MultiTexCoord0;
    }
    Fragment:
    Code:
    void main()
    {
      gl_FragColor.rgb = vec3(1.0, 1.0, 1.0);
      gl_FragColor.a = 1.0;
    }
    I made them very basic, but I don't know if I need to do anything to conform to the KAG engine.

    - Koi
     
  2. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    I dont think this works from mods I'm afraid; putting it in base should work. Running at the same time as hq2x should be no problem (we've had multiple shaders in TR at many points, though i think it's down just 1 now..) but it's possible that the hq2x one in kag is added in some strange way by the menu?

    I'm sorry that I'm not really able to help out here; I'm not "working on" KAG today and I didn't implement the shader system; I've just worked with it when working on TR. You can see how the scripts work with it there (and how the shaders look).
     
  3. Koi_

    Koi_ Bison Rider

    Messages:
    16
    Thanks Geti.
     
  4. Eluded

    Eluded Haxor Official Server Admin

    Messages:
    132
    @Koi_ I know how to do this, see my thread here: https://forum.thd.vg/threads/adding-opengl-shaders-for-cool-graphical-effects.25525/

    Here's an example of a more complex shader in the WIP mod Brutality Isle: https://github.com/Normangorman/BrutalityIsle/blob/master/Shaders/brutality.frag
    It causes darkness to engulf the player at night
    --- Double Post Merged, Dec 16, 2016, Original Post Date: Dec 15, 2016 ---
    When I was working on this I wasn't able to find a way to get multiple shaders to work - so I think it's only possible to override the default hq2x shader.
     
    Osmal and mcrifel like this.
  5. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Is "how to make it work" just explicitly including the ../Mods part?

    What sort of errors do you get with multiple shaders? The system is set up to work with this already, you might just not be setting them with the right priority or something? As I said, maybe hq2x is interfering with that, but TR used lots of layered shaders at one point (and still layers the separate drunk and paletisation shaders).
     
  6. Koi_

    Koi_ Bison Rider

    Messages:
    16
    When I try loading another shader after hq2x I get this in the console: http://i.imgur.com/KhQRa2n.png
    It also happens vice-versa if I load this shader before hq2x.

    It says "Shader not found," but the shaders are in Base/Shaders/ so it should be able to find them.
    These are different to the error messages that show when the shader files are in the mod folder: http://i.imgur.com/ln41bWD.png

    I can make it find them in the mod folder if I use "../../Mods/ModName/shadertest" instead of "shadertest" in the shader init code, but it still has the error shown above.
     
    Last edited: Dec 23, 2016
  7. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Have you tried getting a known-good shader working? like copying one of the shaders from tr, or a dupe of the hq2x code?

    Sorry, I'm not going to be around to debug this much over xmas, but I'm interested in why it breaks, especially if it breaks when not set up as a mod (maybe only TR supports multiple shaders properly in that case and there's some engine-side changes preventing using them with kag)
     
  8. Koi_

    Koi_ Bison Rider

    Messages:
    16
    I just did a quick test and found that if I duplicate the hq2x shader, rename it, then try to load it (it's in the base folder), it has the same error.
    However, if I simply try to load the original hq2x shader again (after it's already been loaded in KAG.as) it works just fine.

    I am using the same code to load the shader as in KAG.as, but it's in a different rules script loaded last in the gamemode.cfg.