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

Adding OpenGL shaders for cool graphical effects

Discussion in 'Modding [KAG]' started by Eluded, Jun 2, 2016.

Tags:
  1. Eluded

    Eluded Haxor Official Server Admin

    Messages:
    132
    Has anyone had experience doing this? I think shaders could be used to add some really cool weather effects, or overlays for if the player is drunk / ate some bad kinds of mushrooms...

    For example, I was able to modify the default hq2x shader to turn the sky green:
    [​IMG]

    Code:
    uniform sampler2D baseMap;

    const vec3 sky_color = vec3(0.694, 0.780, 0.796);
    const vec3 green_color = vec3(0.0, 1.0, 0.0);

    void main()
    {
    vec3 inFragColor = texture2D(baseMap, gl_TexCoord[0].xy).xyz;
    vec3 fragCoord = vec3(gl_FragCoord);
    vec3 ivec = vec3(1.0, 1.0, 1.0);

    float d = dot(abs(sky_color - inFragColor), ivec);
    if (d <= 0.28)
    {
    gl_FragColor = vec4(green_color, 1.0);
    }
    else
    {
    gl_FragColor = vec4(inFragColor, 1.0);
    }
    }



    The AngelScript file that loads the hq2x shader is Base/Rules/CommonScripts/KAG.as.
    The relevant lines are:

    driver.AddShader("hq2x", 1.0f);
    driver.SetShader("hq2x", true);

    So I added a simple mod which changes these lines to:
    driver.AddShader("../../Mods/ShaderTest/Shaders/hq2x", 1.0f);

    driver.SetShader("../../Mods/ShaderTest/Shaders/hq2x", true);

    And of course put the modded shader in that folder.
    It would be nice to know the full list of uniforms which are accessible from shader code. Although it seems that you can use driver.SetShaderInt / driver.SetShaderFloat to include some custom ones, e.g:

    driver.SetShaderInt("../../Mods/ShaderTest/Shaders/hq2x", "globalTime", getGameTime());


     
    Osmal and PUNK123 like this.
  2. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Actually, Trench Run exactly does this.

    Particles and sky gradient is the easiest thing to start up with.