Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable world fragment shader #1541

Open
3 tasks
heinezen opened this issue Sep 17, 2023 · 0 comments
Open
3 tasks

Configurable world fragment shader #1541

heinezen opened this issue Sep 17, 2023 · 0 comments
Labels
area: renderer Concerns our graphics renderer lang: c++ Done in C++ code nice new thing ☺ A new feature that was not there before

Comments

@heinezen
Copy link
Member

The world shader is the shader program used for the world render stage, which is responsible for drawing units, buildings, ambience, and everything else that is displayed by a sprite. Making it configurable gives us some leeway in how these objects are rendered.

Our planned approach to configuration is to allow encoding of "commands" in the alpha channels of pixels in a texture. In short, every even alpha value can represent a "command", which means the pixel should be processed using custom shader code. Odd alpha values are drawn without any processing. This gives us 128 possible commands to use in the shader.

The shader code that runs when such a command is encountered should be configurable by modders, e.g. to draw special pixels like player color or outlines. The final world shader would be assembled from the code snippets for each command individual command. These snippets would probably be embedded in a simple switch statement in the GLSL code like this:

# get command
int alpha = int(round(tex_val.a * 255));
switch (alpha) {
    case 254:
        # command 254
        col = vec4(1.0f, 0.0f, 0.0f, 1.0f);
        break;
    case 252:
        # command 252
        col = vec4(0.0f, 1.0f, 0.0f, 1.0f);
        break;
    default:
        # no command
        col = tex_val;
        break;
}

Tasks:

  • Add method to define custom shader code for commands
  • Dynamically assemble world shader from template + command code
  • (later) Allow passing data to shader in uniforms for use in custom shader code
@heinezen heinezen added area: renderer Concerns our graphics renderer nice new thing ☺ A new feature that was not there before lang: c++ Done in C++ code labels Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: renderer Concerns our graphics renderer lang: c++ Done in C++ code nice new thing ☺ A new feature that was not there before
Projects
Status: 🔖 TODO
Development

No branches or pull requests

1 participant