使用 DirectX 驱动的 RPGMaker VX Ace Game.exe

目录 / Contents

  1. 简介 / Introduction
  2. 使用方法和下载 / Instructions and Download Link
  3. API 参考 / API Reference
    1. Bitmap
    2. Font
    3. Graphics
    4. Mouse
    5. Sprite
    6. Viewport
  4. 与 RGSS3 的差异 / Difference with RGSS3
  5. Shader 参考 / Shader Reference
    1. RGD 中的 shader / Shader in RGD
    2. 在 Sprite 和 Viewport 上使用 shader / Use Shader on Sprites and Viewports
    3. 一些内置 shader 的可用内容 / Some Useful Contents in Built-in Shader
  6. 兼容性 / Compatibility
  7. 使用约定 / Terms of Use
  8. 更新记录 / Update Log

 

简介 / Introduction

RGDirect (RGD) 是对 RPG Maker VX Ace (RMVA) 的脚本系统 RGSS3 的部分重新实现和功能扩展。它的主要作用是提升游戏的绘图效率、增强绘图扩展性,同时修正一些存在于原版 RGSS3 的漏洞。

RGD 使用 DirectX9 重新实现了 RGSS3 的 Bitmap, Graphics, Viewport, Sprite, Tilemap 和 Plane 绘图相关类和模块,利用 GPU 资源,使得绘制大地图、大图片、较多旋转缩放精灵的时候足够高效,杜绝了原版 RGSS 的卡顿现象。RGD 内置了 Sprite 和 Viewport 的 shader 接口,可以很方便地添加实时计算的自定义特效代码。位图操作方面,RGD 在实现原有操作的基础上,文字绘制内置了采用像素字的选项,可以不依赖外部 DLL 绘制像素字体。在图像绘制之外,RGD 加入了鼠标输入的功能,可以使用 Mouse 模块方便地获取鼠标的位置和按键状态。

这项工作由我和 Fux2 共同完成。Fux2 负责所有 C++ 代码和 Ruby 交互、Ruby 对象处理以及描绘文字相关的功能,我负责 D3D 绘图相关的功能。感谢 Mayaru 绘制了 RGD 的形象和图标文件。

如果有任何询问或意见,请在此处回复或发送邮件到 cirno@live.cn。

RGDirect (RGD) is a partial reimplementation and functional extension of the script system of RPG Maker VX Ace (RMVA), RGSS3. The main purporse of this project is to enhance the rendering efficiency, expansibility and to fix some bugs on original RGSS3.

RGD reimplements graphical classes and modules in RGSS3, Bitmap, Graphics, Viewport, Sprite, Tilemap and Plane, using DirectX9 technique. The performance for drawing maps, images of large size and scaling, rotating sprites of large number with GPU is greatly higher compared to the lag in RGSS3. RGD has a built-in shader interface in Sprites and Viewports which is used for real-time custom effect code. On bitmap operations, besides the operators in RGSS3, RGD implements built-in pixel font option without using external DLLs. In addition, RGD implements mouse input. You may use module Mouse to get mouse position and button status easily.

This work is completed by Fux2 and me. Fux2 completed all the communications between C++ and ruby, and functions on drawing texts. I completed the functions related to D3D rendering. Many thanks to Mayaru for drawing the character and icons of RGD.

If you have any questions or advice, please reply to this post or send email to cirno@live.cn.

      

 

使用方法和下载 / Instructions and Download Link

下载地址 Download Link:  RGDv1.2.1

使用此处提供的 RGD Game.exe 替换原版游戏的 Game.exe。

Replace original Game.exe with RGD Game.exe from here.

当前可用的 RGD 脚本一览:

Available RGD script list:

请注意一些范例内置exe可能版本并非最新。

Please pay attention to the version of exe in example. They are not always the newest version.

光照 Lighting (RGD1.2):RGD_Lighting_Example

 

API 参考 / API Reference

本节只显示默认 RGSS3 没有提供的接口。对于 RGSS3 已有的功能,请参考 RMVA 的 F1 帮助文档。

This section only shows interfaces RGSS3 does not provide. For existing functions in RGSS3, please refer to the F1 manual in RMVA.

Bitmap

Controller

 

Controller::ControllerState

Font

 

Geometry

 

Graphics

 

Mouse

 

RGD

 

Sprite

 

Viewport

 

与 RGSS3 的差异 / Difference with RGSS3

本节不包括上述 API 中介绍的部分。除此之外已知的 RGD 和 RGSS3 的差异有:

  • Graphics.play_movie 没有在 RGD 实现;
  • Bitmap 读写效率略低于 RGSS3 ,因为把修改后的纹理更新到 GPU 时有额外开销;
  • RGSS3 中 Sprite 的 blend_type可以跨 Viewport 起作用,但 RGD 中由于实现方式差异, Viewport 之间的合成相互独立,上层的加法、减法合成不能作用在下层。
  • RGD 取消了 RGSS3 的 F1 设置界面,用“关于”代替。

This section does not include API differences above. Other known differences between RGD and RGSS3 include:

  • Graphics.play_movie is not implemented in RGD;
  • Performance of Bitmap operators is slightly lower than RGSS3, because of extra overhead when updating modified texture to GPU.
  • blend_type in Sprites of RGSS3 can work across Viewports, while Sprites with additive and subtractive blend types in higher viewport in RGD cannot work with lower viewport since the difference in implementation methods of Viewport.
  • RGD removes F1 config dialog in RGSS3 and replaces it with “About” dialog.

 

Shader 参考 / Shader Reference

English is currently not available in the first parts of this section. Sorry.

RGD 中的 shader / Shader in RGD

RGD 使用 shader 的方式为首先在 Graphics 中添加相应代码,再在 Sprite 和 Viewport 中设置对应的名称和参数去启用 shader 特效。Graphics.add_shader 分为两部分:主函数部分和 pass 定义部分。所有的 shader 都使用 HLSL 语言。

The way RGD using shaders is to add them in Graphics first, then to set corresponding name and parameters in Sprites and Viewports to enable shader effects. Graphics.add_shader is divided into two parameters: main function part and pass definition part. All the shaders use HLSL here.

对于主函数部分,一个通用的例子,也是 RGD 的默认 shader 展示如下。本案例中使用的函数都可以在自定义 shader 中调用。

For the main function part, a common example is demonstrated here, which is also the default shader in RGD. All the functions used in this case can be arbitrary called in custom shaders.

这一段函数是在 GPU 中每一个用上这段 shader 的像素都会独立执行一遍的,它们之间唯一的不同是传入的参数差别。下面分析上述函数的意义和作用:

This piece of function is executed on every pixel that GPU used the shader on. The only difference between these function executions are parameters. Now we analyse the function above:

首先上述函数中用到了 float4 和 float2 这些类型。它们是 HLSL 中的矢量格式,分别表示4个和2个 float 构成的矢量。它们可以进行逐位的加减乘除等操作,也可以使用 color.r, color.g, color.b, color.a(rgba 可以换成 xyzw)访问它们的分量。更进一步地,可以用 color.rg, color.rgb 等组合来用更小的向量形式一次性表示它其中好几个分量。

First the function above used data types like float4 and float2. They are vectors in HLSL, meaning vectors constructed with 4 floats or 2 floats. Vectors can be added, subtracted, multiplied and divided. You can also use color.r, color.g, color.b and color.a (rgba can replaced by xyzw) to access its components. Further more, you can use combinations like color.rg, color.rgb to represent multiple components as smaller vectors.

对于函数的定义,两个参数的格式是 name : SEMATIC。其中 name 表示参数名称,和 C 的函数参数相同;SEMATIC 表示它在 shader 中的使用方法和传递过程。color : COLOR0 是表示(顶点插值后)颜色的属性,texcoord : TEXCOORD0 表示当前位置的纹理坐标,也就是它对应 Bitmap 上哪一点。 PS_OUTPUT 是 shader 中自定义的结构,用来表示 Pixel Shader 的输出。其中包含两个颜色 COLOR0 和 COLOR1。这里不论是颜色还是纹理坐标,数据范围都是 0 到 1。对于颜色来说,(0, 0, 0) 代表全黑,(1, 1, 1) 代表全白(相当于 RM 的 (255, 255, 255))。对纹理坐标来说,(0, 0) 代表左上角,(1, 1) 代表右下角。

For function definition, the form of two parameters is name: SEMATIC, where name represents parameter name just like C function parameters, and SEMATIC means how it is passed and used in the shader. “color: COLOR0” represents vertex color after interpolation, and “texcoord: TEXCOORD0” represents texture coordinate on current pixel, which means what point on bitmap is the pixel corresponding to. PS_OUTPUT is a custom-defined structure in shader representing shader output. Two colors COLOR0 and COLOR1 are included. In this case, all colors and texture coordinates are from 0 to 1. For a color, (0, 0, 0) is totally black while (1, 1, 1) is totally white (like (255, 255, 255) in RM). For texture coordinates, (0, 0) is upper left corner while (1, 1) is bottom right corner.

samp(texcoord) 是自定义的在纹理寄存器上采样的函数,包括了坐标缩放和偏移的一些计算。如果想要直接进行采样,可以使用 tex2D( spriteSampler, texcoord ) 。tex2D 是从采样器上采样,也就是在图片上取颜色的操作;spriteSampler 通过 register(s0) 获得,是 D3DXSprite 中纹理的采样器,也就是我们需要绘制的图片。每个像素都具有不同的 texcoord,因此它们才能在图片上取到不同的点,最终把整张图片呈现出来。

samp(texcoord) is a custom sampling function on texture registers including some computation on coordinate scaling and translating. If you need to sample directly, you can use tex2D(spriteSampler, texcoord). tex2D is sampling function directly on registers, that is, obtaining colors from the image. Value of spriteSampler is obtained from register(s0), which is the texture used on D3DXSprite. Each pixel has different texture coordinate (texcoord), so they find different points on original image and finally present the whole image on screen.

ColorMap, BushMap 和 ToneMap 都是自定义的颜色处理函数,传入和返回的都是 float4 格式。其中 ColorMap 处理变色效果,BushMap 处理“草木茂密”效果,ToneMap 处理色调变更。

ColorMap, BushMap, and ToneMap are custom color transforming functions with both input and output float4. ColorMap handles color changing effect, BushMap handles “bush” effect in RM, while ToneMap handles tone changing effect.

res *= color 是把顶点颜色合成到当前颜色上。最常见的功能是当设置不透明度后,不透明度的信息就被携带在顶点颜色中,而 res 通过 tex2D 得到,只包含了原始图片的透明通道信息,所以要把精灵的整体不透明度信息合成上去。

“res *= color” is to blend vertex color on current color. A main function is to store alpha information in vertex color when using translucent sprites. Since res is got from tex2D with only alpha information in original bitmap, the overall alpha of sprite needs to be blended on it.

res.rgb *= res.a 的步骤称为预乘(Pre-multiply)。因为 alpha blending 中,最终颜色的计算公式为:背景色 * 背景色的 alpha * (1 – 前景色的不透明度) + 前景色 * 前景色的 alpha,所以我们在处理前景色时,先把它乘以 alpha,最后只要加到背景色的那一项上就可以了。当它成为背景色以后,因为已经预先乘了 alpha,所以“背景色 * 背景色的 alpha”也可以看作一个整体,直接参与运算。

“res.rgb *= res.a” is called “pre-multiply”. Because color formula in alpha blending is: final_color = background_color * background_alpha * (1 – foreground_alpha) + foreground_color * foreground_alpha, we multiply foreground_color with foreground_alpha as the new foreground_color, then we just need to add it directly on the background term. When the new color becomes background color, “background_color * background_color” is seen as a whole because alpha channel is pre-multiplied.

最后的 GetOutput,就是把我们得到的颜色,包装成 PS_OUTPUT 的格式输出。

Finally, GetOutput is to warp our result color as PS_OUTPUT and output it.

在写 shader 时可以从上面的代码开始修改和编辑。比如下面的案例就能让最终的颜色变得更红一些(为了避免重复,函数名称改成了PS2):

When you create a new shader, you can start modifying and editing from the example above. For example, the shader below makes final color more reddish. (We use PS2 as function name to avoid name conflict)

完成这个步骤后,就能在 add_shader 的第二个参数中添加 pass 了。一个典型的案例如下:

After this step, you can add a pass in the second parameter of add_shader. A typical example is shown here:

其中需要注意的是,AlphaBlend 代表 pass 的名字,在 Sprite 和 Viewport 的 effect_name 中设置成这个值就能对应使用(但是自定义的 pass 请换一个名称,因为 AphaBlend 是内部 shader 使用的,自定义写成 AlphaBlend2 就没问题)。另一点需要注意的在 PixelShader = compile ps_2_0 PS(); 中,PS() 就是我们上面定义的函数,如果想要使用自己定义的名叫 PS2 的函数,那么这里也要使用 PS2。

What you need to pay attention to is that AlphaBlend is the name of a pass. You can use it by setting effect_name to it on Sprites or Viewports (but please select another name in your custom shader, such as AlphaBlend2, because AlphaBlend is used in internal shader). Another point is that PS in PixelShader = compile ps_2_0 PS(); is the function we have defined. If you are going to use custom function PS2, you need to change function name to PS2 here.

AlphaBlendEnable 和 SeparateAlphaBlendEnable 分别表示开启透明合成以及颜色和不透明度采用不同的透明合成方式(因为存在减法合成这类颜色和透明度合成方式不同的算法)。BlendOp代表合成的运算符号,下面四行分别代表前景图颜色、背景图颜色、前景图 alpha,背景图 alpha 的合成参数。ONE 代表乘以1,INVSRCALPHA 代表 1 – 前景图 alpha 。上述的合成方式是在采用预乘的条件下,按透明度合成的正确做法。

在 Sprite 和 Viewport 上使用 shader / Use Shader on Sprites and Viewports

要使用上面定义的 shader,方法很直接,只要设置 Sprite#effect_name 和 Viewport#effect_name 对应于我们设置的值(比如 AlphaBlend2)就可以了。但是要实现一些复杂的效果,还需要把参数传入 shader 中才行。

If you need to use shader defined in previous section, just set Sprite#effect_name and Viewport#effect_name to our pass names (like AlphaBlend2). But you need to pass parameters in your shader if you are going to implement some complicated effects.

在 shader 第一部分的函数上方,我们可以自定义一些全局变量,比如:

On the first part of shader, we can define some global variables. For example:

其中定义 texture 的方式比较复杂。首先需要定义一个纹理资源 texture myparam_tex; ,然后定义一个 sampler 在它的上面采样。sampler_state中可以设置纹理的采样方式,比如 AddressU = Wrap 意味着如果纹理坐标超出了0到1,就会通过循环的方式回到0到1的范围,利用 Wrap 可以做出远景图循环等效果。

Here the definition of texture is a bit complicated. First we create a texture resource myparam_tex, then define a sampler to sample on it. Sampling methods are defined in sampler_state. AddressU = Wrap means texture coordinates will return to the range of 0 to 1 in cycle if it exceeds the range. You can use Wrap to obtain parallax looping effect.

这些参数一旦设置,就可以在自定义的函数中使用了。但为了设置这些参数,在 Sprite 和 Viewport 中,需要调用 set_effect_param,方式如下:

These parameters can be used in custom functions as long as they are set. But you still need set_effect_param to pass value into these parameters:

只要保证第一个名字参数和变量名一样,第二个参数符合变量类型,就没问题了。

You only need to ensure that the first parameter is variable name, and the second parameter fits your variable type.

一些内置 shader 的可用内容 / Some Useful Contents in Built-in Shader

这部分介绍定义在内置 shader 中(但并不是 HLSL 语言特性)的一些变量和函数。它们是 RGD 代码实现的。

This part introduces some built-in variables and functions of default shader (but not a part of HLSL feature). They are implemented in RGD source code.

兼容性 / Compatibility

已知有一些情况会导致 RGD 不能正常运行,请参考下列方式调整:

  1. RGSS300.dll 不受到 RGD 支持。请使用 RGSS301 或更新的版本。
  2. 因为硬件设备支持的纹理尺寸各不相同,太大的图片可能会在载入后自动缩小或出现崩溃等其他问题,所以请确保图片资源大小在 2048×2048 以下。如果需要大幅图片,请把它分割成多张图使用。
  3. AMD 显卡环境下可能会导致出错,这一点还未确定是不是 DirectX9 与 AMD 的兼容性问题或是其他原因,暂时没有解决的办法。

Ruby 脚本方面,RGD 保证和 RGSS3 的行为几乎一致,绝大多数第三方脚本不会引起兼容性问题。

一些第三方脚本使用内存地址等方式对 Bitmap 等对象进行处理,在直接使用 RGD 时可能会遇到兼容性问题。在这里列举一些可能有帮助的解决方法,希望它们不会成为制作游戏的阻碍。

  1. 使用 RGD 内置的功能,如 Font.pixel和Mouse模块,能替代一些特定功能的脚本(如利用半生的文字描绘扩展做像素字体效果,和一些鼠标脚本系统)。
  2. 使用 Bitmap#process_color 处理图片颜色。一些脚本(比如截图存档)会利用内存地址访问位图的数据,但是纹理的数据必须经过 lock 的过程才能编辑,因此建议使用 process_color。
  3. 尽量多使用精灵,并且把特效转移到 shader 中。一些脚本过度依赖位图操作,甚至每一帧都会修改图片,导致性能下降;RGD 的精灵以及 shader 开销都非常小,请尽量使用。
  4. 把一些 Sprite 设置为正确的 Viewport。因为跨图层叠加的行为和 RGSS3 存在差异,所以把带有合成效果的 Sprite 都放在同一 Viewport 内,比如 Scene_Map 的 @viewport1。

如果出现其他兼容性相关问题,会陆续补充到此处。

Some known factors may cause RGD not start properly. Please refer to the following solutions:

  1. RGSS300.dll is not supported in RGD. Please use RGSS301 or newer versions of DLL.
  2. Different hardware may support different texture size, while images with too large size may be automatically resized or cause other problems. Make sure the size of your image resources is smaller than 2048×2048. You may divide large images into multiple partitions if necessary.
  3. Crashes may happen on AMD graphic cards when running RGD. It is still unknown whether the crashes are caused by incompatibility of DirectX9 and AMD graphics. There is no solution for this issue at present.

RGD keeps all the behavior almost the same as RGSS3. Most third-party scripts do not cause any compatibility problems with RGD.

In Ruby scripts, some third-party scripts use memory address to handle Bitmap and other objects. This may cause compatibility problems when they are combined with RGD. Here are some solutions which may help you solve the problems and remove the obstructions when making your game.

  1. Use built-in functions of RGD, like Font.pixel and module Mouse. This replaces some scripts with specific functions (such as pixelated font from tktkgame bitmap extension, and some mouse input systems).
  2. Use Bitmap#process_color to process bitmap colors. Some scripts (such as snapshot on savefile) may use memory address on bitmap to access data. However the bitmap data in RGD is in form of textures and lock/unlock must be used to modify data. So the process_color is recommended here.
  3. Use sprite combinations instead of bitmap processing, while move special effects into shaders. Some third-party scripts rely on bitmap processing too much, even modify bitmaps at each frame, which may cause poor performance. The cost for RGD sprites and effects are greatly reduced. Please make use of them.
  4. Set the viewport of sprites properly. Because of the difference on cross viewport blending with RGSS3, it is helpful to put sprites in one viewport, such as @viewport1 in Scene_Map, if they have blending effects.

Other compatibility solutions will be updated here if new problems are found and solved.

 

使用约定 / Terms of Use

  • RGDirect 可以在 RPG Maker VX Ace 制作的非商业或商业游戏中使用。
  • 请勿用于违反相关国家法律法规的用途,请勿用于伤害他人的合理合法权益。
  • 请勿以制作者之外的其他名义二次发布 RGDirect。
  • RGDirect 的开发者不对使用过程中和使用后的任何问题负责。
  • 如果出现任何冲突,以相关法律法规、Enterbrain 公司的官方规定为准。
  • RGDirect is permitted to use in non-commercial or commercial games made with RPG Maker VX Ace.
  • Do not use RGDirect in violating the laws and regulations of related countries, and do not use it to harm the legitimate rights and interests of other people.
  • Do not republish RGDirect outside the name of the developers.
  • Developers on RGDirect are not responsible for any problems during and after use.
  • In the event of any conflict, laws and regulations of related countries, and the official instructions from Enterbrain Corporation shall prevail.

 

更新记录 / Update Log

  • 2018/9/2 – 1.2.1
    • 增加Controller模块识别XInput(XBOX360)手柄操作。
    • 修复一些BUG。
  • 2018/8/29 – 1.2
    • 增加了Geometry的z和w坐标,以及shader功能。
    • 窗口焦点触发事件改为RGD.focus_in和RGD.focus_out,取消窗口关闭事件。
    • 性能优化。
    • 修复大量BUG。
  • 2018/7/24 – 1.1.2
    • 修复一些BUG。
  • 2018/7/1 – 1.1.1
    • 增加Graphics.resize_window功能,直接缩放游戏窗口尺寸。
    • 修复一些BUG。
  • 2018/6/7 – 1.1
    • 增加了窗口获得焦点、失去焦点、关闭时的回调。
    • 增加了Geometry的图片功能。
    • 增加了调整窗口大小功能。
    • 修复大量BUG。
  • 2018/5/12 – 1.0.2
    • 增加了 Geometry 类,可以用于在屏幕上直接绘制三角形。
    • 增加了 Viewport 的快速绘制层的功能,便于制作粒子特效等批量精灵效果。
  • 2018/5/9 – 1.0.1
    • 修正了包括文字描绘、图像缩放等方面的大量BUG。
    • 增加了使用 Symbol 访问鼠标状态的方式。
  • 2018/5/4 – 1.0
    • 初版发布。
  • Sep 2, 2018 – 1.2.1
    • Added Controller module to receive XInput(XBOX360) game controller input.
    • Fixed some bugs.
  • Aug 29, 2018 – 1.2
    • Added z and w coordinates and shaders for Geometry.
    • Window events of getting and losing focus changed to RGD.focus_in and RGD.focus_out. Removed window close event.
    • Performance optimization.
    • Fixed lots of bugs.
  • Jul 24, 2018 – 1.1.2
    • Fixed some bugs.
  • Jul 1, 2018 – 1.1.1
    • Added Graphics.resize_window to resize game window directly.
    • Fixed some bugs.
  • Jun 7, 2018 – 1.1
    • Added callback on window getting focus, losing focus and closing.
    • Added bitmap on Geometry.
    • Added resizing window function.
    • Fixed lots of bugs.
  • May 12, 2018 – 1.0.2
    • Added Geometry class, which is used for drawing triangles on screen.
    • Added fast drawing layers on Viewport for batch sprites like particles.
  • May 9, 2018 – 1.0.1
    • Fixed lots of bugs related to text drawing, image scaling and more.
    • Added Symbol parameters on mouse state functions.
  • May 4, 2018 – 1.0
    • RGDirect released.

7 thoughts on “使用 DirectX 驱动的 RPGMaker VX Ace Game.exe

    1. invwindy Post author

      没有违反用户协议的,在RMW已经和官方的人联系过,没有问题。
      源码暂时不打算公开,因为可能比较乱,自己也暂时继续维护着,等没有精力更新了再公开吧。

      Reply
  1. 路过的海豹

    发现换用后会导致地图上第二层开始那些本来显示在玩家角色下方的图块变成覆盖玩家角色(没有其他任何脚本和修改)。

    典型的比如一棵树、一个高塔的下半部分。原版exe的话一棵树下半部分(通行X)会被玩家角色覆盖,而上半部分(通行☆)会覆盖玩家角色
    而换用新exe后只要位于第二层(B)以上的图块就会覆盖玩家角色。

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *