Jump to content

Baking Projected Texture Maps


Recommended Posts

Hey everyone!

I am projecting a still plate onto geometry, and would like to bake out the texture as I will be moving the geometry around, and possibly doing stretch and squash.

I followed the instructions here:

http://odforce.net/wiki/index.php/ShaderUnwrap

But they only worked for uv unwrapped objects, once I added in the UVTexture SOP with a camera projecting, it renders with box artifacts in Mantra. In any case, observing the UV space, it seems that the UVTexture SOP modifies the uv space greatly. I don't want that, as I would like to touch up my baked textures later.

Just thinking off my head, perhaps the UV texture sop isn't needed, just some new vex shader that will project the texture from camera/screen space onto the geometry, so that we can keep the UVUnwrapped layout?

I've attached a file, one showing the baking working for a uv mapped cylinder, and not working for the box.

Thanks!

Alvin

textureProjection.hip

Link to comment
Share on other sites

Hey all!

I finally got this working. I was going through the old Houdini 4 VEX tutorials, and found the tutorial on light and shadow shaders, and adapted the Spotlight projection map shader into a surface shader. Here's the code that I adapted, hope it works for you:

#pragma hint map image

surface
GW_camera_map_per_pixel(
string map = "";
vector uv = 0; // For debug
)

{

float uu,vv;
vector pos;
string gwString = "cam1";

if (map != "")
{

//pos  = wo_space(P);

//pos = toNDC(gwString, pos);

pos = toNDC(P);

uu = pos.x;
vv = pos.y;


Cf = texture(map, uu,vv);
}

else
{
Cf = {0,1,0};
//Cf = texture(map, uv.x,uv.y); // Debug purposes
}
}

This is a shader, so it should be in shops. Pipe in the image that you wish to project from. It will project from a camera in the scene. i still haven't figured out how it chooses the camera, but I only had one camera and it was projecting from that viewpoint. More tests required here. If you render the scene, it should work exactly like the UVTexture sop with camera projection enabled.

In order to bake out, ensure that you have unwrapped the object, on the vertices, not points. Then use the render command:

mantra -u /obj/geo1

Note that when baking out textures, I had to set the render resolution of the Mantra ROP to the same aspect ratio of the textures I was projection. E.g. I was projecting a 1280x960 JPEG onto some low res geometry, so my output from my mantra rop has to be, e.g. 640x480, 320x240 etc. If I were to render using say 1k by 1k, it would somehow be distorted? Wierd. More investigation required here. But in anycase, the experiment seems to be a success!

Disclaimer: If there is a better way of doing this, please let me know!!

post-1921-1176240660_thumb.jpg

post-1921-1176240880_thumb.jpg

post-1921-1176240889_thumb.jpg

post-1921-1176241007_thumb.jpg

post-1921-1176241102_thumb.jpg

Edited by GallenWolf
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...