Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader as background and/or sphere texture #8

Open
shiffman opened this issue Oct 25, 2013 · 4 comments
Open

Shader as background and/or sphere texture #8

shiffman opened this issue Oct 25, 2013 · 4 comments

Comments

@shiffman
Copy link
Member

@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 added a commit that referenced this issue Oct 25, 2013
@shiffman
Copy link
Member Author

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
Copy link

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
Copy link

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 added a commit that referenced this issue Oct 28, 2013
@shiffman
Copy link
Member Author

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. . .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants