nature-of-code / The-Nature-of-Code-Cosmos-Edition

Repository for fall 2013 workshop at ITP on space data visualization
129 stars 16 forks source link

Shader as background and/or sphere texture #8

Open shiffman opened 11 years ago

shiffman commented 11 years ago

@codeanticode - I'm playing with the "Star Nest" example and thinking about how best to view it in the dome.

Using the dome library doesn't make a lot of sense given that it warps it to appear as if it's a flat rectangle "ceiling" on top of the dome. See: https://github.com/shiffman/The-Nature-of-Code-Cosmos-Edition/tree/master/stars/StarNestShaderDome

In another example, I was able to create a starfield like background by placing dots on a large sphere (centered at 0,0,0). See: https://github.com/shiffman/The-Nature-of-Code-Cosmos-Edition/tree/master/stars/StarFieldBackground

I tried applying this same idea to the shader, i.e. create a large sphere, one big enough that it essentially becomes the background and texture the shader on it. See: https://github.com/shiffman/The-Nature-of-Code-Cosmos-Edition/tree/master/stars/StarFieldShaderBackground

For some reason the texture does not cover the entire sphere. Any ideas @codeanticode?

shiffman commented 11 years ago

I'm realizing this is sort of pointless b/c the dome itself will do this exact warping. hah. of course, if i was not projecting into a dome this would be interesting to still try.

codeanticode commented 11 years ago

Hi Dan, the examples are amazing!

The reason for the texture not covering the entire sphere is that you need to use the resolution of the canvas, not the output window:

shader = loadShader("stars.glsl");
shader.set("resolution", float(canvas.width), float(canvas.height));

and

canvas.beginDraw();
canvas.shader(shader); 
canvas.rect(0, 0, canvas.width, canvas.height);
canvas.endDraw();

However, the star nest shader doesn't generate an image that joins seamlessly at the edges.

codeanticode commented 11 years ago

About how to properly projecting the star nest shader as the background, my impression is that using the sphere would be the right thing to do, placing it exactly at the camera eye:

translate(width/2, height/2, ((PGraphicsOpenGL)g).cameraZ);
rotateX(rotY);
rotateY(rotX);
rotateZ(rotZ);
shape(sphere);
shiffman commented 11 years ago

thanks, it's working now. Now, I just need to make the texture spherical and tiled properly. So perhaps this particular shader is not conducive. I could possibly integrate this into the shader actually. Someday. . .