设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 963|回复: 3
打印 上一主题 下一主题

[已经解决] 【已解决】关于RGD Lighting脚本的问题

[复制链接]

Lv2.观梦者

梦石
0
星屑
283
在线时间
36 小时
注册时间
2018-4-30
帖子
14
跳转到指定楼层
1
发表于 2023-2-8 11:16:06 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 沐沐沐了个兮 于 2023-2-8 16:54 编辑

请问这个报错是因为什么呢

RD`5~%Z{`5X6E]PKAEIIAPW.png (7.59 KB, 下载次数: 5)

RD`5~%Z{`5X6E]PKAEIIAPW.png

Lv2.观梦者

梦石
0
星屑
283
在线时间
36 小时
注册时间
2018-4-30
帖子
14
2
 楼主| 发表于 2023-2-8 11:28:06 | 只看该作者


  1. Graphics.add_shader("
  2. PS_OUTPUT PS_RemoveAlpha(float4 color : COLOR0, float2 tex : TEXCOORD0) : COLOR
  3. {
  4.   float4 res = tex2D(spriteSampler, tex);
  5.   return GetOutput(float4(0, 0, 0, res.r) * color);
  6. }

  7. PS_OUTPUT PS_RemoveAlphaSub(float4 color : COLOR0, float2 tex : TEXCOORD0) : COLOR
  8. {
  9.   float4 res = tex2D(spriteSampler, tex);
  10.   return GetOutput(float4(res.a, res.a, res.a, res.a) * color);
  11. }

  12. int sheet_size;
  13. float opnear, opfar;
  14. PS_OUTPUT PS_CharacterShadow(float4 color : COLOR0,
  15.   float2 tex : TEXCOORD0) : COLOR
  16. {
  17.   float4 res = tex2D(spriteSampler, tex);
  18.   
  19.   float rem = tex.y * sheet_size;
  20.   rem = rem - (int)(rem-0.0001);
  21.   rem = opnear * rem + opfar * (1 - rem);
  22.   res.a *= rem;
  23.   return GetOutput(float4(0, 0, 0, res.a) * color);
  24. }

  25. PS_OUTPUT PS_GeoColor(float4 color : COLOR0) : COLOR
  26. {
  27.   return GetOutput(color);
  28. }

  29. float occlusion_ambient = 1.0;
  30. PS_OUTPUT PS_GeoGlobalSprite(float4 color : COLOR0, float2 tex : TEXCOORD0) : COLOR
  31. {
  32.   
  33.   float4 res = tex2D(spriteSampler, tex);
  34.   return GetOutput(float4(0, 0, 0, 1.0 - occlusion_ambient) - res);
  35. }
  36. ", "
  37. pass RemoveAlpha
  38. {
  39.   AlphaBlendEnable = true;
  40.   SeparateAlphaBlendEnable = false;
  41.   BlendOp = REVSUBTRACT;
  42.   SrcBlend = ONE;
  43.   DestBlend = ONE;
  44.   
  45.   PixelShader = compile ps_2_0 PS_RemoveAlpha();
  46. }

  47. pass RemoveAlphaSub
  48. {
  49.   AlphaBlendEnable = true;
  50.   SeparateAlphaBlendEnable = false;
  51.   BlendOp = REVSUBTRACT;
  52.   SrcBlend = ONE;
  53.   DestBlend = ONE;
  54.   
  55.   PixelShader = compile ps_2_0 PS_RemoveAlphaSub();
  56. }

  57. pass CharacterShadow
  58. {
  59.   AlphaBlendEnable = true;
  60.   SeparateAlphaBlendEnable = false;
  61.   BlendOp = MAX;
  62.   SrcBlend = ONE;
  63.   DestBlend = ONE;
  64.   
  65.   PixelShader = compile ps_2_0 PS_CharacterShadow();
  66. }

  67. pass GeoMinimum
  68. {
  69.   AlphaBlendEnable = true;
  70.   SeparateAlphaBlendEnable = false;
  71.   BlendOp = ADD;
  72.   SrcBlend = ONE;
  73.   DestBlend = ONE;
  74.   
  75.   PixelShader = compile ps_2_0 PS_GeoColor();
  76. }

  77. pass GeoSprite
  78. {
  79.   AlphaBlendEnable = true;
  80.   SeparateAlphaBlendEnable = false;
  81.   BlendOp = REVSUBTRACT;
  82.   SrcBlend = ONE;
  83.   DestBlend = ONE;
  84.   
  85.   PixelShader = compile ps_2_0 PS();
  86. }

  87. pass GeoGlobalSprite
  88. {
  89.   AlphaBlendEnable = true;
  90.   SeparateAlphaBlendEnable = true;
  91.   BlendOp = Add;
  92.   SrcBlend = SrcAlpha;
  93.   DestBlend = InvSrcAlpha;
  94.   
  95.   PixelShader = compile ps_2_0 PS_GeoGlobalSprite();
  96. }
  97. ")
  98. module Cirno
  99.   module Light
  100. #==============================================================================
  101. # ** Cirno::Light::LightSource
  102. #------------------------------------------------------------------------------
  103. #  This class performs light source and visibility ranges.
  104. #==============================================================================
  105.     class LightSource
  106.       attr_accessor :uuid
  107.       attr_accessor :visible
  108.       attr_accessor :sprite
  109.       attr_accessor :character
  110.       attr_accessor :offset_x
  111.       attr_accessor :offset_y
  112.       attr_accessor :zoom
  113.       attr_accessor :power
  114.       attr_accessor :color
  115.       attr_accessor :randomness
  116.       attr_accessor :cast_shadow
  117.       attr_accessor :shadow_opacity
  118.       attr_accessor :cast_scale
  119.       attr_accessor :cast_distance
  120.       attr_accessor :cast_angle
  121.       attr_accessor :viewport_shadow
  122.       attr_accessor :cast_occlusion
  123.       attr_accessor :occlusion_viewport
  124.       attr_accessor :occlusion_power
  125.       attr_accessor :life
  126.       attr_accessor :update_proc
  127.       attr_accessor :vars
  128.       
  129.       def initialize(viewport, character, bitmap)
  130.         @viewport = viewport
  131.         @character = character
  132.         @sprite = Sprite.new(viewport)
  133.         @sprite.bitmap = bitmap
  134.         @sprite.ox = @sprite.width / 2
  135.         @sprite.oy = @sprite.height / 2
  136.         @offset_x = 0
  137.         @offset_y = 0
  138.         @z = 0
  139.         @zoom = 1
  140.         @power = 1
  141.         @color = [0, 0, 0]
  142.         @randomness = 0
  143.         @cast_shadow = false
  144.         @shadow_opacity = 255
  145.         @cast_scale = 1.0
  146.         @cast_distance = 3
  147.         @cast_angle = 180
  148.         @cast_occlusion = false
  149.         @occlusion_power = 0
  150.         @shadows = {}
  151.         
  152.         # Particle Properties ==========
  153.         @life = -1
  154.         @update_proc = nil
  155.         # ==========
  156.         
  157.         @vars = {}
  158.         update
  159.       end
  160.       
  161.       def dispose
  162.         @sprite.dispose
  163.         @shadows.each_value { |sh|
  164.           sh.each { |ss|
  165.             # two shadow sprites for one character
  166.             ss.dispose
  167.           }
  168.         }
  169.         @occlusion.dispose if @occlusion
  170.       end
  171.       
  172.       def update
  173.         update_properties
  174.         update_shadows
  175.         update_occlusion
  176.       end
  177.       
  178.       def center_x
  179.         ox = 0
  180.         if @character
  181.           ox += @character.real_x
  182.         end
  183.         ox += @offset_x / 32.0
  184.         ox
  185.       end
  186.       
  187.       def center_y
  188.         oy = 0
  189.         if @character
  190.           oy += @character.real_y
  191.         end
  192.         oy += @offset_y / 32.0
  193.         oy
  194.       end
  195.       
  196.       def update_properties
  197.         return if @life == 0
  198.         @sprite.visible = @visible
  199.         @sprite.z = @z
  200.         @sprite.zoom_x = @sprite.zoom_y = @zoom
  201.         @sprite.opacity = @power * 255
  202.         
  203.         
  204.         if color.size > 3
  205.           @sprite.color = Color.new(color[0], color[1], color[2], color[3])
  206.         else
  207.           @sprite.color = Color.new(color[0], color[1], color[2])
  208.         end
  209.         if @character
  210.           # character offset
  211.           @offset_x = @character.custom_comment("offx").to_i
  212.           @offset_y = @character.custom_comment("offy").to_i
  213.           @offset_x = 0 unless @offset_x
  214.           @offset_y = 0 unless @offset_y
  215.          
  216.           # light bound to character
  217.           @sprite.visible = false if [email protected]_enabled
  218.           @sprite.opacity *= @character.light_power.to_f
  219.           @sprite.x = @character.screen_x + @offset_x
  220.           @sprite.y = @character.screen_y - 16 + @offset_y
  221.         else
  222.           # light is not at character
  223.           @life -= 1
  224.           if @life == 0
  225.             @visible = false
  226.             return
  227.           end
  228.           if update_proc
  229.             update_proc.call(self)
  230.           end
  231.         end
  232.         
  233.         # create randomness
  234.         @rd_timer ||= 0
  235.         @old_rd ||= 0.0
  236.         @new_rd ||= 0.0
  237.         @rd_timer += 1
  238.         if @rd_timer % 5 == 0
  239.           @rd_timer = 0
  240.           @new_rd = (Light.rand(@randomness * 2) - @randomness) / 100.0
  241.         end
  242.         @old_rd = (@old_rd * 4 + @new_rd) / 5
  243.         @sprite.opacity *= (1.0 + @old_rd)
  244.         
  245.         if @character
  246.           target_angle = {
  247.             3 => 315,
  248.             2 => 270,
  249.             1 => 225,
  250.             4 => 180,
  251.             7 => 135,
  252.             6 => 0,
  253.             9 => 45,
  254.             8 => 90,
  255.             
  256.           }[@character.direction]
  257.           if @sprite.angle % 360 != target_angle
  258.             unless @angle_initialized
  259.               @angle_initialized = true
  260.               @sprite.angle = target_angle % 360
  261.             else
  262.               d1 = (target_angle - @sprite.angle) % 360
  263.               d2 = (@sprite.angle - target_angle) % 360
  264.               if d1 < d2
  265.                 @sprite.angle += 10
  266.               else
  267.                 @sprite.angle -= 10
  268.               end
  269.             end
  270.           end
  271.           @sprite.angle %= 360
  272.         end
  273.       end
  274.       
  275.       def update_shadows
  276.         return unless @cast_shadow
  277.         all_characters = []
  278.         all_characters += $game_map.events.values
  279.         all_characters << $game_player
  280.         $game_player.followers.each { |f| all_characters << f }
  281.         all_characters.each { |ch|
  282.           if ch.real_y == center_y &&
  283.             ch.real_x == center_x
  284.             next
  285.           end
  286.           if ch.custom_comment("noshadow")
  287.             next
  288.           end
  289.           if ch.tile_id > 0
  290.             next
  291.           end
  292.           ch_dist_sq =
  293.             (ch.real_y - center_y) ** 2 +
  294.             (ch.real_x - center_x) ** 2
  295.           if ch_dist_sq > @cast_distance ** 2
  296.             if @shadows[ch]
  297.               @shadows[ch].each { |spr| spr.visible = false }
  298.             end
  299.             next
  300.           end
  301.          
  302.           if !@shadows[ch]
  303.             spr1 = Sprite_CharacterShadow.new(@viewport_shadow, ch)
  304.             spr2 = Sprite_CharacterShadow.new(@viewport_shadow, ch)
  305.             spr1.effect_name = "CharacterShadow"
  306.             spr2.effect_name = "CharacterShadow"
  307.             spr1.color = Color.new(0, 0, 0)
  308.             spr2.color = Color.new(0, 0, 0)
  309.             spr1.pattern = 1
  310.             spr2.pattern = 1
  311.             @shadows[ch] = [spr1, spr2]
  312.           end
  313.           sprs = @shadows[ch]
  314.           spr1 = sprs[0]
  315.           spr2 = sprs[1]
  316.           spr1.visible = spr2.visible = true
  317.           dxsym = ch.real_x - center_x
  318.           dysym = ch.real_y - center_y
  319.           dx = (dxsym).abs
  320.           dy = (dysym).abs
  321.           len = Math.sqrt(dx * dx + dy * dy)
  322.          
  323.           #ref_angle = {
  324.           #2 => 90,
  325.           #4 => 180,
  326.           #6 => 0,
  327.           #8 => 270}[@character.direction]
  328.           ref_angle = 360 - @sprite.angle
  329.           real_angle = Math.atan2(dysym, dxsym) * 180 / Math::PI
  330.           delta_angle = (ref_angle + 180 - real_angle) % 360 - 180
  331.           if len > @cast_distance || delta_angle.abs > @cast_angle
  332.             spr1.visible = false
  333.             spr2.visible = false
  334.             next
  335.           else
  336.             spr_angle_power = (@cast_angle.to_f - delta_angle.abs) / @cast_angle * 2
  337.             spr_angle_power = 1 if spr_angle_power > 1
  338.             spr1.visible = true
  339.             spr2.visible = true
  340.           end

  341.           # set pattern
  342.          
  343.           if [2, 4, 6, 8].include?(ch.direction)
  344.             if ch.custom_comment("symmetric")
  345.               spr1.direction = spr2.direction = ch.direction
  346.             else
  347.               if ch.real_x > center_x
  348.                 spr1.direction = { 2 => 6, 4 => 8, 6 => 2, 8 => 4 }[ch.direction]
  349.               else
  350.                 spr1.direction = { 2 => 4, 4 => 2, 6 => 8, 8 => 6 }[ch.direction]
  351.               end
  352.               #if ch.real_y > center_y
  353.               #  spr2.direction = { 2 => 2, 4 => 6, 6 => 4, 8 => 8 }[ch.direction]
  354.               #else
  355.               #  spr2.direction = { 2 => 8, 4 => 4, 6 => 6, 8 => 2 }[ch.direction]
  356.               #end
  357.               spr2.direction = ch.direction
  358.             end
  359.           end
  360.         
  361.           zoomx_correction = 1
  362.          
  363.           spr1.zoom_x = [[dx.to_f / len / zoomx_correction, 0].max, 1].min
  364.           spr2.zoom_x = [[dy.to_f / len / zoomx_correction, 0].max, 1].min
  365.           #if @cast_height > spr1.frame_height
  366.           #  zoom = len * 32.0 / (@cast_height.to_f - spr1.frame_height)
  367.           #else
  368.           #  zoom = 1.0
  369.           #end
  370.           zoom = len * @cast_scale
  371.           spr1.zoom_y = spr2.zoom_y = zoom
  372.          
  373.           opacity_factor_near =
  374.             1 - (len-1).to_f / (@cast_distance-1)
  375.           opacity_factor_near = 1 if opacity_factor_near > 1
  376.           opacity_factor_far =
  377.             1 - ((len + spr1.frame_height * zoom / 32.0)-1).to_f / (@cast_distance-1)
  378.           opacity_factor_far = 0.5 if opacity_factor_far > 0.5
  379.             
  380.           #spr1.global_opacity = spr2.global_opacity =
  381.           #  @shadow_opacity * @character.light_strength / 100.0 *
  382.           #  [[1 - (len-1).to_f / (@cast_distance-1), 0].max, 1].min

  383.           sh = spr1.single_character_sheet ? 4 : 8
  384.           [spr1, spr2].each { |s|
  385.             s.global_opacity =
  386.               @shadow_opacity * @character.light_power * spr_angle_power
  387.             s.set_effect_param("sheet_size", sh)
  388.             s.set_effect_param("opnear", opacity_factor_near)
  389.             s.set_effect_param("opfar", opacity_factor_far)
  390.           #  s.set_effect_param("light_rad", @cast_distance)
  391.           #  s.set_effect_param("light_x", @character.screen_x)
  392.           #  s.set_effect_param("light_y", @character.screen_y)
  393.           }
  394.           spr1.update
  395.           spr2.update
  396.           spr1.x -= dxsym / len * 2
  397.           spr1.y -= dysym / len * 2
  398.           spr2.x -= dxsym / len * 2
  399.           spr2.y -= dysym / len * 2
  400.          
  401.           foot = ch.custom_comment("foot")
  402.           if foot
  403.             if foot == true
  404.               foot = Cirno::Light::DEFAULT_FOOT_OFFSET
  405.             else
  406.               foot = foot.to_i
  407.             end
  408.             #spr1.oy = spr1.frame_height - foot
  409.             spr1.y -= foot
  410.             #spr2.oy = spr2.frame_height - foot
  411.             spr2.y -= foot
  412.           end
  413.          
  414.           spr1.angle = spr2.angle = -Math.atan2(ch.real_y - center_y,
  415.             ch.real_x - center_x) * 180.0 / Math::PI - 90
  416.           if dysym > 0
  417.             spr1.mirror = spr2.mirror = true
  418.           else
  419.             spr1.mirror = spr2.mirror = false
  420.           end
  421.          
  422.           #shear_x = -dxsym
  423.           #spr1.zoom_y = spr2.zoom_y = -dysym
  424.           #shear_y = 0
  425.           #spr1.shear_x = spr2.shear_x = shear_x
  426.           #spr1.shear_y = spr2.shear_y = shear_y

  427.         }
  428.       end
  429.       
  430.       def update_occlusion
  431.         return unless @cast_occlusion
  432.         @occlusion ||= Occlusion.new(@character, @occlusion_viewport)
  433.         @occlusion.power = @occlusion_power * @character.light_power
  434.         @occlusion.update
  435.       end
  436.     end
  437. #==============================================================================
  438. # ** Cirno::Light::Light_Visibility
  439. #==============================================================================
  440.     class Light_Visibility < LightSource
  441.       def initialize(viewport, character, bitmap)
  442.         super(viewport, character, bitmap)
  443.         @sprite.effect_name = "RemoveAlpha"
  444.         @z = Light::VISIBILITY_LAYER_Z
  445.       end
  446.     end
  447. #==============================================================================
  448. # ** Cirno::Light::Light_Illumination
  449. #==============================================================================
  450.     class Light_Illumination < LightSource
  451.       def initialize(viewport, character, bitmap, blend, depth = nil)
  452.         super(viewport, character, bitmap)
  453.         if depth
  454.           @z = depth
  455.         elsif defined? Light::ILLUMINATION_LAYER_Z
  456.           @z = Light::ILLUMINATION_LAYER_Z
  457.         elsif @character
  458.           @z = character.screen_z + 1
  459.         end
  460.         @sprite.blend_type = blend
  461.       end
  462.     end
  463. #==============================================================================
  464. # ** Cirno::Light::Occlusion
  465. #------------------------------------------------------------------------------
  466. #  This class performs invisible ranges created by walls.
  467. #==============================================================================
  468.     class Occlusion
  469.       attr_accessor :power
  470.       def initialize(character, viewport)
  471.         @character = character
  472.         @occlusion_viewport = viewport
  473.         @power = 0
  474.         initialize_viewrange
  475.       end
  476.       
  477.       def set_viewport(viewport)
  478.         @occlusion_viewport = viewport
  479.       end
  480.       
  481.       def self.create_walltop_bitmap(fillc)
  482.         bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
  483.         for i in 0 ... $game_map.width
  484.           for j in 0 ... $game_map.height
  485.             rid = $game_map.region_id(i, j)
  486.             if [Cirno::Light::WALL_REGION,
  487.                 Cirno::Light::WALL_TOP_REGION].include?(rid)
  488.               bitmap.fill_rect(i * 32, j * 32, 32, 32, fillc)
  489.             end
  490.           end
  491.         end
  492.         bitmap
  493.       end
  494.       
  495.       def self.create_walltop_sprite(viewport, z, effect_name = "")
  496.         fillc = Color.new(0, 0, 0, 255)
  497.         spr = Sprite.new(viewport)
  498.         spr.bitmap = create_walltop_bitmap(fillc)
  499.         spr.z = z
  500.         spr.effect_name = effect_name
  501.         #spr.effect_name = "GeoSprite"
  502.         spr
  503.       end
  504.       
  505.       def initialize_viewrange
  506.         @shadow_geometry = Geometry.new(@occlusion_viewport)
  507.         @shadow_geometry.z = 100
  508.         #@shadow_geometry.visible = false
  509.         @shadow_geometry.effect_name = "GeoMinimum"
  510.         #@shadow_geometry.visible = false
  511.    
  512.         #@walltop = Sprite.new(@occlusion_viewport)
  513.         #@walltop.effect_name = "GeoSprite"
  514.         #@walltop.bitmap = create_walltop_bitmap
  515.         #@walltop.z = @shadow_geometry.z + 1
  516.         @walltop = Occlusion.create_walltop_sprite(@occlusion_viewport,
  517.           @shadow_geometry.z + 1)
  518.       end
  519.       
  520.       def dispose
  521.         @shadow_geometry.dispose
  522.         @walltop.bitmap.dispose
  523.         @walltop.dispose
  524.       end
  525.   
  526.       def update
  527.         #@shadow_geometry.viewport = @occlusion_viewport
  528.         @color = Color.new(0, 0, 0, 255 * @power)
  529.         update_viewrange
  530.       end
  531.   
  532.       def update_viewrange
  533.         #@walltop.visible = $game_switches[1]
  534.         #@shadow_geometry.visible = $game_switches[1]
  535.    
  536.         @walltop.x = -$game_map.display_x * 32
  537.         @walltop.y = -$game_map.display_y * 32
  538.    
  539.         g = @shadow_geometry
  540.         
  541.         center = [@character.real_x + 0.5, @character.real_y + 0.5]
  542.         map = $game_map
  543.         visibility_triangles =
  544.           Cirno::Light::get_visibility_triangles_from_map(map, center)
  545.         g.triangles = visibility_triangles.size
  546.         visibility_triangles.each_with_index { |triangle, index|
  547.           3.times { |p|
  548.             shadow_add_on_map(index, p, triangle[p][0], triangle[p][1])
  549.           }
  550.         }
  551.       end
  552.   
  553.       def shadow_add_on_map(triangle, point, mx, my)
  554.         x = (mx - $game_map.display_x) * 32.0
  555.         y = (my - $game_map.display_y) * 32.0
  556.         @shadow_geometry.set_point_position(triangle, point, x, y)
  557.         @shadow_geometry.set_point_color(triangle, point, @color)
  558.       end
  559.   
  560.       def shadow_hide_triangle(triangle)
  561.         @shadow_geometry.set_point_position(triangle, 0, -1, -1)
  562.         @shadow_geometry.set_point_position(triangle, 1, -1, -1)
  563.         @shadow_geometry.set_point_position(triangle, 2, -1, -1)
  564.       end
  565.     end
  566.    
  567. #==============================================================================
  568. # ** Cirno::Light::LightLayer
  569. #------------------------------------------------------------------------------
  570. #  This class performs all lighting effects.
  571. #==============================================================================
  572.     class LightLayer
  573.       attr_accessor :enabled
  574.    
  575.       def initialize(viewport_visibility, viewport_illum)
  576.         @viewport_visibility = viewport_visibility
  577.         @viewport_illumination = viewport_illum
  578.         @viewport_occlusion = Viewport.new
  579.         @viewport_occlusion.z = 990
  580.         #@viewport_occlusion.effect_name = "GeoViewport"
  581.         @viewport_occlusion.visible = false
  582.         
  583.         @viewport_shadow = Viewport.new
  584.         @viewport_shadow.visible = false
  585.         @enabled = true
  586.         create_mask
  587.         create_sources
  588.         create_occlusion
  589.         create_shadow
  590.         update
  591.       end
  592.       
  593.       def dispose
  594.         dispose_mask
  595.         dispose_sources
  596.         dispose_shadow
  597.         dispose_occlusion
  598.       end
  599.    
  600.       def update
  601.         update_mask
  602.         update_sources
  603.         update_shadow
  604.         update_occlusion
  605.       end
  606.    
  607.       def create_mask
  608.         @mask = Sprite.new(@viewport_visibility)
  609.         @mask.bitmap = Bitmap.new(1, 1)
  610.         @mask.bitmap.set_pixel(0, 0, Color.new(0, 0, 0, 255))
  611.         @mask.zoom_x = Graphics.width
  612.         @mask.zoom_y = Graphics.height
  613.         @mask.z = Light::VISIBILITY_LAYER_Z - 1
  614.       end
  615.       
  616.       def create_occlusion
  617.         #@occlusion_sprite = Sprite.new(@viewport_occlusion)
  618.         #@occlusion_sprite.bitmap = Bitmap.new(1, 1)
  619.         #@occlusion_sprite.bitmap.set_pixel(0, 0, Color.new(0, 0, 0, 255))
  620.         #@occlusion_sprite.zoom_x = Graphics.width
  621.         #@occlusion_sprite.zoom_y = Graphics.height
  622.         @occlusion_sprite = Sprite.new(@viewport_illumination)
  623.         @occlusion_sprite.effect_name = "GeoGlobalSprite"
  624.         @occlusion_sprite.set_effect_param("occlusion_ambient",
  625.           Cirno::Light::OCCLUSION_AMBIENT)
  626.         @occlusion_sprite.z = Cirno::Light::OCCLUSION_LAYER_Z
  627.       end
  628.       
  629.       def create_sources
  630.         @sources = []
  631.         $game_map.events.each_value { |e|
  632.           add_source_from_character(e)
  633.         }
  634.         add_source_from_character($game_player)
  635.       end
  636.       
  637.       def create_shadow
  638.         @shadow_sprite = Sprite.new(@viewport_illumination)
  639.         @shadow_sprite.z = 0
  640.         
  641.         @shadow_walltop_sprite = Occlusion.create_walltop_sprite(
  642.           @viewport_shadow, 100, "GeoSprite")
  643.       end
  644.       
  645.       def add_source(s, ch, init_proc = nil, update_proc = nil, depth = nil)
  646.         @@uuid ||= 0
  647.         @@uuid += 1
  648.         
  649.         if s[:visibility].size > 0
  650.           src_visibility = Light_Visibility.new(@viewport_visibility, ch,
  651.             Cache.picture(s[:visibility]))
  652.           src_visibility.uuid = @@uuid
  653.           if init_proc
  654.             init_proc.call(src_visibility)
  655.           end
  656.           src_visibility.update_proc = update_proc
  657.           src_visibility.zoom = s[:zoom]
  658.           src_visibility.randomness = s[:light_rand]
  659.           src_visibility.cast_occlusion = s[:cast_occlusion]
  660.           src_visibility.occlusion_viewport = @viewport_occlusion
  661.           src_visibility.occlusion_power = s[:occlusion_power]
  662.           @sources << src_visibility
  663.         end
  664.         
  665.         color_data = s[:color]
  666.         if color_data[0] == "t"
  667.           color_data = color_data[rand(color_data.size - 1) + 1]
  668.         end
  669.         color_alpha = 255
  670.         if color_data.size > 3
  671.           color_alpha = color_data[3]
  672.         end
  673.         
  674.         if s[:illumination].size > 0
  675.           create_absorb = false
  676.           color1 = [0, 0, 0, color_alpha]
  677.           color2 = [0, 0, 0, color_alpha]
  678.           3.times { |i|
  679.             if color_data[i] >= 0
  680.               color1[i] += color_data[i]
  681.             else
  682.               create_absorb = true
  683.               color2[i] -= color_data[i]
  684.             end
  685.           }
  686.           create_absorb = false if s[:light_type] == 2
  687.          
  688.           src_illum = Light_Illumination.new(@viewport_illumination, ch,
  689.             Cache.picture(s[:illumination]), s[:light_type], depth)
  690.           src_illum.uuid = @@uuid
  691.           if init_proc
  692.             init_proc.call(src_illum)
  693.           end
  694.           src_illum.update_proc = update_proc
  695.           src_illum.zoom = s[:zoom]
  696.           src_illum.power = s[:power]
  697.           src_illum.color = color1
  698.           src_illum.randomness = s[:light_rand]
  699.           src_illum.cast_shadow = s[:cast_shadow]
  700.           src_illum.shadow_opacity = s[:shadow_opacity]
  701.           src_illum.cast_scale = s[:cast_scale]
  702.           src_illum.cast_distance = s[:cast_distance]
  703.           src_illum.cast_angle = s[:cast_angle]
  704.           src_illum.viewport_shadow = @viewport_shadow
  705.           @sources << src_illum
  706.          
  707.           if create_absorb
  708.             src_absorb = Light_Illumination.new(@viewport_illumination, ch,
  709.               Cache.picture(s[:illumination]), 2, depth)
  710.             src_absorb.uuid = @@uuid
  711.             if init_proc
  712.               init_proc.call(src_absorb)
  713.             end
  714.             src_absorb.update_proc = update_proc
  715.             src_absorb.zoom = s[:zoom]
  716.             src_absorb.power = s[:power]
  717.             src_absorb.color = color2
  718.             src_absorb.randomness = s[:light_rand]
  719.             @sources << src_absorb
  720.           end
  721.         end
  722.       end
  723.       
  724.       def add_source_from_character(ch, custom_flag = nil)
  725.         if custom_flag
  726.           s = Light::get_setting(custom_flag)
  727.         else
  728.           s = Light::get_setting(ch.light_flag)
  729.         end
  730.         return unless s
  731.         
  732.         add_source(s, ch)
  733.       end
  734.       
  735.       def delete_source_from_character(character)
  736.         @sources.each { |src|
  737.           if src.character == character
  738.             src.dispose
  739.           end
  740.         }
  741.         @sources.delete_if { |src|
  742.           src.character == character
  743.         }
  744.       end
  745.    
  746.       def dispose_mask
  747.         @mask.bitmap.dispose
  748.         @mask.dispose
  749.       end
  750.    
  751.       def dispose_sources
  752.         @sources.each { |source|
  753.           source.dispose
  754.         }
  755.       end
  756.       
  757.       def dispose_shadow
  758.         @shadow_sprite.bitmap.dispose if @shadow_sprite.bitmap
  759.         @shadow_sprite.dispose
  760.         @shadow_walltop_sprite.bitmap.dispose
  761.         @shadow_walltop_sprite.dispose
  762.         @viewport_shadow.dispose
  763.       end
  764.       
  765.       def dispose_occlusion
  766.         @occlusion_sprite.bitmap.dispose if @occlusion_sprite.bitmap
  767.         @occlusion_sprite.dispose
  768.         @viewport_occlusion.dispose
  769.       end
  770.    
  771.       def update_mask
  772.         @mask.visible = @enabled
  773.         @mask.opacity = $game_variables[Light::DARKNESS_OPACITY_VARIABLE]
  774.       end
  775.    
  776.       def update_sources
  777.         @sources.each { |source|
  778.           source.visible = @enabled
  779.           source.update
  780.           if source.life == 0
  781.             source.dispose
  782.           end
  783.         }
  784.         @sources.delete_if { |src| src.life == 0 }
  785.       end
  786.       
  787.       def update_occlusion
  788.         return unless @occlusion_sprite
  789.         any_occlusion = @sources.any? { |s| s.cast_occlusion }
  790.         @occlusion_sprite.visible = any_occlusion
  791.         @occlusion_sprite.bitmap = @viewport_occlusion.snap_to_bitmap
  792.         #@occlusion_sprite.visible = false
  793.       end
  794.       
  795.       def update_shadow
  796.         return unless @shadow_sprite
  797.         #@shadow_sprite.bitmap.dispose if @shadow_sprite.bitmap
  798.         @shadow_sprite.bitmap = @viewport_shadow.snap_to_bitmap
  799.         
  800.         @shadow_walltop_sprite.x = -$game_map.display_x * 32
  801.         @shadow_walltop_sprite.y = -$game_map.display_y * 32
  802.         #@shadow_walltop_sprite.visible = false
  803.       end
  804.       
  805.     end
  806.   end
  807. end

  808. class Game_Character
  809.   attr_accessor :light_enabled
  810.   attr_accessor :light_need_refresh
  811.   alias cirno_20180814_initialize initialize
  812.   def initialize
  813.     @light_enabled = true
  814.     @light_need_refresh = false
  815.     @light_power = 1.0
  816.     cirno_20180814_initialize
  817.   end
  818.   
  819.   def custom_comment(flag)
  820.     nil
  821.   end
  822.   
  823.   def default_light_flag
  824.     nil
  825.   end
  826.   
  827.   def light_flag
  828.     @light_flag = default_light_flag unless @light_flag
  829.     @light_flag
  830.   end
  831.   
  832.   def light_flag=(val)
  833.     @light_flag = val
  834.   end
  835.   
  836.   def light_power
  837.     @light_power
  838.   end
  839.   
  840.   def light_power=(val)
  841.     @light_power = val
  842.     @light_power = 0.0 if @light_power < 0.0
  843.     @light_power = 1.0 if @light_power > 1.0
  844.   end
  845. end

  846. class Game_Player
  847.   def default_light_flag
  848.     Cirno::Light::PLAYER_LIGHT_SETTING
  849.   end
  850. end

  851. class Game_Event
  852.   alias cirno_20181213_initialize initialize
  853.   def initialize(map_id, event)
  854.     self.default_light_flag
  855.     cirno_20181213_initialize(map_id, event)
  856.   end

  857.   def custom_comment(flag)
  858.     if self.list
  859.       self.list.each { |item|
  860.         if item.code == 108 || item.code == 408
  861.           if item.parameters[0] == "[#{flag}]"
  862.             return true
  863.           elsif /\[#{flag}\](.+)/ === item.parameters[0]
  864.             return $1
  865.           end
  866.         end
  867.       }
  868.     end
  869.     return nil
  870.   end
  871.   
  872.   def default_light_flag
  873.     light_flag = custom_comment("light")
  874.     light_flag
  875.   end
  876.   
  877.   alias cirno_20181213_refresh refresh
  878.   def refresh
  879.     cirno_20181213_refresh
  880.     new_light_flag = custom_comment("light")
  881.     if @light_flag != new_light_flag
  882.       @light_flag = new_light_flag
  883.       @light_need_refresh = true
  884.     end
  885.   end
  886. end

  887. class Sprite_CharacterShadow < Sprite_Character
  888.   attr_accessor :direction
  889.   attr_accessor :pattern
  890.   attr_accessor :global_opacity
  891.   def initialize(viewport, character)
  892.     @direction = 0
  893.     @pattern = 0
  894.     @global_opacity = 255
  895.     super(viewport, character)
  896.   end
  897.   def update_position
  898.     move_animation(@character.screen_x - x, @character.screen_y - y)
  899.     self.x = @character.screen_x
  900.     self.y = @character.screen_y
  901.     self.z = @character.screen_z - 1
  902.   end
  903.   def update_src_rect
  904.     if @tile_id == 0
  905.       index = @character.character_index
  906.       sx = (index % 4 * 3 + @pattern) * @cw
  907.       sy = (index / 4 * 4 + (@direction - 2) / 2) * @ch
  908.       self.src_rect.set(sx, sy, @cw, @ch)
  909.     end
  910.   end
  911.   def update_other
  912.     self.opacity = @character.opacity * global_opacity / 255
  913.     self.blend_type = @character.blend_type
  914.     self.bush_depth = @character.bush_depth
  915.     self.visible = [email protected]
  916.   end
  917.   def frame_width
  918.     @cw
  919.   end
  920.   def frame_height
  921.     @ch
  922.   end
  923.   def single_character_sheet
  924.     sign = @character_name[/^[\!\$]./]
  925.     return sign && sign.include?(')
  926.   end
  927. end

  928. class Spriteset_Map
  929.   alias cirno_20180808_initialize initialize
  930.   alias cirno_20180808_dispose dispose
  931.   alias cirno_20180808_update update
  932.   
  933.   def initialize
  934.     cirno_20180808_initialize
  935.     create_light
  936.   end
  937.   def dispose
  938.     dispose_light
  939.     cirno_20180808_dispose
  940.   end
  941.   def update
  942.     cirno_20180808_update
  943.     update_light
  944.   end
  945.   
  946.   def light
  947.     @light
  948.   end
  949.   
  950.   def create_light
  951.     @light_map_id = $game_map.map_id
  952.     if Cirno::Light::VISIBILITY_LAYER_MODE == 1
  953.       if !@viewport_mask
  954.         @viewport_mask = Viewport.new
  955.         @viewport_mask.z = @viewport1.z + 1
  956.       end
  957.       viewport_visibility = @viewport_mask
  958.       @viewport_mask.effect_name = "RemoveAlphaSub"
  959.     else
  960.       viewport_visibility = @viewport2
  961.     end
  962.     @light = Cirno::Light::LightLayer.new(viewport_visibility, @viewport1)
  963.   end
  964.    
  965.   def dispose_light
  966.     @light.dispose
  967.     @viewport_mask.dispose if @viewport_mask
  968.     @viewport_mask = nil
  969.   end
  970.    
  971.   def update_light
  972.     return unless @light
  973.     if @light_map_id != $game_map.map_id
  974.       dispose_light
  975.       create_light
  976.     end
  977.     $game_map.events.values.each { |e|
  978.       if e.light_need_refresh
  979.         e.light_need_refresh = false
  980.         refresh_light(e)
  981.       end
  982.     }
  983.     @light.update
  984.   end
  985.   
  986.   def replace_light(character, new_light_flag)
  987.     @light.delete_source_from_character(character)
  988.     @light.add_source_from_character(character, new_light_flag)
  989.   end
  990.   
  991.   def refresh_light(character)
  992.     @light.delete_source_from_character(character)
  993.     if character.light_flag
  994.       @light.add_source_from_character(character)
  995.     end
  996.   end
  997. end

  998. class Scene_Map
  999.   def light
  1000.     @spriteset.light
  1001.   end
  1002.   
  1003.   def replace_light(character, flag)
  1004.     @spriteset.replace_light(character, flag)
  1005.   end
  1006. end

  1007. class Game_Interpreter
  1008.   # event_id:
  1009.   #    -1: player
  1010.   #     0: this event
  1011.   # other: event with this id
  1012.   def change_light(event_id, name)
  1013.     return if $game_party.in_battle
  1014.     character = get_character(event_id)
  1015.     character.light_flag = name
  1016.     SceneManager.scene.replace_light(character, name)
  1017.   end
  1018.   
  1019.   def get_light_power(event_id = 0)
  1020.     event_id = 0 unless event_id
  1021.     return get_character(event_id).light_power
  1022.   end
  1023.   
  1024.   def set_light_power(value, event_id = 0)
  1025.     event_id = 0 unless event_id
  1026.     get_character(event_id).light_power = value
  1027.   end
  1028. end
复制代码
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24252
在线时间
5036 小时
注册时间
2016-3-8
帖子
1618
3
发表于 2023-2-8 14:19:18 | 只看该作者
没有打官方补丁吧?
https://rpg.blue/forum.php?mod=viewthread&tid=350955

所以调用不存在的move_animation方法时就报错了
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
283
在线时间
36 小时
注册时间
2018-4-30
帖子
14
4
 楼主| 发表于 2023-2-8 15:25:35 | 只看该作者
alexncf125 发表于 2023-2-8 14:19
没有打官方补丁吧?
https://rpg.blue/forum.php?mod=viewthread&tid=350955

啊啊解决啦 非常感谢TT
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-20 01:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表