简体   繁体   中英

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.

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

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_cude',
    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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM