Game Objects (like projectiles) with Shaders?

edited January 2017 in GLSL / Shaders

I have a simple game engine architecture and I would like to add effects to my projectiles.
Are shaders typically applied over the entire screen, or is it possible to just apply a shader locally to , let's say, a sprite which is drawn using a. an image or b. some combination of vector drawings like ellipses or custom shapes or an svg file?

How might you prevent it from looking like just a rectangle over the image location? Is there a way to apply shaders only to that particular sprite? Would you just make sure that every non 'important' pixel in the image has some alpha value of 0? Just curious as most of the shader examples i've seen always fill up the sketch area.

Things that I'd like to explore would be making glowing effects and such on every projectile, or trails. Thank you.

Tagged:

Answers

  • @aarondbaron --

    PShaders may be applied to an shape (e.g. a PShape, or a beginShape-endShape) or a series of shapes. They can be applied in a PGraphics object which is then rendered to part of the screen. They can be set for some objects and removed before drawing other objects with resetShader().

    Have you gone through the Processing Shader Tutorial? It will answer many of your questions.

  • Thank you. I went back over the shader tutorial again and can see now that I can apply shaders to any shape. I'm guessing that the same will hold true if I pass in an image sprite instead of drawing a shape. (I'm guessing the vertex part will just be ignored, and every pixel in the image goes thru the fragment shader?)

  • try it.

    write (or copy) a shader. draw a sprite (just a rect will do, just some pixels)

    disable shader, draw another sprite.

    the problem is getting it to ignore transparent pixels in your image. you can check the colour value coming in and just ignore the transparent ones.

    glowing is usually done with an additive blend of a blurred copy of the object being rendered. this will (i think) require a vert shader (because it's modifying pixels other than those you are explicitly drawing)

  • this link suggests that isn't true if you use textures. a frag shader has access to the passed in texture and can sample (and blur) multiple pixels within that passed-in texture before setting the one frag it's handling.

    https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson5

Sign In or Register to comment.