Project1

标题: 请问一般的阴影字用的都是什么算法? [打印本页]

作者: gonglinyuan    时间: 2015-8-28 17:02
标题: 请问一般的阴影字用的都是什么算法?
RMXP有很多阴影字脚本,原理都是在x+1且y+1的位置再用灰黑色draw_text一遍作为阴影,但是效果似乎不是很好。很多网页常见的漂亮的阴影字是用什么算法得来的?我觉得是像我前面说的一样投影然后把投影模糊,不知道大家怎么看?

还有RMVA的描边字,配合黑体真的很漂亮。这又是用什么算法得到的呢?不会是把原文字上下左右4个方向差一个像素的位置各draw_text一遍吧?我记得这样的实现会把字弄得很粗很难看呃。
作者: LBQ    时间: 2015-8-28 17:09
本帖最后由 LBQ 于 2015-8-28 17:18 编辑

我以前脑残实现的阴影方法(好像和你的差不多)是:
1:将原来文字Bitmap复制,变成全黑
2:放大
3:高斯模糊

当然这是我的方法

我感觉会有更好的方法(模糊肯定慢啊),但是这里6R我觉得不是一个特别适合你问的地方。gamedev.stackexchange.com假如会英文的话是更好,知乎我也不清楚。总之这里感觉不会特别好……


编辑:查到了文字描边


Flexible & Accurate: Filters

Use a texel filter either on the texture on the CPU side, or if you are using programmable pipeline OpenGL, directly in the fragment shader.

The idea of a filter is simply that you run through a 2D loop to process every texel. If it is white, then you run through an inner 2D loop for each of its surrounding pixels in some radius, and adapt accordingly. This is also known as a box filter, though if you include the radius check, it is really a circular filter -- which avoids axis-al artifacting.

A faster way to do this is to precalculate the set of offsets from each central pixel that you check; this way, you needn't run a square root for every pixel surrounding a given pixel. You want to keep complexity down to `O(texWidth*texHeight) rather than O(texWidth*texHeight*filterRadius*filterRadius), in other words.

Easy: Multiple renders

Another way to achieve the effect would be not to scale the text, but instead to render your red outline at each of eight (or more) directions, each slightly offset from the original in that direction:

\|/
--+--
/|\

By offsetting each of the red versions like this, you would get a fairly uniform outer edge around your original text. Bear in mind that when shifting diagonally, you should use the same vector magnitude as when you shift horizontally or vertically, rather than simply offsetting by the same x and y values (which leads to a approximatlely 1.4x further length -- basic trig).

FYI

This sort of effect is known as dilation, and is sometimes performed via Minkowski Summation, which is the vector-based (continuous) approach to the pixel-based (quantised) box filter I described above.

来自:http://gamedev.stackexchange.com ... line-in-opengl-ftgl, 原作者Arcane Engineer

大意:
第一种方法:用GPU或者CPU把每个文字的Bitmap过一遍,脑残方法直接造。最准确
第二种方法:就是类似4方向错位,这次改成8方向。就是按照极坐标就是(1, 0) (1, pi/4) (1, pi/2) ...八方向一直画一遍。RM估计可以用
第三种方法:自己看吧,貌似要用我不懂的算法(Minkowski Summation)。

当然RM就弄不着了,用GPU的人可以看这篇论文http://www.valvesoftware.com/pub ... edMagnification.pdf

所以就是快速的给你找到了也许你想要看的....VA具体是啥我就不知道了(俺能力不足)
作者: 喵呜喵5    时间: 2015-8-28 18:18
rm阴影丑是因为rm里bitmap模糊速度太慢,中文三千字数量太多又不能像英文那样提前缓存……
作者: 冷峻逸    时间: 2015-8-30 12:05
提示: 作者被禁止或删除 内容自动屏蔽
作者: 精灵使者    时间: 2015-8-30 14:33
RMXP没有阴影字很难看。
精灵目前使用这个脚本。
原作 @SailCat 大大。
一直是RMXP核心脚本。
RUBY 代码复制
  1. #======================================================================
  2. # 脚本来自[url]www.66rpg.com[/url],使用请保留此信息
  3. # 作者:SailCat;升级:柳柳;最后升级日期:2006年4月30日
  4. #======================================================================
  5. class Bitmap
  6.   unless $OK
  7.     alias sailcat_draw_text draw_text unless method_defined?(:sailcat_draw_text)
  8.     def draw_text(p1, p2, p3 = 0, p4 = 3, p5 = nil, p6 = 0, p7 = 3, p8 = nil)
  9.       case p1
  10.       when Numeric
  11.         x = p1
  12.         y = p2
  13.         width = p3
  14.         height = p4
  15.         text = p5
  16.         align = p6
  17.         shadow_direction = p7
  18.         shadow_color = p8
  19.         if shadow_color.nil?
  20.           shadow_color = Color.new(0, 0, 0, self.font.color.alpha * 0.67)
  21.         end
  22.       when Rect
  23.         x = p1.x
  24.         y = p1.y
  25.         width = p1.width
  26.         height = p1.height
  27.         text = p2
  28.         align = p3
  29.         shadow_direction = p4
  30.         shadow_color = p5
  31.         if shadow_color.nil?
  32.           shadow_color = Color.new(0, 0, 0, self.font.color.alpha * 0.67)
  33.         end
  34.       end
  35.       color_temp = self.font.color.clone
  36.       if shadow_direction != 0
  37.         self.font.color = shadow_color
  38.         case shadow_direction
  39.         when 1
  40.           sailcat_draw_text(x-1, y+1, width, height, text, align)
  41.         when 3
  42.           sailcat_draw_text(x+1, y+1, width, height, text, align)
  43.         when 7
  44.           sailcat_draw_text(x-1, y-1, width, height, text, align)
  45.         when 9
  46.           sailcat_draw_text(x+1, y-1, width, height, text, align)
  47.         end
  48.         self.font.color = color_temp
  49.       end
  50.       $OK = true
  51.       sailcat_draw_text(x, y, width, height, text, align)
  52.     end
  53.   end
  54. end





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1