Sign in to follow this  
BlackBrain

Correct UVs after Resoloution change

Recommended Posts

BlackBrain    517

Hi .

 

  I am developing an app that scans a portion of camera image and use it as a texture . The texture works fairly nice in 512x512 resolution but in the app this is not possible and I may have the texture in 512x128 . When I use the scanned texture it is maladjusted and not correctly at the place it has to be. I guess it's because of the resoloution.

 

 

  How can I add an coefficient to uv to correct this , knowing the Best possible resolution(example: 512x512) and the captured resolution(example: 512x128)?

 

Share this post


Link to post
Share on other sites
Seabolt    781

Well your uvs should be independent of the actual resolution of the texture, they should be values clamped between 0 and 1 where 0 is one side of the image and 1 is the other side of the image.

 

So the question is how are you generating your texture? If you have access to render targets, you could just render a quad that is the correct size of the image that you want into the source image at the correct spot in the source image, blit every pixel into a target texture and your UVs shoudn't have to change. 

 

This is me shot-gunning ideas though, I need to know more about your problem.

Share this post


Link to post
Share on other sites
BlackBrain    517

Thanks for the answer. Actually I am developing a AR (augmented reality) application. By the Camera Image I don't mean the result of a computer generated rendering task but the Image that the Camera of the device captures . 

 

 We are developing it for children . They color a drawing and we scan their painting and use it as a texture of a 3D Object . So we have different resolutions on different devices .

Share this post


Link to post
Share on other sites
Ashaman73    13715

I think that the resolution does not matter, eg. if your target is 512x512 it should not matter if your texture is 64x64, 1024x1024 or 2048x2048 (texture coords are relative in most APIs).

 

What seems more like a problem is the changing ratio between width and height of the texture. To fix it, you can

1. try to expand the texture to make it square again (eg. fill the rest with black): 512x128 => 512x512

2. try to cut the longer side off to make it square again: 512x128=>128x128

3. try to adjust the uvs like this (this will either repeat the texture or show a clamped version of it, depending on the texturing mode):

int width = ...given by image..
int height = ...given by image..
int max_size = max(width,height);
// scale uv
float u2 = u * max_size/width;
float v2 = v * max_size/height;
Edited by Ashaman73

Share this post


Link to post
Share on other sites

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