骑砍战团MOD开发(34)-光照系统

一.Direct3D光照类型

     Direct3D将光源分为3种类型,点光源,方向光源,聚光灯源.Direct3D内部会根据光源类型进行2D渲染管线实时计算.

     Direct3D将光照参数封装在D3DLight9结构体中,重要参数有光源类型,漫反射参数,高光参数等.

typedef struct D3DLIGHT9 {
    D3DLIGHTTYPE Type;
    D3DCOLORVALUE Diffuse;
    D3DCOLORVALUE Specular;
    D3DCOLORVALUE Ambient;
    D3DVECTOR Position;
    D3DVECTOR Direction;
} D3DLIGHT9, *LPD3DLIGHT;

Diffuse-光源发出的漫反射光颜色。
Specular-光源发出的镜面光颜色。
Ambient-光源发出的环境光颜色。
Position-用向量表示的光源世界坐标位置(对方向光无效)。

二.骑砍引擎光照

     骑砍通过将Direct3D中光照类型进行封装后,提供点光源参数动态修改接口,可实现火把,篝火,灯笼等光照效果.


  #环境默认光照参数设置
  set_startup_sun_light = 2390  # (set_startup_sun_light, , , ),

  set_startup_ambient_light                    = 2391  # (set_startup_ambient_light, , 
  , ),

  set_startup_ground_ambient_light             = 2392  (set_startup_ground_ambient_light, , , ),



  #自发光场景物(电灯泡,火把)
  ("light_sun",sokf_invisible,"light_sphere","0",  []),
  ("light",sokf_invisible,"light_sphere","0",  []),
  ("light_red",sokf_invisible,"light_sphere","0",  []),
  ("light_night",sokf_invisible,"light_sphere","0",  []),

  #动态添加点光源至场景物
  set_current_color  = 1950  # (set_current_color, , , ),

  set_position_delta = 1955  # (set_position_delta, , , ),

  add_point_light = 1960  # (add_point_light, [flicker_magnitude], [flicker_interval]),

  add_point_light_to_entity = 1961  # (add_point_light_to_entity, [flicker_magnitude], [flicker_interval]),

.根据白天和夜晚动态设置光照

(ti_on_init_scene_prop,[
  (neg|is_currently_night),
  (store_trigger_param_1, ":prop_instance_no"),
  (set_fixed_point_multiplier, 100),
  (prop_instance_get_scale, pos5, ":prop_instance_no"),
  (position_get_scale_x, ":scale", pos5),

  #获取当前时间
  (store_time_of_day,reg(12)),
  (try_begin),
    (is_between,reg(12),5,20),
    (store_mul, ":red", 5 * 200, ":scale"),
    (store_mul, ":green", 5 * 193, ":scale"),
    (store_mul, ":blue", 5 * 180, ":scale"),
  (else_try),
    (store_mul, ":red", 5 * 90, ":scale"),
    (store_mul, ":green", 5 * 115, ":scale"),
    (store_mul, ":blue", 5 * 150, ":scale"),
  (try_end),
  (val_div, ":red", 100),
  (val_div, ":green", 100),
  (val_div, ":blue", 100),

  #设置光源强度,颜色
  (set_current_color,":red", ":green", ":blue"),
  (set_position_delta,0,0,0),
  (add_point_light_to_entity, 0, 0),
]),

你可能感兴趣的:(骑砍1战团mod开发,游戏程序)