menu

Questions & Answers

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.

Comments:
2023-01-21 00:30:08
you have to add texture externally like - texture = 'white_cube in your Entity.
Answers(4) :

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()

Use this code for your entity:

ground = Entity(
    model = 'untitled.gltf',
    z = 20,
    y = -3,
    collider = 'box',
    texture = 'texture.png', # or load_texture('texture.png') : load texture
    shader = lit_with_shadows_shader
)

You forgot to set the texture

You are missing the texture so here's your 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',
    texture='white_cube',
    shader = lit_with_shadows_shader
)

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

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

Your Problem is that you're misspelled "white_cube" to "white_cude" which is wrong. Change the syntax and it will work.