赞 | 7 |
VIP | 0 |
好人卡 | 0 |
积分 | 3 |
经验 | 0 |
最后登录 | 2023-8-22 |
在线时间 | 36 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 283
- 在线时间
- 36 小时
- 注册时间
- 2018-4-30
- 帖子
- 14
|
2楼
楼主 |
发表于 2023-2-8 11:28:06
|
只看该作者
- Graphics.add_shader("
- PS_OUTPUT PS_RemoveAlpha(float4 color : COLOR0, float2 tex : TEXCOORD0) : COLOR
- {
- float4 res = tex2D(spriteSampler, tex);
- return GetOutput(float4(0, 0, 0, res.r) * color);
- }
- PS_OUTPUT PS_RemoveAlphaSub(float4 color : COLOR0, float2 tex : TEXCOORD0) : COLOR
- {
- float4 res = tex2D(spriteSampler, tex);
- return GetOutput(float4(res.a, res.a, res.a, res.a) * color);
- }
- int sheet_size;
- float opnear, opfar;
- PS_OUTPUT PS_CharacterShadow(float4 color : COLOR0,
- float2 tex : TEXCOORD0) : COLOR
- {
- float4 res = tex2D(spriteSampler, tex);
-
- float rem = tex.y * sheet_size;
- rem = rem - (int)(rem-0.0001);
- rem = opnear * rem + opfar * (1 - rem);
- res.a *= rem;
- return GetOutput(float4(0, 0, 0, res.a) * color);
- }
- PS_OUTPUT PS_GeoColor(float4 color : COLOR0) : COLOR
- {
- return GetOutput(color);
- }
- float occlusion_ambient = 1.0;
- PS_OUTPUT PS_GeoGlobalSprite(float4 color : COLOR0, float2 tex : TEXCOORD0) : COLOR
- {
-
- float4 res = tex2D(spriteSampler, tex);
- return GetOutput(float4(0, 0, 0, 1.0 - occlusion_ambient) - res);
- }
- ", "
- pass RemoveAlpha
- {
- AlphaBlendEnable = true;
- SeparateAlphaBlendEnable = false;
- BlendOp = REVSUBTRACT;
- SrcBlend = ONE;
- DestBlend = ONE;
-
- PixelShader = compile ps_2_0 PS_RemoveAlpha();
- }
- pass RemoveAlphaSub
- {
- AlphaBlendEnable = true;
- SeparateAlphaBlendEnable = false;
- BlendOp = REVSUBTRACT;
- SrcBlend = ONE;
- DestBlend = ONE;
-
- PixelShader = compile ps_2_0 PS_RemoveAlphaSub();
- }
- pass CharacterShadow
- {
- AlphaBlendEnable = true;
- SeparateAlphaBlendEnable = false;
- BlendOp = MAX;
- SrcBlend = ONE;
- DestBlend = ONE;
-
- PixelShader = compile ps_2_0 PS_CharacterShadow();
- }
- pass GeoMinimum
- {
- AlphaBlendEnable = true;
- SeparateAlphaBlendEnable = false;
- BlendOp = ADD;
- SrcBlend = ONE;
- DestBlend = ONE;
-
- PixelShader = compile ps_2_0 PS_GeoColor();
- }
- pass GeoSprite
- {
- AlphaBlendEnable = true;
- SeparateAlphaBlendEnable = false;
- BlendOp = REVSUBTRACT;
- SrcBlend = ONE;
- DestBlend = ONE;
-
- PixelShader = compile ps_2_0 PS();
- }
- pass GeoGlobalSprite
- {
- AlphaBlendEnable = true;
- SeparateAlphaBlendEnable = true;
- BlendOp = Add;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- PixelShader = compile ps_2_0 PS_GeoGlobalSprite();
- }
- ")
- module Cirno
- module Light
- #==============================================================================
- # ** Cirno::Light::LightSource
- #------------------------------------------------------------------------------
- # This class performs light source and visibility ranges.
- #==============================================================================
- class LightSource
- attr_accessor :uuid
- attr_accessor :visible
- attr_accessor :sprite
- attr_accessor :character
- attr_accessor :offset_x
- attr_accessor :offset_y
- attr_accessor :zoom
- attr_accessor :power
- attr_accessor :color
- attr_accessor :randomness
- attr_accessor :cast_shadow
- attr_accessor :shadow_opacity
- attr_accessor :cast_scale
- attr_accessor :cast_distance
- attr_accessor :cast_angle
- attr_accessor :viewport_shadow
- attr_accessor :cast_occlusion
- attr_accessor :occlusion_viewport
- attr_accessor :occlusion_power
- attr_accessor :life
- attr_accessor :update_proc
- attr_accessor :vars
-
- def initialize(viewport, character, bitmap)
- @viewport = viewport
- @character = character
- @sprite = Sprite.new(viewport)
- @sprite.bitmap = bitmap
- @sprite.ox = @sprite.width / 2
- @sprite.oy = @sprite.height / 2
- @offset_x = 0
- @offset_y = 0
- @z = 0
- @zoom = 1
- @power = 1
- @color = [0, 0, 0]
- @randomness = 0
- @cast_shadow = false
- @shadow_opacity = 255
- @cast_scale = 1.0
- @cast_distance = 3
- @cast_angle = 180
- @cast_occlusion = false
- @occlusion_power = 0
- @shadows = {}
-
- # Particle Properties ==========
- @life = -1
- @update_proc = nil
- # ==========
-
- @vars = {}
- update
- end
-
- def dispose
- @sprite.dispose
- @shadows.each_value { |sh|
- sh.each { |ss|
- # two shadow sprites for one character
- ss.dispose
- }
- }
- @occlusion.dispose if @occlusion
- end
-
- def update
- update_properties
- update_shadows
- update_occlusion
- end
-
- def center_x
- ox = 0
- if @character
- ox += @character.real_x
- end
- ox += @offset_x / 32.0
- ox
- end
-
- def center_y
- oy = 0
- if @character
- oy += @character.real_y
- end
- oy += @offset_y / 32.0
- oy
- end
-
- def update_properties
- return if @life == 0
- @sprite.visible = @visible
- @sprite.z = @z
- @sprite.zoom_x = @sprite.zoom_y = @zoom
- @sprite.opacity = @power * 255
-
-
- if color.size > 3
- @sprite.color = Color.new(color[0], color[1], color[2], color[3])
- else
- @sprite.color = Color.new(color[0], color[1], color[2])
- end
- if @character
- # character offset
- @offset_x = @character.custom_comment("offx").to_i
- @offset_y = @character.custom_comment("offy").to_i
- @offset_x = 0 unless @offset_x
- @offset_y = 0 unless @offset_y
-
- # light bound to character
- @sprite.visible = false if [email protected]_enabled
- @sprite.opacity *= @character.light_power.to_f
- @sprite.x = @character.screen_x + @offset_x
- @sprite.y = @character.screen_y - 16 + @offset_y
- else
- # light is not at character
- @life -= 1
- if @life == 0
- @visible = false
- return
- end
- if update_proc
- update_proc.call(self)
- end
- end
-
- # create randomness
- @rd_timer ||= 0
- @old_rd ||= 0.0
- @new_rd ||= 0.0
- @rd_timer += 1
- if @rd_timer % 5 == 0
- @rd_timer = 0
- @new_rd = (Light.rand(@randomness * 2) - @randomness) / 100.0
- end
- @old_rd = (@old_rd * 4 + @new_rd) / 5
- @sprite.opacity *= (1.0 + @old_rd)
-
- if @character
- target_angle = {
- 3 => 315,
- 2 => 270,
- 1 => 225,
- 4 => 180,
- 7 => 135,
- 6 => 0,
- 9 => 45,
- 8 => 90,
-
- }[@character.direction]
- if @sprite.angle % 360 != target_angle
- unless @angle_initialized
- @angle_initialized = true
- @sprite.angle = target_angle % 360
- else
- d1 = (target_angle - @sprite.angle) % 360
- d2 = (@sprite.angle - target_angle) % 360
- if d1 < d2
- @sprite.angle += 10
- else
- @sprite.angle -= 10
- end
- end
- end
- @sprite.angle %= 360
- end
- end
-
- def update_shadows
- return unless @cast_shadow
- all_characters = []
- all_characters += $game_map.events.values
- all_characters << $game_player
- $game_player.followers.each { |f| all_characters << f }
- all_characters.each { |ch|
- if ch.real_y == center_y &&
- ch.real_x == center_x
- next
- end
- if ch.custom_comment("noshadow")
- next
- end
- if ch.tile_id > 0
- next
- end
- ch_dist_sq =
- (ch.real_y - center_y) ** 2 +
- (ch.real_x - center_x) ** 2
- if ch_dist_sq > @cast_distance ** 2
- if @shadows[ch]
- @shadows[ch].each { |spr| spr.visible = false }
- end
- next
- end
-
- if !@shadows[ch]
- spr1 = Sprite_CharacterShadow.new(@viewport_shadow, ch)
- spr2 = Sprite_CharacterShadow.new(@viewport_shadow, ch)
- spr1.effect_name = "CharacterShadow"
- spr2.effect_name = "CharacterShadow"
- spr1.color = Color.new(0, 0, 0)
- spr2.color = Color.new(0, 0, 0)
- spr1.pattern = 1
- spr2.pattern = 1
- @shadows[ch] = [spr1, spr2]
- end
- sprs = @shadows[ch]
- spr1 = sprs[0]
- spr2 = sprs[1]
- spr1.visible = spr2.visible = true
- dxsym = ch.real_x - center_x
- dysym = ch.real_y - center_y
- dx = (dxsym).abs
- dy = (dysym).abs
- len = Math.sqrt(dx * dx + dy * dy)
-
- #ref_angle = {
- #2 => 90,
- #4 => 180,
- #6 => 0,
- #8 => 270}[@character.direction]
- ref_angle = 360 - @sprite.angle
- real_angle = Math.atan2(dysym, dxsym) * 180 / Math::PI
- delta_angle = (ref_angle + 180 - real_angle) % 360 - 180
- if len > @cast_distance || delta_angle.abs > @cast_angle
- spr1.visible = false
- spr2.visible = false
- next
- else
- spr_angle_power = (@cast_angle.to_f - delta_angle.abs) / @cast_angle * 2
- spr_angle_power = 1 if spr_angle_power > 1
- spr1.visible = true
- spr2.visible = true
- end
- # set pattern
-
- if [2, 4, 6, 8].include?(ch.direction)
- if ch.custom_comment("symmetric")
- spr1.direction = spr2.direction = ch.direction
- else
- if ch.real_x > center_x
- spr1.direction = { 2 => 6, 4 => 8, 6 => 2, 8 => 4 }[ch.direction]
- else
- spr1.direction = { 2 => 4, 4 => 2, 6 => 8, 8 => 6 }[ch.direction]
- end
- #if ch.real_y > center_y
- # spr2.direction = { 2 => 2, 4 => 6, 6 => 4, 8 => 8 }[ch.direction]
- #else
- # spr2.direction = { 2 => 8, 4 => 4, 6 => 6, 8 => 2 }[ch.direction]
- #end
- spr2.direction = ch.direction
- end
- end
-
- zoomx_correction = 1
-
- spr1.zoom_x = [[dx.to_f / len / zoomx_correction, 0].max, 1].min
- spr2.zoom_x = [[dy.to_f / len / zoomx_correction, 0].max, 1].min
- #if @cast_height > spr1.frame_height
- # zoom = len * 32.0 / (@cast_height.to_f - spr1.frame_height)
- #else
- # zoom = 1.0
- #end
- zoom = len * @cast_scale
- spr1.zoom_y = spr2.zoom_y = zoom
-
- opacity_factor_near =
- 1 - (len-1).to_f / (@cast_distance-1)
- opacity_factor_near = 1 if opacity_factor_near > 1
- opacity_factor_far =
- 1 - ((len + spr1.frame_height * zoom / 32.0)-1).to_f / (@cast_distance-1)
- opacity_factor_far = 0.5 if opacity_factor_far > 0.5
-
- #spr1.global_opacity = spr2.global_opacity =
- # @shadow_opacity * @character.light_strength / 100.0 *
- # [[1 - (len-1).to_f / (@cast_distance-1), 0].max, 1].min
- sh = spr1.single_character_sheet ? 4 : 8
- [spr1, spr2].each { |s|
- s.global_opacity =
- @shadow_opacity * @character.light_power * spr_angle_power
- s.set_effect_param("sheet_size", sh)
- s.set_effect_param("opnear", opacity_factor_near)
- s.set_effect_param("opfar", opacity_factor_far)
- # s.set_effect_param("light_rad", @cast_distance)
- # s.set_effect_param("light_x", @character.screen_x)
- # s.set_effect_param("light_y", @character.screen_y)
- }
- spr1.update
- spr2.update
- spr1.x -= dxsym / len * 2
- spr1.y -= dysym / len * 2
- spr2.x -= dxsym / len * 2
- spr2.y -= dysym / len * 2
-
- foot = ch.custom_comment("foot")
- if foot
- if foot == true
- foot = Cirno::Light::DEFAULT_FOOT_OFFSET
- else
- foot = foot.to_i
- end
- #spr1.oy = spr1.frame_height - foot
- spr1.y -= foot
- #spr2.oy = spr2.frame_height - foot
- spr2.y -= foot
- end
-
- spr1.angle = spr2.angle = -Math.atan2(ch.real_y - center_y,
- ch.real_x - center_x) * 180.0 / Math::PI - 90
- if dysym > 0
- spr1.mirror = spr2.mirror = true
- else
- spr1.mirror = spr2.mirror = false
- end
-
- #shear_x = -dxsym
- #spr1.zoom_y = spr2.zoom_y = -dysym
- #shear_y = 0
- #spr1.shear_x = spr2.shear_x = shear_x
- #spr1.shear_y = spr2.shear_y = shear_y
- }
- end
-
- def update_occlusion
- return unless @cast_occlusion
- @occlusion ||= Occlusion.new(@character, @occlusion_viewport)
- @occlusion.power = @occlusion_power * @character.light_power
- @occlusion.update
- end
- end
- #==============================================================================
- # ** Cirno::Light::Light_Visibility
- #==============================================================================
- class Light_Visibility < LightSource
- def initialize(viewport, character, bitmap)
- super(viewport, character, bitmap)
- @sprite.effect_name = "RemoveAlpha"
- @z = Light::VISIBILITY_LAYER_Z
- end
- end
- #==============================================================================
- # ** Cirno::Light::Light_Illumination
- #==============================================================================
- class Light_Illumination < LightSource
- def initialize(viewport, character, bitmap, blend, depth = nil)
- super(viewport, character, bitmap)
- if depth
- @z = depth
- elsif defined? Light::ILLUMINATION_LAYER_Z
- @z = Light::ILLUMINATION_LAYER_Z
- elsif @character
- @z = character.screen_z + 1
- end
- @sprite.blend_type = blend
- end
- end
- #==============================================================================
- # ** Cirno::Light::Occlusion
- #------------------------------------------------------------------------------
- # This class performs invisible ranges created by walls.
- #==============================================================================
- class Occlusion
- attr_accessor :power
- def initialize(character, viewport)
- @character = character
- @occlusion_viewport = viewport
- @power = 0
- initialize_viewrange
- end
-
- def set_viewport(viewport)
- @occlusion_viewport = viewport
- end
-
- def self.create_walltop_bitmap(fillc)
- bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
- for i in 0 ... $game_map.width
- for j in 0 ... $game_map.height
- rid = $game_map.region_id(i, j)
- if [Cirno::Light::WALL_REGION,
- Cirno::Light::WALL_TOP_REGION].include?(rid)
- bitmap.fill_rect(i * 32, j * 32, 32, 32, fillc)
- end
- end
- end
- bitmap
- end
-
- def self.create_walltop_sprite(viewport, z, effect_name = "")
- fillc = Color.new(0, 0, 0, 255)
- spr = Sprite.new(viewport)
- spr.bitmap = create_walltop_bitmap(fillc)
- spr.z = z
- spr.effect_name = effect_name
- #spr.effect_name = "GeoSprite"
- spr
- end
-
- def initialize_viewrange
- @shadow_geometry = Geometry.new(@occlusion_viewport)
- @shadow_geometry.z = 100
- #@shadow_geometry.visible = false
- @shadow_geometry.effect_name = "GeoMinimum"
- #@shadow_geometry.visible = false
-
- #@walltop = Sprite.new(@occlusion_viewport)
- #@walltop.effect_name = "GeoSprite"
- #@walltop.bitmap = create_walltop_bitmap
- #@walltop.z = @shadow_geometry.z + 1
- @walltop = Occlusion.create_walltop_sprite(@occlusion_viewport,
- @shadow_geometry.z + 1)
- end
-
- def dispose
- @shadow_geometry.dispose
- @walltop.bitmap.dispose
- @walltop.dispose
- end
-
- def update
- #@shadow_geometry.viewport = @occlusion_viewport
- @color = Color.new(0, 0, 0, 255 * @power)
- update_viewrange
- end
-
- def update_viewrange
- #@walltop.visible = $game_switches[1]
- #@shadow_geometry.visible = $game_switches[1]
-
- @walltop.x = -$game_map.display_x * 32
- @walltop.y = -$game_map.display_y * 32
-
- g = @shadow_geometry
-
- center = [@character.real_x + 0.5, @character.real_y + 0.5]
- map = $game_map
- visibility_triangles =
- Cirno::Light::get_visibility_triangles_from_map(map, center)
- g.triangles = visibility_triangles.size
- visibility_triangles.each_with_index { |triangle, index|
- 3.times { |p|
- shadow_add_on_map(index, p, triangle[p][0], triangle[p][1])
- }
- }
- end
-
- def shadow_add_on_map(triangle, point, mx, my)
- x = (mx - $game_map.display_x) * 32.0
- y = (my - $game_map.display_y) * 32.0
- @shadow_geometry.set_point_position(triangle, point, x, y)
- @shadow_geometry.set_point_color(triangle, point, @color)
- end
-
- def shadow_hide_triangle(triangle)
- @shadow_geometry.set_point_position(triangle, 0, -1, -1)
- @shadow_geometry.set_point_position(triangle, 1, -1, -1)
- @shadow_geometry.set_point_position(triangle, 2, -1, -1)
- end
- end
-
- #==============================================================================
- # ** Cirno::Light::LightLayer
- #------------------------------------------------------------------------------
- # This class performs all lighting effects.
- #==============================================================================
- class LightLayer
- attr_accessor :enabled
-
- def initialize(viewport_visibility, viewport_illum)
- @viewport_visibility = viewport_visibility
- @viewport_illumination = viewport_illum
- @viewport_occlusion = Viewport.new
- @viewport_occlusion.z = 990
- #@viewport_occlusion.effect_name = "GeoViewport"
- @viewport_occlusion.visible = false
-
- @viewport_shadow = Viewport.new
- @viewport_shadow.visible = false
- @enabled = true
- create_mask
- create_sources
- create_occlusion
- create_shadow
- update
- end
-
- def dispose
- dispose_mask
- dispose_sources
- dispose_shadow
- dispose_occlusion
- end
-
- def update
- update_mask
- update_sources
- update_shadow
- update_occlusion
- end
-
- def create_mask
- @mask = Sprite.new(@viewport_visibility)
- @mask.bitmap = Bitmap.new(1, 1)
- @mask.bitmap.set_pixel(0, 0, Color.new(0, 0, 0, 255))
- @mask.zoom_x = Graphics.width
- @mask.zoom_y = Graphics.height
- @mask.z = Light::VISIBILITY_LAYER_Z - 1
- end
-
- def create_occlusion
- #@occlusion_sprite = Sprite.new(@viewport_occlusion)
- #@occlusion_sprite.bitmap = Bitmap.new(1, 1)
- #@occlusion_sprite.bitmap.set_pixel(0, 0, Color.new(0, 0, 0, 255))
- #@occlusion_sprite.zoom_x = Graphics.width
- #@occlusion_sprite.zoom_y = Graphics.height
- @occlusion_sprite = Sprite.new(@viewport_illumination)
- @occlusion_sprite.effect_name = "GeoGlobalSprite"
- @occlusion_sprite.set_effect_param("occlusion_ambient",
- Cirno::Light::OCCLUSION_AMBIENT)
- @occlusion_sprite.z = Cirno::Light::OCCLUSION_LAYER_Z
- end
-
- def create_sources
- @sources = []
- $game_map.events.each_value { |e|
- add_source_from_character(e)
- }
- add_source_from_character($game_player)
- end
-
- def create_shadow
- @shadow_sprite = Sprite.new(@viewport_illumination)
- @shadow_sprite.z = 0
-
- @shadow_walltop_sprite = Occlusion.create_walltop_sprite(
- @viewport_shadow, 100, "GeoSprite")
- end
-
- def add_source(s, ch, init_proc = nil, update_proc = nil, depth = nil)
- @@uuid ||= 0
- @@uuid += 1
-
- if s[:visibility].size > 0
- src_visibility = Light_Visibility.new(@viewport_visibility, ch,
- Cache.picture(s[:visibility]))
- src_visibility.uuid = @@uuid
- if init_proc
- init_proc.call(src_visibility)
- end
- src_visibility.update_proc = update_proc
- src_visibility.zoom = s[:zoom]
- src_visibility.randomness = s[:light_rand]
- src_visibility.cast_occlusion = s[:cast_occlusion]
- src_visibility.occlusion_viewport = @viewport_occlusion
- src_visibility.occlusion_power = s[:occlusion_power]
- @sources << src_visibility
- end
-
- color_data = s[:color]
- if color_data[0] == "t"
- color_data = color_data[rand(color_data.size - 1) + 1]
- end
- color_alpha = 255
- if color_data.size > 3
- color_alpha = color_data[3]
- end
-
- if s[:illumination].size > 0
- create_absorb = false
- color1 = [0, 0, 0, color_alpha]
- color2 = [0, 0, 0, color_alpha]
- 3.times { |i|
- if color_data[i] >= 0
- color1[i] += color_data[i]
- else
- create_absorb = true
- color2[i] -= color_data[i]
- end
- }
- create_absorb = false if s[:light_type] == 2
-
- src_illum = Light_Illumination.new(@viewport_illumination, ch,
- Cache.picture(s[:illumination]), s[:light_type], depth)
- src_illum.uuid = @@uuid
- if init_proc
- init_proc.call(src_illum)
- end
- src_illum.update_proc = update_proc
- src_illum.zoom = s[:zoom]
- src_illum.power = s[:power]
- src_illum.color = color1
- src_illum.randomness = s[:light_rand]
- src_illum.cast_shadow = s[:cast_shadow]
- src_illum.shadow_opacity = s[:shadow_opacity]
- src_illum.cast_scale = s[:cast_scale]
- src_illum.cast_distance = s[:cast_distance]
- src_illum.cast_angle = s[:cast_angle]
- src_illum.viewport_shadow = @viewport_shadow
- @sources << src_illum
-
- if create_absorb
- src_absorb = Light_Illumination.new(@viewport_illumination, ch,
- Cache.picture(s[:illumination]), 2, depth)
- src_absorb.uuid = @@uuid
- if init_proc
- init_proc.call(src_absorb)
- end
- src_absorb.update_proc = update_proc
- src_absorb.zoom = s[:zoom]
- src_absorb.power = s[:power]
- src_absorb.color = color2
- src_absorb.randomness = s[:light_rand]
- @sources << src_absorb
- end
- end
- end
-
- def add_source_from_character(ch, custom_flag = nil)
- if custom_flag
- s = Light::get_setting(custom_flag)
- else
- s = Light::get_setting(ch.light_flag)
- end
- return unless s
-
- add_source(s, ch)
- end
-
- def delete_source_from_character(character)
- @sources.each { |src|
- if src.character == character
- src.dispose
- end
- }
- @sources.delete_if { |src|
- src.character == character
- }
- end
-
- def dispose_mask
- @mask.bitmap.dispose
- @mask.dispose
- end
-
- def dispose_sources
- @sources.each { |source|
- source.dispose
- }
- end
-
- def dispose_shadow
- @shadow_sprite.bitmap.dispose if @shadow_sprite.bitmap
- @shadow_sprite.dispose
- @shadow_walltop_sprite.bitmap.dispose
- @shadow_walltop_sprite.dispose
- @viewport_shadow.dispose
- end
-
- def dispose_occlusion
- @occlusion_sprite.bitmap.dispose if @occlusion_sprite.bitmap
- @occlusion_sprite.dispose
- @viewport_occlusion.dispose
- end
-
- def update_mask
- @mask.visible = @enabled
- @mask.opacity = $game_variables[Light::DARKNESS_OPACITY_VARIABLE]
- end
-
- def update_sources
- @sources.each { |source|
- source.visible = @enabled
- source.update
- if source.life == 0
- source.dispose
- end
- }
- @sources.delete_if { |src| src.life == 0 }
- end
-
- def update_occlusion
- return unless @occlusion_sprite
- any_occlusion = @sources.any? { |s| s.cast_occlusion }
- @occlusion_sprite.visible = any_occlusion
- @occlusion_sprite.bitmap = @viewport_occlusion.snap_to_bitmap
- #@occlusion_sprite.visible = false
- end
-
- def update_shadow
- return unless @shadow_sprite
- #@shadow_sprite.bitmap.dispose if @shadow_sprite.bitmap
- @shadow_sprite.bitmap = @viewport_shadow.snap_to_bitmap
-
- @shadow_walltop_sprite.x = -$game_map.display_x * 32
- @shadow_walltop_sprite.y = -$game_map.display_y * 32
- #@shadow_walltop_sprite.visible = false
- end
-
- end
- end
- end
- class Game_Character
- attr_accessor :light_enabled
- attr_accessor :light_need_refresh
- alias cirno_20180814_initialize initialize
- def initialize
- @light_enabled = true
- @light_need_refresh = false
- @light_power = 1.0
- cirno_20180814_initialize
- end
-
- def custom_comment(flag)
- nil
- end
-
- def default_light_flag
- nil
- end
-
- def light_flag
- @light_flag = default_light_flag unless @light_flag
- @light_flag
- end
-
- def light_flag=(val)
- @light_flag = val
- end
-
- def light_power
- @light_power
- end
-
- def light_power=(val)
- @light_power = val
- @light_power = 0.0 if @light_power < 0.0
- @light_power = 1.0 if @light_power > 1.0
- end
- end
- class Game_Player
- def default_light_flag
- Cirno::Light::PLAYER_LIGHT_SETTING
- end
- end
- class Game_Event
- alias cirno_20181213_initialize initialize
- def initialize(map_id, event)
- self.default_light_flag
- cirno_20181213_initialize(map_id, event)
- end
- def custom_comment(flag)
- if self.list
- self.list.each { |item|
- if item.code == 108 || item.code == 408
- if item.parameters[0] == "[#{flag}]"
- return true
- elsif /\[#{flag}\](.+)/ === item.parameters[0]
- return $1
- end
- end
- }
- end
- return nil
- end
-
- def default_light_flag
- light_flag = custom_comment("light")
- light_flag
- end
-
- alias cirno_20181213_refresh refresh
- def refresh
- cirno_20181213_refresh
- new_light_flag = custom_comment("light")
- if @light_flag != new_light_flag
- @light_flag = new_light_flag
- @light_need_refresh = true
- end
- end
- end
- class Sprite_CharacterShadow < Sprite_Character
- attr_accessor :direction
- attr_accessor :pattern
- attr_accessor :global_opacity
- def initialize(viewport, character)
- @direction = 0
- @pattern = 0
- @global_opacity = 255
- super(viewport, character)
- end
- def update_position
- move_animation(@character.screen_x - x, @character.screen_y - y)
- self.x = @character.screen_x
- self.y = @character.screen_y
- self.z = @character.screen_z - 1
- end
- def update_src_rect
- if @tile_id == 0
- index = @character.character_index
- sx = (index % 4 * 3 + @pattern) * @cw
- sy = (index / 4 * 4 + (@direction - 2) / 2) * @ch
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- end
- def update_other
- self.opacity = @character.opacity * global_opacity / 255
- self.blend_type = @character.blend_type
- self.bush_depth = @character.bush_depth
- self.visible = [email protected]
- end
- def frame_width
- @cw
- end
- def frame_height
- @ch
- end
- def single_character_sheet
- sign = @character_name[/^[\!\$]./]
- return sign && sign.include?(')
- end
- end
- class Spriteset_Map
- alias cirno_20180808_initialize initialize
- alias cirno_20180808_dispose dispose
- alias cirno_20180808_update update
-
- def initialize
- cirno_20180808_initialize
- create_light
- end
- def dispose
- dispose_light
- cirno_20180808_dispose
- end
- def update
- cirno_20180808_update
- update_light
- end
-
- def light
- @light
- end
-
- def create_light
- @light_map_id = $game_map.map_id
- if Cirno::Light::VISIBILITY_LAYER_MODE == 1
- if !@viewport_mask
- @viewport_mask = Viewport.new
- @viewport_mask.z = @viewport1.z + 1
- end
- viewport_visibility = @viewport_mask
- @viewport_mask.effect_name = "RemoveAlphaSub"
- else
- viewport_visibility = @viewport2
- end
- @light = Cirno::Light::LightLayer.new(viewport_visibility, @viewport1)
- end
-
- def dispose_light
- @light.dispose
- @viewport_mask.dispose if @viewport_mask
- @viewport_mask = nil
- end
-
- def update_light
- return unless @light
- if @light_map_id != $game_map.map_id
- dispose_light
- create_light
- end
- $game_map.events.values.each { |e|
- if e.light_need_refresh
- e.light_need_refresh = false
- refresh_light(e)
- end
- }
- @light.update
- end
-
- def replace_light(character, new_light_flag)
- @light.delete_source_from_character(character)
- @light.add_source_from_character(character, new_light_flag)
- end
-
- def refresh_light(character)
- @light.delete_source_from_character(character)
- if character.light_flag
- @light.add_source_from_character(character)
- end
- end
- end
- class Scene_Map
- def light
- @spriteset.light
- end
-
- def replace_light(character, flag)
- @spriteset.replace_light(character, flag)
- end
- end
- class Game_Interpreter
- # event_id:
- # -1: player
- # 0: this event
- # other: event with this id
- def change_light(event_id, name)
- return if $game_party.in_battle
- character = get_character(event_id)
- character.light_flag = name
- SceneManager.scene.replace_light(character, name)
- end
-
- def get_light_power(event_id = 0)
- event_id = 0 unless event_id
- return get_character(event_id).light_power
- end
-
- def set_light_power(value, event_id = 0)
- event_id = 0 unless event_id
- get_character(event_id).light_power = value
- end
- end
复制代码 |
|