简体   繁体   English

3D Ursina 游戏中的照明

[英]Lighting in 3D Ursina Games

I just started learning the Ursina game engine and I was wondering if there was any way to add lighting against entities.我刚开始学习Ursina游戏引擎,我想知道是否有任何方法可以为实体添加光照。 I'm trying to make an FPS game and it seems I can't find anything on the topic of lighting!我正在尝试制作 FPS 游戏,但似乎找不到关于照明主题的任何内容! It surprising and frustrating so, please help me out.这令人惊讶和沮丧,请帮助我。 :) :)

Easy way:简单的方法:

for x in range(some_intager):
    for z in range(some_other_intager):
        Entity(model='cube', x=x, z=z, shader=lit_with_shadows_shader)
DirectionalLight(parent=pivot, y=2, z=3, shadows=True, rotation=(45, -45, 45))

You will need to add lights ( directional , point , spot or ambient ).您将需要添加灯光( directionalpointspotambient )。 And then use a shader like lit_with_shadows_shader .然后使用像lit_with_shadows_shader这样的着色器。 The code will be:代码将是:

from ursina import *
from ursina.shaders import lit_with_shadows_shader


class Lights:
        def __init__(self):
            self.pivot = Entity()
            self.direc_light = DirectionalLight(parent=self.pivot, y=2, z=3, shadows=True, rotation=(45, -45, 45))
            self.amb_light = AmbientLight(parent=self.pivot, color = color.rgba(100, 100, 100, 0.1))



app = Ursina()

# Set shader to all entities
Entity.default_shader = lit_with_shadows_shader



# Lights
Lights()
pivot = Lights().pivot
direc_light = Lights().direc_light
amb_light = Lights().amb_light


# Create entity
cube1 = Entity(model='plane', color = color.blue, position = (0,0,0), scale=(10,10,0), collider='box')
cube2 = Entity(model='cube', color = color.red, position = (3,3,0), collider='box')



app.run()

The best I can offer is that you make a nested for loop above the map and place objects.我能提供的最好的方法是在地图上方创建一个嵌套的 for 循环并放置对象。

Here is the code:这是代码:

for x in range(some_intager):
    for z in range(some_other_intager):
        Entity(model='cube', x=x, z=z, shader=lit_with_shadows_shader)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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