Lua API
  • 🔎Overview
  • Introduction
    • 🚀Creating scripts
      • 🧠First Steps
      • 🖥️Adding UI
      • 📚Creating Libraries
  • API
    • 🌐Global Functions
    • ⚙️Instances
      • 🔢Math
      • ☎️Events
        • event_t
      • 🎮Game
        • global_vars_t
        • cengine_client
          • cnet_chan
        • ccsgo_input
        • cinput_system
        • cgame_ui_funcs
        • ccvar
          • convar
      • 🕹️Mods
        • events_t
      • ✏️Draw
        • ⚙️Types
          • ⚙️rect
          • ⚙️vec2
          • ⚙️color
          • ⚙️accessor
        • 🖥️Adapter
        • ✏️Layer
          • outline_mode
          • rounding
          • glow_parts
          • text_params
            • text_alignment
          • shadow_dir
          • command
            • render_mode
        • 🖼️Managed
          • 🖼️texture
            • svg_texture
            • animated_texture
          • 🖼️shader
          • ™️font_base
            • font
            • font_gdi
            • glyph_t
            • font_flags
      • 🙋Entities
        • entity_list_t
          • entity_entry_t
        • base_entity
          • schema_accessor_t
          • cs2_weapon_base_gun
          • cs2_player_pawn
          • cs2_player_controller
          • cs2_weapon_base
          • cs2_grenade_projectile
        • ccsweapon_base_vdata
          • cfiring_mode
        • chandle
        • csweapon_mode
        • csweapon_type
        • weapon_id
        • csweapon_category
        • observer_mode_t
      • 🖥️Gui
        • ⚙️Types
          • ⚙️bits
          • ⚙️control_id
        • context
          • user_t
        • context_input
          • mouse_button
        • notification_system
          • notification
        • control
          • control_type
          • value_param
          • checkbox
          • slider
          • label
          • selectable
          • button
          • color_picker
          • spacer
          • text_input
          • combo_box
          • image
        • container
          • control_container
            • layout
            • group
      • ⚙️Utils
    • ⚙️Types
      • ⚙️ptr
      • ⚙️ref_holder_t
      • ⚙️vector
      • ⚙️vector4d
      • 🎮veccolor
      • 🎮color
      • 🎮cview_setup
      • 🎮cuser_cmd
      • 🎮game_event_t
    • 🟰Enums
      • 🟰client_frame_stage
      • 🟰input_bit_mask
Powered by GitBook

© 2025 - FATALITY

On this page
  • HLSL structures
  • __call
Export as PDF
  1. API
  2. Instances
  3. Draw
  4. Managed

shader

Previousanimated_textureNextfont_base

Last updated 3 months ago

This type represents a shader.

This type inherits type. All of its base methods and fields are also available in this type.

Only fragment shaders (aka Pixel Shaders) are supported.

Rendering system uses Shader Version 4 (ps_4_0).

HLSL structures

The constant buffer fields are the following:

Name

Type

Description

mvp

float4x4

Projection matrix.

tex

float2

Texture dimensions.

time

float

Render time (NOT the frame time).

alpha

float

Global opacity override.

The input fields are the following:

Name

Type

Description

pos

float4

Vertex position on screen (x,y,z over w). Register: SV_POSITION.

col

float4

Vertex color tint (r, g, b, a). Register: COLOR0.

uv

float2

UV coordinates (u, v). Register: TEXCOORD0.

The bound objects are the following:

Name

Type

Description

sampler0

sampler

Texture sampler.

texture0

Texture2D

Texture object.

Template:

cbuffer cb : register(b0) {
    float4x4 mvp;
    float2 tex;
    float time;
    float alpha;
};

struct PS_INPUT {
    float4 pos : SV_POSITION;
    float4 col : COLOR0;
    float2 uv : TEXCOORD0;
};

sampler sampler0;
Texture2D texture0;

__call

Constructs a shader.

Arguments

Name

Type

Description

src

string

Shader source code.

Returns

Type

Description

shader

Shader object.

Example

local blur = draw.shader([[

// define constant buffer.
cbuffer cb : register(b0) {
    float4x4 mvp;
    float2 tex;
    float time;
    float alpha;
};

// define input.
struct PS_INPUT {
    float4 pos : SV_POSITION;
    float4 col : COLOR0;
    float2 uv : TEXCOORD0;
};

// use texture sampler and texture.
sampler sampler0;
Texture2D texture0;

float4 main(PS_INPUT inp) : SV_Target {
    float radius = 2.0; // blur radius
    float2 inv_size = 1.0 / tex.xy; // inversed size of the texture
    float weight = 0.0; // total weight
    float4 color = 0.0; // total color

    // perform a gaussian blur
    for (float x = -radius; x <= radius; x += 1.0)
    {
        for (float y = -radius; y <= radius; y += 1.0)
        {
            float2 coord = inp.uv + float2(x, y) * inv_size;
            color += texture0.Sample(sampler0, coord) * exp(-((x * x + y * y) / (2.0 * radius * radius)));
            weight += exp(-((x * x + y * y) / (2.0 * radius * radius)));
        }
    }

    // average the color
    color /= weight;
    color.a *= inp.col.a; // apply alpha modulation
    return color;
}
]]);
⚙️
✏️
🖼️
🖼️
HLSL documentation
managed