User Tools

Site Tools


en:examples:shaders:flashing_an_object_white_shader_params

Flashing an Object White

(Using a shader that accepts parameters)

Useful for indicating hits on an object, for example in shoot-em-ups.

Assets

Code

orxObject_CreateFromConfig("Object");

Config

[Object]
Graphic         = Graphic
ShaderList	= WhiteShader
 
[Graphic]
Texture       = ship.png
 
[WhiteShader]
ParamList = texture # objectTime # flashSpeed # maxFlashes
objectTime = time
maxFlashes = 4 ;how many times to flash
flashSpeed = 8 ;how fast between flashes
Code = "
void main() {
 
    vec2 p = gl_TexCoord[0].xy;
    vec4 textureCol = texture2D(texture, p);
 
    float t = mod(objectTime*flashSpeed, 1); 
    float flashCount = abs(objectTime*flashSpeed);
 
    if (t < 0.5 && flashCount < maxFlashes){
            gl_FragColor.r = 1.0;
            gl_FragColor.g = 1.0;
            gl_FragColor.b = 1.0;
            gl_FragColor.a = textureCol.a;
    } else {
            gl_FragColor.rgb = textureCol.rgb;
            gl_FragColor.a = textureCol.a;
    }
 
}"

Result

en/examples/shaders/flashing_an_object_white_shader_params.txt · Last modified: 2018/02/14 08:47 (2 years ago) (external edit)