pythonursina

Ursina engine lit_with_shadows_shader when added to a 3d model the textures disappear


Here is my code:

import numba as nb
from ursina import *
from ursina.shaders import lit_with_shadows_shader


app = Ursina()

ground = Entity(
    model = 'untitled.gltf',
    z = 20,
    y = -3,
    collider = 'box',
    shader = lit_with_shadows_shader
)

pivot = Entity()
AmbientLight()
DirectionalLight(parent=pivot, y=2, z=3, shadows=True)

EditorCamera()
sky = Sky()
app.run()

I am trying to display a 3D model I got from sketchfab and without the shader = lit_with_shadows_shader it works but when I add it in order to use the ambient light, it doesn't display the textures and it's the model but it's white and doesn't have any surface.


Solution

  • You need to define your texture otherwise the shader will not be able to render something that is not defined.

    ground = Entity(
        model = 'untitled.gltf',
        texture = "yourTextureName", # Put your texture here
        z = 20,
        y = -3,
        collider = 'box',
        shader = lit_with_shadows_shader
    )
    

    If you do not have a texture you can simply put a color, like this:

    ground = Entity(
        model = 'untitled.gltf',
        color = color.rgba(40,90,12,0.5) #This will be half transparent, to disable it change the 0.5 value to 1 or 0
        z = 20,
        y = -3,
        collider = 'box',
        shader = lit_with_shadows_shader
    )
    

    Your final code should be

    import numba as nb
    from ursina import *
    from ursina.shaders import lit_with_shadows_shader
    
    
    app = Ursina()
    
    ground = Entity(
        model = 'untitled.gltf',
        texture = 'textureFileName.png',
        z = 20,
        y = -3,
        collider = 'box',
        shader = lit_with_shadows_shader
    )
    
    pivot = Entity()
    AmbientLight()
    DirectionalLight(parent=pivot, y=2, z=3, shadows=True)
    
    EditorCamera()
    sky = Sky()
    app.run()