这是indexloc提供的服务,不要输入任何密码
Skip to content

Configurable world fragment shader #1541

@heinezen

Description

@heinezen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: rendererConcerns our graphics rendererlang: c++Done in C++ codenice new thing ☺A new feature that was not there before

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions