Sign in to follow this  

texCUBE help

This topic is 3295 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

Do you mean how it uses the address to sample the cubemap? Typically it's done by normalizing the vector, and using the largest component to indicate which face of the cubemap should be sampled. The other two components are then scaled to the [0,1] range and used as a UV address to sample that face.

Share this post


Link to post
Share on other sites
Here is my code that seems to me like it should be the same as texCUBE but something is off. Thanks for the help!


float3 myTexCUBE(sampler myEnvMapS, float3 myEnvMapTex)
{

//figure out which face to grab tex off of
//1. Pick the biggest value (from the absolute values):
float u;
float v;
myEnvMapTex = normalize(myEnvMapTex);

float x = abs(myEnvMapTex.x);
float y = abs(myEnvMapTex.y);
float z = abs(myEnvMapTex.z);

if( x > y && x > z )
{
if( myEnvMapTex.x > 0 )
{
//face 0
u = -z + 0.5;
v = y + 0.5;
}
else
{
//face 1
u = z + 0.5;
v = y + 0.5;
}
}
if( y > x && y > z )
{
if( myEnvMapTex.y > 0 )
{
//face 2
u = x + 0.5;
v = -z + 0.5;
}
else
{
//face 3
u = x + 0.5;
v = z + 0.5;
}
}
if( z > x && z > y )
{
if( myEnvMapTex.z > 0 )
{
//face 4
u = x + 0.5;
v = y + 0.5;
}
else
{
//face 5
u = -x + 0.5;
v = y + 0.5;
}
}


float2 uvlookup = float2(u,v);

float3 texColor = tex2D(EnvMapS, uvlookup);
return texColor;
}

Share this post


Link to post
Share on other sites
You can't use the absolute value of the coordinates for determining U and V, you have to use the result you got from normalization. You also need to multiply the values by 0.5 before adding 0.5.

However it doesn't look like this will work anyway once you've got the right UV coordinates, since in the end you just sample the same texture no matter what the result. To work like cube sampling you'd have to choose the sampler and texture based on the face you chose.

Why are you doing this, btw?

Share this post


Link to post
Share on other sites
I am confused about how you would access the face in the texture. The texture here contains all of the 6 faces i think.
And to answer your question i'm just trying to understand what the function does better. Thanks so much for the help so far, it is getting a lot closer.


float3 myTexCUBE(sampler myEnvMapS, float3 myEnvMapTex)
{

//figure out which face to grab tex off of
//1. Pick the biggest value (from the absolute values):
float u;
float v;
myEnvMapTex = normalize(myEnvMapTex);

float x = abs(myEnvMapTex.x);
float y = abs(myEnvMapTex.y);
float z = abs(myEnvMapTex.z);
float face;

if( x > y && x > z )
{
if( myEnvMapTex.x > 0 )
{
//face 0
face = 0;
u = -myEnvMapTex.z*0.5 + 0.5;
v = myEnvMapTex.y*0.5 + 0.5;
}
else
{
//face 1
face = 1;
u = myEnvMapTex.z*0.5 + 0.5;
v = myEnvMapTex.y*0.5 + 0.5;
}
}
if( y > x && y > z )
{
if( myEnvMapTex.y > 0 )
{
//face 2
face = 2;
u = myEnvMapTex.x*0.5 + 0.5;
v = -myEnvMapTex.z*.05 + 0.5;
}
else
{
//face 3
face = 3;
u = myEnvMapTex.x*0.5 + 0.5;
v = myEnvMapTex.z*0.5 + 0.5;
}
}
if( z > x && z > y )
{
if( myEnvMapTex.z > 0 )
{
//face 4
face = 4;
u = myEnvMapTex.x*0.5 + 0.5;
v = myEnvMapTex.y*0.5 + 0.5;
}
else
{
//face 5
face = 5;
u = -myEnvMapTex.x*0.5 + 0.5;
v = myEnvMapTex.y*0.5 + 0.5;
}
}


float2 uvlookup = float2(u,v);

float3 texColor = tex2D(EnvMapS, uvlookup);
return texColor;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Screamer
I am confused about how you would access the face in the texture. The texture here contains all of the 6 faces i think.


If you're working with an actual cube texture, then the only way to sample it properly is with texCUBE. It might be possible to sample it with tex2D...but if you can I don't know how you can control which face you'd sample.

What I Was talking about would work if you had 6 seperate textures and you wanted to simulate cubemapping with those textures.

Share this post


Link to post
Share on other sites

This topic is 3295 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this