cross shader

Started by
4 comments, last by mireazma 9 years ago

Hello.

Can you guys give me a direction where to get assistance about making a specific shader?

I want to make a starry night sky from 2 separate textures: 1 for the sky background + 1 for the stars. The stars texture is 90% empty, as in RGBA(0, 0, 0, 0) and only have scattered white points or little blobs as stars.
I need an idea about how to make a shader for the stars texture to draw a cross for each star (horizontal/vertical spikes). The idea here is whenever camera is rotated the crosses stay unrotated.
One alternate way is to just have a pre-crossed star texture and draw it multiple times at different locations over the already rotated background. But with 1000 stars I'm afraid it's not going to be very economical. And I want to take advantage of the shader parallelism.

The shader would probably be something like the simple blur shader. I'm saying this because I guess it should "smudge" the points (original stars) upwards, downwards, left and right.

But I have no clue as to where to begin.

Advertisement

Try looking for "lens flare shader".


One alternate way is to just have a pre-crossed star texture and draw it multiple times at different locations over the already rotated background. But with 1000 stars I'm afraid it's not going to be very economical.

Why not?


The shader would probably be something like the simple blur shader. I'm saying this because I guess it should "smudge" the points (original stars) upwards, downwards, left and right.

Blur shaders are generally a lot more costly than a shader that just draws from a texture, since each pixel needs to take multiple texture samples. I don't see how this is cheaper than your first option, you still have the same amount of geometry (probably a quad for each star), and are drawing the same number of pixels. Unless I'm understanding your meaning incorrectly?


And I want to take advantage of the shader parallelism.

All shaders take advantage of "shader paralellism".

It sounds like your stars should just be billboards. They have a 3d presence in your world, but are actually just billboards that are drawn to always face the camera view plane. Search for "billboarding". Most particle effect shaders also do this - particles are just textured quads that face the camera view plane.

Thank you for replying.

I wasn't clear about it -- It's 2D, a sky as seen from below, which could spin (you/camera in fact).

The idea is to use only 1 large texture that would contain all the stars, already at their positions, like a transparent starry sky. So no multiple drawings, i.e. for each star, but only one for the whole large texture.

If I draw the stars each with its own texture and quad, even if I draw the "cross" in a shader, I don't benefit of parallelism, as the stars are drawn sequentially.

On the other hand fragmenting the texture in multiple stars, each on its own texture, saves me memory in that I won't need the "void" space around the stars in the large texture.

About the blur shader I meant I have to create the star rays/spikes starting from the original point-like star and this for each star i.e. bright point (1000) on the sky texture.

In the first place I thought I could make the sky texture with pre-crossed stars but if I rotated the sky the crosses would of course rotated as well. But they have to keep their orientation.

I hope I was clear.


If I draw the stars each with its own texture and quad, even if I draw the "cross" in a shader, I don't benefit of parallelism, as the stars are drawn sequentially.

Yes and no. The vertex shader does infact work on multiple vertexes in parallel and the fragment shader will also be working on multiple pixels in parallel. If you use a textureatlas and put all the stars in a single vbo you can issue a single drawcall to draw all the stars and the shaders will do it all in parallel. You will most likely get more performance this way as it doesn't have to work on all the pixels in the "void" space and you can predraw the cross in the textureatlas so you don't have to do any blur shaders.

If you use a textureatlas and put all the stars in a single vbo you can issue a single drawcall to draw all the stars and the shaders will do it all in parallel.

I'm planning to use only 1 VBO and VAO for all the assets in the game. Thank you. You are very clear about parallelism, draw calls and VBO. I decided that I go with separate star textures, pre-crossed.

I also thank the others.

This topic is closed to new replies.

Advertisement