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

Project1

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

[讨论] 请问一般的阴影字用的都是什么算法?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
60
在线时间
705 小时
注册时间
2007-12-23
帖子
874
跳转到指定楼层
1
发表于 2015-8-28 17:02:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

还有RMVA的描边字,配合黑体真的很漂亮。这又是用什么算法得到的呢?不会是把原文字上下左右4个方向差一个像素的位置各draw_text一遍吧?我记得这样的实现会把字弄得很粗很难看呃。
买了正版RMMV的同学进来看一下,谢谢~
https://rpg.blue/thread-393237-1-1.html

Lv3.寻梦者

唯一的信徒

梦石
0
星屑
1665
在线时间
1357 小时
注册时间
2013-1-29
帖子
1637
2
发表于 2015-8-28 17:09:54 | 只看该作者
本帖最后由 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具体是啥我就不知道了(俺能力不足)

点评

我的模糊是用Ruby模拟的高斯模糊,特别慢。。至于GPU我是不会用的了。。。  发表于 2015-8-30 19:45
谢谢您的指点。。高斯模糊的效果差不多,但是好像会影响FPS(XP去掉FPS限制之后本来能到120FPS满的,加了模糊之后显示文字瞬间FPS会大幅下降)  发表于 2015-8-30 19:44

评分

参与人数 1星屑 +30 收起 理由
gonglinyuan + 30 塞糖

查看全部评分

『我只是一个正在潜心修炼的渣乐师罢了』
Dear Time\(^o^)/~


假如上面的图片挂了的话麻烦各位去发个帖 @ 一下 orzFly 让他修复 deartime
回复 支持 反对

使用道具 举报

Lv5.捕梦者 (暗夜天使)

只有笨蛋才会看到

梦石
1
星屑
20915
在线时间
9331 小时
注册时间
2012-6-19
帖子
7105

开拓者短篇九导演组冠军

3
发表于 2015-8-28 18:18:04 | 只看该作者
rm阴影丑是因为rm里bitmap模糊速度太慢,中文三千字数量太多又不能像英文那样提前缓存……

点评

RMXP的Bitmap没有模糊功能,只能用dll或者写Ruby代码模拟,前者还没试过,后者效率特别低。。  发表于 2015-8-30 19:46

评分

参与人数 1星屑 +10 收起 理由
gonglinyuan + 10 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止访问)

梦石
0
星屑
88
在线时间
631 小时
注册时间
2014-8-4
帖子
3600
4
发表于 2015-8-30 12:05:55 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

精灵族の天使

梦石
0
星屑
1697
在线时间
3038 小时
注册时间
2007-3-16
帖子
33731

开拓者贵宾

5
发表于 2015-8-30 14:33:45 | 只看该作者
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

点评

你不是在过烧烤节吗···  发表于 2015-8-31 00:27
你说呢……呵呵  发表于 2015-8-30 22:44
如果设置不好就毁了吗···  发表于 2015-8-30 21:44
这个脚本的优点就是利用好draw_text的后面的两个参数,可以改变阴影的颜色。如果设置好的话会大赞  发表于 2015-8-30 21:01
阴影的模糊可以改alpha*后面的那个0.67...  发表于 2015-8-30 20:57

评分

参与人数 1星屑 +20 收起 理由
gonglinyuan + 20 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-20 16:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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