mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 249 forks source link

Unable to render object with texture #1108

Closed duongnlt closed 8 months ago

duongnlt commented 8 months ago

System configuration

OS: Ubuntu 20.04 CPU: 12th Gen Intel(R) Core(TM) i5-12400 GPU: NVIDIA GeForce RTX 3060 Python version: 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0] LLVM version: 10.0.0 CUDA version: 12.2 NVidia driver: 535.104.12

Dr.Jit version: 0.4.3 Mitsuba version: 3.4.0 Compiled with: Clang 10.0.0 Variants compiled: scalar_rgb scalar_spectral llvm_rgb llvm_ad_rgb llvm_spectral cuda_rgb cuda_ad_rgb cuda_spectral scalar_rgb_polarized scalar_rgb_polarized_double scalar_spectral_polarized scalar_spectral_polarized_double cuda_rgb_polarized cuda_rgb_polarized_double cuda_spectral_polarized cuda_spectral_polarized_double llvm_spectral_polarized

Description

When I render my object with a texture file, the texture does not appear in my output image.

image

However, when I replace my object file with a built-in shape like sphere, the texture appears.

image

Here is link to the obj file and the texture files.

Steps to reproduce

import mitsuba as mi
import drjit as dr
import numpy as np
import matplotlib.pyplot as plt
import os
mi.set_variant('scalar_spectral_polarized')
from mitsuba import ScalarTransform4f as T

sensor = mi.load_dict({
    'type': 'orthographic',
    'to_world': T.translate([0,0,-20]),
    'sampler': {
        'type': 'multijitter',
        'sample_count': 64
    },
    'film': {
        'type': 'hdrfilm',
        'width': 1032,
        'height': 780,
        'pixel_format': 'rgb',
        'rfilter': {
            'type': 'gaussian'
        }
    }

})

integrator = mi.load_dict({
                    'type': 'path',
            },)
bsdf = {
    'type': 'diffuse',
    'reflectance': {
       'type': 'bitmap',
       'filename': '../scene/textures/metalplate_2-1K/metalplate_2_basecolor-1K.png',
    }
}
shape = mi.load_dict({
    'type': 'obj',
    'filename': f'../scene/meshes/DiLiGenT-obj/goblet.obj',
    'bsdf': bsdf,
    'to_world': T.translate([0,-0.5,0]).rotate(axis=[1,0,0], angle=-70).scale(0.01),

})
scene = mi.load_dict({
    'type':'scene',
    'integrator': integrator,
    'sensor': sensor,

        'light': {'type': 'constant'},
        'object': shape,
    'polarizer': polarizer
})
image = mi.render(scene)
bitmap = scene.sensors()[0].film().bitmap().split()[0][1]
merlinND commented 8 months ago

Hello @duongnlt,

This is happening because your OBJ file does not include a UV parametrization (one sign is that there are no vt directives inside the OBJ file). There sphere shape built into Mitsuba comes with a UV parametrization, which is why the texture could be displayed.

An easy way to generate a UV parametrization for your object is to use Blender's Smart UV Project tool.