Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to bake UV map #815

Open
JWBWork opened this issue Aug 17, 2024 · 8 comments
Open

Unable to bake UV map #815

JWBWork opened this issue Aug 17, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@JWBWork
Copy link

JWBWork commented Aug 17, 2024

Description

Blender 4.1
Dream Textures Windows CUDA 4-1
Windows 11

Cuda version details

> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Wed_Apr_17_19:36:51_Pacific_Daylight_Time_2024
Cuda compilation tools, release 12.5, V12.5.40
Build cuda_12.5.r12.5/compiler.34177558_0

When I try to generate with bake enabled the result uses the original generated image and the baked version of the image is just a black image.

No exceptions/warnings are logged.

Screenshot 2024-08-13 224452
Screenshot 2024-08-13 224509
Screenshot 2024-08-13 224604

Steps to Reproduce

  1. Install with blender 4.1
  2. Create a mesh
  3. Unwrap mesh
  4. Duplicate mesh and rotate second mesh 90 degrees
  5. Generate with bake enabled using default recommended model

Expected Behavior

I believe the baked image should re-arrange the generated image to match my UV-map.

Addon Version

Windows (CUDA)

Blender Version

Blender 4.1+

GPU

NVIDIA

@JWBWork JWBWork added the bug Something isn't working label Aug 17, 2024
@JWBWork JWBWork changed the title <title> unable to bake UV map Unable to bake UV map Aug 17, 2024
@ViachaslauBusel
Copy link

The same problem. Both on Blender 4.1 and 3.6.

@klfajardo
Copy link

Same problem. Blender 4.2

@drvelociraptor
Copy link

Same problem here

@drvelociraptor
Copy link

did someone find a solution to this?

@Mopzilla
Copy link

having this issue, 4.3.1. would love a solution or fix

@jploski
Copy link

jploski commented Dec 27, 2024

The reason for the "black image" (Blender 4.2 here) appears to be that the "src" image passed in to the bake function, in script file .config/blender/4.2/scripts/addons/dream_textures/operators/project.py:416 is RGB instead of RGBA - which is expected by the bake function. This can be fixed by replacing the invocation:

                        bake(context, bm, result.image.ravel(), dest, src_uvs, dest_uvs)

with

                        bake(context, bm, image_utils.rgba(result.image).ravel(), dest, src_uvs, dest_uvs)

However, while with this "fix" the image is no longer black, the baking process does not work correctly, i.e. apparently wrong regions of the source image are mapped to the dest UV map.

@jploski
Copy link

jploski commented Dec 27, 2024

However, while with this "fix" the image is no longer black, the baking process does not work correctly, i.e. apparently wrong regions of the source image are mapped to the dest UV map.

I had to flip the y coordinate of the src_uv before bake. So in summary this patch solved this issue for me:

diff --git a/operators/project.py b/operators/project.py
index 7180763..c0c8afd 100644
--- a/operators/project.py
+++ b/operators/project.py
@@ -408,8 +408,9 @@ class ProjectDreamTexture(bpy.types.Operator):
                         for face in bm.faces:
                             for loop in face.loops:
                                 src_uvs[loop.vert.index] = loop[src_uv_layer].uv
+                                src_uvs[loop.vert.index][1] = 1.0 - src_uvs[loop.vert.index][1]
                                 dest_uvs[loop.vert.index] = loop[dest_uv_layer].uv
-                        bake(context, bm, result.image.ravel(), dest, src_uvs, dest_uvs)
+                        bake(context, bm, image_utils.rgba(result.image).ravel(), dest, src_uvs, dest_uvs)
                         dest.update()
                         dest.pack()
                         image_texture_node.image = dest

@carson-katri
Copy link
Owner

@jploski thanks for tracking this down! Would you be able to open a PR with this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants