Advertisement Jump to content
Sign in to follow this  

Using Plane to generate texCoord on SkyDome

This topic is 4958 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay _DarkWing game the idea in a thread awhile ago and I've finally gotten around to impliment it. I believe my ray-plane collision is fine. The dome is fine. What I do is fire a ray from origin (0,0,0) to each of the sky dome vertices, where is cross' the plane (0,height,0) (normal(0,1,0)) I use that intersect point as the tex coord. What is happening tho, the texture is tiling a billion times across the dome, which makes sense since the the dome and the plane are not between 0.0f and 1.0f. Although, with the tiling, it still kinda trails into the horizon. Maybe I am not making sense of the method here is what I was told: _DarkWing: -Create sky-dome with some radius R. For better results make it anisotropic(sp?) tessellated so it has more triangles on horizon. -Create a virtual plane (at height H) that will represent your cloud layer. -For each vertex V of sky-dome create ray R from origin to vertex. -Find the point P=(x,H,z) where R goes trough your plane. -Use point P (x,z components) as texture coordinates for vertex V -Use distance from origin to point P as weigh for alpha blending so your clouds fade out at horizon. -Be careful with rays that are parallel to plane.

Share this post

Link to post
Share on other sites
Okay, here are two attemps.
The first is just by firing rays from (0,0,0) to each vertex in the dome and using the x,z coords of its intersection with the plane for the tu/tv.

This one is done the way same way except the intersection point is divided by the height of the plane from (0,0,0) before used as the tu/tv

In both case's the dome is created around origin (0,0,0) with a radius of 1000.0f.
The virtual plane used for collision is created with origin (0,500,0) and has a normal of (0,1,0).

All rays from the origin the dome is centered on, (0,0,0).

Also, to note, during the ray firing, I NEVER get a ray which is parellel, ie.) the test will result in dividing by 0.

Share this post

Link to post
Share on other sites
Not sure really what your question is.

Did you expect it not to tile?
In which case you need to tweak you uv generation to account for this.

However in terms of generating uv's for my cloud dome I wanted it to tile just a few times, but more importantly I wanted maximise the area of the cloud around the center of the sphere (above the camera position) so when looking up it didn't lose resolution.

My solution was to use the following code

-- Generate plane projected Texture coordinates
yOffset = y + 128
xOffset = (x/yOffset)*tCloudHeight
zOffset = (z/yOffset)*tCloudHeight
add pTxCordlist, [atan(xoffset)*2, atan(zoffset)*2]

where x,y,z are generated for the skydome as

z = tRadius * sin(phi) * cos(theta)
x = tRadius * sin(phi) * sin(theta)
y = tRadius * cos(phi)

This tiles it but not uniformly you can see some samples here.
Note the source texture is a 2x2 checker (white/red pattern)
Skydome UV Samples

Hope that helps

Skydome cloud samples Still looks a little flat but I think its mainly due to poor shading on the cloud texture at the moment (actually its completely faked as the shading is added to the texture in photoshop)

Share this post

Link to post
Share on other sites
My question is whats going wrong.

Where do u want me to impliment this first code you posted?

About the Dome vertices, I got a routine to calculate that already.

I also want no tiling.

Share this post

Link to post
Share on other sites
I am able to get it working, sorta. The tiling stops, but its may look a little funky, I'll post a screeny if no solution can be established from what I say.

I create a dome at radius 1000.0f.
I position a plane height 400.0f
I position the start point of every ray at (-1000.0f, 0.0f, -1000.0f)
I fire each ray to each vertices (set ray end point as the vertice pos)
I divide the intersection point of the ray to the plane by 1000.0f
Use that value as the texU and texV values for the vertice.

This seemingly works and looks okay. To say the least, it is textured over the dome once I believe. I am also not sure why that fixed it.

_Darkwing showed some very nice skyies to me once. I am hoping he shall give me some more insight.

Share this post

Link to post
Share on other sites
Your pictures look mostly correct. Specially the 1st one. You are missing just 2 things: fading with distance and tiling texture.

Fading with distance solves the problem with clouds just ending somewhere. Try doing something like this : final_color = sky_blue_color + (per_vertex_alpha * texture). Since you fade alpha with distance clouds will fade away on horizon giving you a smooth look.

Here is a clouds texture I used in the shots I posted before:

Here is a code from my old engine. It's messy but I think you'll get the point.

void USkyDome::BuildTextureCoordinats( float textureScale = 0.01f ) {
const float cloudPlaneHeight = 10.0f;
const float someNumber = cloudPlaneHeight * textureScale;
const float maxCloudDist = 1.0f / SQR( UEnviroment::viewDistance*textureScale );
UVector vertex;
float distMult;
for ( unsigned int i = 0; i<verticCount; i++ ) {
// calculate uv
vertex = vaData[ i ].position;
if ( vertex.y > EPSILON ) {
distMult = someNumber / vertex.y;
} else {
if ( vertex.y < -EPSILON ) {
distMult = -someNumber / vertex.y;
} else {
distMult = 1.0f;
} };

const float u = distMult * vertex.x;
const float v = distMult * vertex.z;

// set texture coords
vaData[ i ].texCoord.u = u;
vaData[ i ].texCoord.v = v;

// set alpha
if ( vertex.y > EPSILON ) {
float dist = ( u*u + v*v ) * maxCloudDist;
vaData[ i ].color.cA = Clamp<float>( 1.0f - dist, 0.0f, 1.0f );
} else {
vaData[ i ].color.cA = 0.0f;

Remember that all this (including my shots) is just a basic approach. There are many things that can be improved to make it look much better.

Share this post

Link to post
Share on other sites
Yes that all makes sense to me except for one variable.

Is that just the array containing all your vertices?
Or is the the array full of coordinates used when firing the rays through the plane. That is the only part I don't understand is the lack of ray-plane collision in your snippet.

I do know this is a basic approach but it suits my needs perfectly. No sense in making the supreme ultimate sky if it isn't goona be utilized a lot.

Share this post

Link to post
Share on other sites
Is what you posted ALL you did to calculate the texU and texV coords?
There is no actual ray-plane collision test's to perform?

You've really lost me now.

Share this post

Link to post
Share on other sites
I used that texture you gave me and bam how I have it set up (using the method the other fellow posted) it works and looks 'okay'. Which is odd because if I use any other texture you can see the texture divided into 4 parts and the coords are completely inccorect for each part.

Your texture seemingly works perfect, seemingly flows everywhere, I cannot find a single spot where the texture looks incorrect.

Edit: However, I am setting the view matrix each time I render as to keep the sphere centered around on the viewer, like the trick with billboard's or quad particles. Is this right? The texture always looks so close now and blurry. Because of the fact it is so close it is hard to see any flatness in it all like in your screeny.

Also, I took the snippet you posted, reworked it, and I got the exact same results as I had by firing rays through a plane, darn near identical.

[Edited by - Halsafar on June 17, 2005 7:04:23 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!