1
$\begingroup$

I am trying to scale and repeat a Cubemap with Latitude-Longitude mapping layout just as you would do with classical UV mapping but without any interesting result. This should be used as a skybox.

This comes from the fact that the coordinates are in 3D space and we can't apply this simple formula texcoord.xy * scale.xy + offset.xy

How would you handle such features : scaling which involves tiling and offsetting.

samplerCUBE _TexCube;
texCUBE(_TexCube, float3);
$\endgroup$
0
$\begingroup$

This doesn't really answer the question but is a workaround. Beware it's hack time :)

Instead of using the texCUBE and samplerCube I'll be using the tex2D method and a simple sampler to sample the texture.

As I am using a sphere mesh, I generate 2D UVs like this.

float x = atan2(vertex.x, vertex.z) / PI;
x = x / 2.0 + 0.5; // To remap from 0 to 1
float y = vertex.y / 2.0 + 0.5; // Also remap from 0 to 1
float3 color = tex2D(sampler, float2(x, y) * scale.xy + offset.xy);

It's a bit hacky but using this I have 2D texture coordinates for my texture.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.