Thursday, October 18, 2007
Reflection
请不要从图形学的角度去看这个词,而是从计算机科学的角度看,你知道Reflection吗?
之前我不知道,现在知道了。不知道的请参考http://en.wikipedia.org/wiki/Reflection_(computer_science)
Sunday, October 7, 2007
Pixar的电影制作工序
以下步骤完全摘自于Pixar的官方网站
There is a scene in Toy Story 2 when the old man repairing Woody tells the impatient toy collector Al, "You can't rush art." This is especially true at Pixar, where films go through four stages: development, creating the storyline; pre-production, addressing technical challenges; production, making the film; and post-production, "polishing" the final product.
1. A STORY IDEA IS PITCHED
A Pixar employee pitches his or her idea to other members of the development team in a way that's reminiscent of a sales pitch. The real challenge is to get the audience to believe in the idea and see the possibilities in it.
2. THE TEXT TREATMENT IS WRITTEN
A treatment is a short document that summarizes the main idea of the story. Sometimes, many treatments of the same idea will be developed in order to find the right balance between solid ideas and open possibilities, which will be filled in later by development and storyboard artists.
3. STORYBOARDS ARE DRAWN
Storyboards are like a hand-drawn comic book version of the movie and serve as the blueprint for the action and dislogue. Each storyboard artist receives script pages and/or a "beat outline," a map of the characters' emotional changes that need to be seen through actions. Using these as guidelines, the artists envision their assigned sequences, draw them out and then "pitch" their work to the director.
4. VOICE TALENT BEGINS RECORDING
First, temporary "scratch" voices are recorded by Pixar artists for the storyboard reels(see Step 5). Later, when the story and dialogue are further along, professional actors begin recording the character voices, reading from a script and improvising. Actors must record lines several different ways, and the best reading is eventually animated. Sometimes, scratch voices are so good, they're not replaced, such as Story Supervisor Joe Ranft's voice for Wheezy.
5. EDITORIAL BEGINS MAKING REELS
A reel is a videotape that allows the cleaned-up storyboard sequence to stand alone, without a pitch person to tell the story. A pitch can be successful because the storyteller is strong, so reels are an essential step to validate the sequence and are the first instance that the "timing" of the sequences is understood. Editorial uses the information to fix the length and other elements of each shot in a sequence.
6. THE ART DEPARTMENT CREATES THE LOOK AND FEEL
Based on the initial text treatment, storyboards and their own creative brain-storming and development work, the art department creates inspirational art illustrating the world and the characters. It also designs sets, props, visual looks for surfaces and colors and "color scripts" for lighting, which are impressionistic pastel illustrations that emphasize the light in scenes.
7. MODELS ARE SCULPTED AND ARTICULATED
Using the art department's model packet - a set of informational drawings - the characters, sets and props are either sculpted by hand and then scanned in three-dimensionally or modeled in 3-D directly in the computer. They are then given "avars," or hinges, which the animator will use to make the object or character move. Woody has 100 avars in his face alone.
8. THE SETS ARE DRESSED
After the sets are built in 3-D they must be dressed with prop models, such as chairs, curtains and toys, to create a believable world. Set dressers work closely with the director to ensure that the director's vision for the environment is being realized.
9. THE SHOTS ARE LAID OUT
Translating the story into three-dimensional scenes, the layout crew choreographs the characters in the set and uses a virtual camera to create the shots that capture the emotion and story point of each scene. Layout often produces multiple versions of shots to provide the editorial department with choices for cutting the scene for maximum storytelling effect. Once the scene has been cut, the final version is released to animation.
10. THE SHOT IS ANIMATED
Pixar's animators neither draw nor paint the shots, as is required in traditional animation. Because the character, models, layout, dialog and sound are already set up, animators are like actors or puppeteers. Using Pixar's animation software, they choreograph the movements and facial expressions in each scene. They do this by using computer controls and the character's avars to define key poses. The computer then creates the "inbetween" frames, which the animator adjusts as necessary.
11. SETS AND CHARACTERS ARE SHADED
The shader is separate from the surface to which it is attached. In other words, the shape is determined by the model, while the surface color and texture is determined by the shader. The shading process is done with "shaders," software programs that allow for complex variations in the color or color shaping. For example, this process allows the color to shift in different lighting like the relections on Woody's polished eyes.
12. LIGHTING COMPLETES THE LOOK
Using "digital light," every scene is lit in much the same mannar as stage lighting. Key, fill and bounce lights and room ambience are all defined and used to enhance the mood and emotion of each scene. Lighting takes its inspiration from the moody color scripts created by the art department.
13. THE COMPUTER DATA IS "RENDERED"
Rendering is the act of translating all of the information in the files that make up the shot - sets, colors, character movement, etc. - into a single frame of film. Pixar's Renderfarm is a huge computer system that interprets the data and incorporates motion blur. Each frame represents 1/24 of a second of screen time and takes about six houres to render, though some frames have taken as many as nitety hours.
14. FINAL TOUCHES ARE ADDED
Editorial oversees the completion and additon of the musical score and the other sound effects. Effect animation adds special effects. And the photoscience department records the digital frames to film or to a form appropriate for digital projection.
Monday, August 20, 2007
Shader/Material 系统
2006年做Splinter Cell Double Agent的时候,就觉得Unreal的material editor是个不错的工具,它使得美工可以制作特效,而很少需要程序的参与。今年的GDC上,Radical的Neall Verheyde题为"The Shader Design Tool: Radical's Collaborative Approach to Shader Development"的讲座,说的也是这样一个工具。其基本目的是
1、解耦程序和美工的工作,
2、美工可以独立完成材质特效的制作
3、缩短开发周期
4、一些材质feature可以重用
工具的基本解决方案来自于一篇题为"Shade Trees"的论文,作者是Lucasfilm的Robert L. Cook。其思想是将shader分割成模块,对模块进行组装,即可实现对一种材质特效的渲染。Cook当时并不是为了这个提出Shade trees的,用shade trees来做material editor,最早来自于Gregory D. Abram 和 Turner Whitted 的论文 "Building block shaders"。
2006年的一篇论文题为"Abstract Shade Trees",对上述论文进行了扩展。个人认为要实现系统,可以第三篇论文为基础。
值得注意的是,Radical的讲座中提到工具的开发大概需要一个人一年的时间。
Monday, August 13, 2007
网络资源集锦
1. http://www.vterrain.org/,Virtual Terrain Project,涉及到terrain的方方面面
2. http://kesen.huang.googlepages.com/,各种图形学学术活动相关文章的索引,棒
3. http://www.particlesystems.org/,免费粒子系统源码
Sunday, July 22, 2007
又看了一本书
除了技术书籍,正儿八经看的书越来越少了,技术书籍,在我看来,不应该算在看的书之列。
基辛格的《大时代》从很早就开始看了,至今也才看了一半,写的不错,看起来却累得慌。
《世界是平的》是作为洗手间书籍看完的,列举的事实感同身受,所以已无震撼力;讲出的道理有对有错,世界是平的只是从我们征服世界的手段来看的。人类总归是动物属,世界越平,强对弱的剥削就越厉害,亘古不变!
又看的这本书,是《流血的仕途 - 李斯和秦帝国》。流血的仕途,司空见惯,并不稀奇。如果书名是“不流血的仕途”,我会更感兴趣。好久没有这种对书籍爱不释手的感觉了,因此一气看完。故事讲的挺好,对事件的见解也有独到之处。作者曹三公子,让人不禁有时空错乱之感。
现在看书,对书中人物的好恶不再那么鲜明,好人坏人的界线开始模糊起来。不过有一点儿还没有改变:小人永远不可交!
Saturday, June 30, 2007
@ERR
这是什么?pseudo register!有什么用处?debug!
完整列表如下:
Pseudoregister | Description |
@ERR | Last error value; the same value returned by the GetLastError() API function |
@TIB | Thread information block for the current thread; necessary because the debugger doesn't handle the "FS:0" format |
@CLK | Undocumented clock register; usable only in the Watch window |
@EAX, @EBX, @ECX, @EDX, @ESI, @EDI, @EIP, @ESP, @EBP, @EFL | Intel CPU registers |
@CS, @DS, @ES, @SS, @FS, @GS | Intel CPU segment registers |
@ST0, @ST1, @ST2, @ST3, @ST4, @ST5, @ST6, @ST7 | Intel CPU floating-point registers |
详细描述请参考如下链接:http://www.codeproject.com/debug/pseudoregister.asp
Tuesday, June 12, 2007
Id Tech 5
这是什么?Id公司的下一代游戏引擎,名字比起他的前辈来,太普通了。但俗语有云:大智若愚,大音希声。John Carmark出品的东西,不得不让人关注。
该引擎的第一次面对公众,竟然是在Mac机器上,有想法。从介绍来看,Carmark的精英们在Terrain上下了不少工夫,研究了一些Texture的优化技术;其它的,还是期待游戏吧。
注: 这个texture的优化技术,应该是megatexture的扩展延伸。Id的editor向来不是很友好的说,因此我觉得介绍中关于创建关卡的神速,似有鼓吹之嫌。
Thursday, May 31, 2007
Saturday, May 19, 2007
Tootle
Tootle是Triangle Order Optimization Tool,ATI出品;它能够"provide significant performance improvements in pixel limited situations, with no penalty in vertex-limited scenarios, and no runtime cost."。
其基本思想就是
1、 先将mesh分片,对各片进行view-independent排序,使得early z-culling能发挥更大的效力,减少overdraw,提高pixel一级的效率;
2、针对各片基于locality进行重新排列,从而减少miss vertex cache的发生,提高vertex一级的效率。
这其中涉及到三篇文章,第一篇是"Triangle Order Optimization for Graphics Hardware Computation Culling",第二篇是解决如何将mesh分片的,题为"Multi-chart Geometry Images",第三篇解决对各片进行重新排列的问题,来自于Hoppe的"Optimization of Mesh locality for transparent vertex caching"。
诱人之处在于:由于Nvidia和ATI在硬件设计上都有考虑early z-culling问题,因此用这个工具优化过的模型,适用于目前所有主流游戏平台。
Friday, May 18, 2007
CryEngine2特性剖析 — Motion Blur & Depth of Field
CryEngine2的官方特性官方文档中的描述如下:
Motion Blur is used to simulate the visual effect of using a slow shutter speed when tracking fast moving objects or making quick camera movements. Blur can be applied both to individual objects( object based motion blur ), and/or to an entire scene (screen based motion blur), while Depth of Field can be used to focus the viewer's eye on a nearby object while subtly blurring objects in front or behind the point of focus.
这两个技术,实在没有太多好说道的。
关于基于物体的motion blur,可以参考Wloka和Zeleznik的文章"Interactive real-time motion blur";关于全屏幕的motion blur,要简单得多,只要你能想办法加噪声即可。
关于depth of field,有两篇不错的文章:"Real-time Depth of Field Simulation"和"Advanced Depth of Field"。两篇都来自于ATI。
这两个技术很容易集成到引擎,但并不是很重要。
Saturday, May 5, 2007
CryEngine2特性剖析 — Terrain 2.5D Ambient Occlusion Maps, Real Time Ambient Maps
CryEngine2官方文档中,对这两个技术的描述是:
Terrain 2.5D Ambient Occlusion Maps: On a per pixel level, approximates the amount of ambient(fill) light reaching an object(static or dynamic) depending on the amount of ambient occlusion created by the surrounding foliage and structures.
Real Time Ambient Maps: Pre-calculate the amount of ambient(fill) light which will be applied to indoor surfaces, to improve the quality of lighting when applying real-time per-pixel lighting and shadows. This means the current light position and color can be dynamically added to the fill light intensity applied to illuminate surfaces in interior spaces.
之所以把这两个技术放到一起说,是因为它们都是关于全局光照(Global Illumination)的。
该技术的鼻祖,应该是ILM的Hayden Landis在2002年SigGraph上题为"Production-Ready Global Illumination"的讲座。文中提到了Ambient Environment Maps和Ambient Occlusion Maps。概括来说,Ambient Environment Maps“均匀”照亮一个物体,Ambient Occlusion Maps基于Ray-Tracing对Ambient Environment Maps做Attenuation,产生soft shadow效果,在计算Ambient Occlusion Maps的过程中,同时计算出“Bent Normal”,该值将被用来调制Surface的Normal作为Ambient Environment Maps的坐标。
从CryEngine2的特性描述和Demo效果来看,应该就是这两个技术的结合,当然还要结合一些后来的改进。
与此类似,Peter-Pike Sloan在2002年的一篇文章"Precomputed Radiance Transfer for Real-Time Rendering in Dynamic, Low-Frequency Lighting Environments",基本思想如出一辙。这个文章读起来会有些累,个人建议可以看来自于SCEA的Robin Green题为"Spherical Harmonic Lighting: The Gritty Details"的文章,文中包括了技术和实现细节,超棒!再推荐一篇文章"Global Illumination Compendium",内容不多说,看了就知道。
前面提到的技术,基于Ray-Tracing,需要Pre-Computing。2005年的GPU Gems2中,Nvidia的Michael Bunnell的文章"Dynamic Ambient Occlusion and Indirect Lighting",提出了一种新的方法,舍弃了Ray-Tracing,从而可以实时计算Ambient Occlusion。
还有两篇文章,个人觉得值得关注,分别是"Approximate Ambient Occlusion For Trees"和"Real-Time Ambient Occlusion for Dynamic Character Skins"。树和人,值得用不同的技术。
应用了上面的技术,你的游戏在这些效果上也可以达到CryEngine2的水平了。
Friday, April 27, 2007
0x00000000
第一次自己写的程序遇到这个问题,程序运行中弹出窗口,内容如下:
The instruction at "0x00000000" referenced memory at "0x00000000". The memory could not be "read".
请注意The instruction at "0x00000000",经常遇到的情况应该是The instruction不在"0x00000000"的位置。而且点击cancel后,进入不了JIT debugger,无从debug。
我的第一反应是线程的问题,于是查找程序中与线程相关的代码,最后发现程序中使用了Process,在Process的OnExited事件的回调函数中,关闭当前的Process,从一个列表中取出下一个command,启动下一个Process。如此反复,直到列表为空。随机的,当启动一个新的Process时,偶尔会发生如上所述bug。
我没有想出何原因会导致这个问题,不过我有解决方案如下,先遍历列表中所有command,生成一个batch文件,然后启动一个Process,运行该batch文件。问题解决!!!
至于上述问题发生的原因,思考中……
Wednesday, April 18, 2007
Tuesday, March 20, 2007
CryEngine2特性剖析 — Volumetric, Layer and View Distance Fogging
CryEngine2的官方Features Document中的描述为:Create clouds or fog banks which can hug the ground and realistically reduce both visibility and contrast, and properly interact with both dynamic lights and shadows, add depth and dimension to a landscape by reducing scene contrast and clarity for distant landmarks.
本来想查找一些相关资料,没有想到却找到了CryTek关于此技术的一篇文档,惊喜!请看Advanced Real-Time Rendering in 3D Graphics and Games中的第六章(Chapter 6):Real-Time Atmospheric Effects in Games.
CryEngine2中Volumetric fog依赖于Scene depth based rendering,也就是Providing access to the depth of each pixel in the scene to be able to recover its original position in world space. 该技术使得post processing各种特效成为无限可能。缺点是难以处理无序透明物体,小左注意到2006年有一篇文章叫作Hardware Oriented Algorithms for Rendering Order-Independent Transparency,不知道能否解决这个问题。
关于从post perspective space到world space的换算,文中提出的算法很有意思:However there's often a simpler way, especially when implementing effects via full screen quads. Knowing the camera's four corner points at the far clipping plane in world space, a full screen quad is set up using the distance of each of these points from the camera position as input texture coordinates. During rasterization, this texture coordinate contains the current direction vector from the camera to the far clipping plane. Scaling this vector by the linear, normalized pixel depth and adding the camera position yields the pixel's position in world space. 看,即使你不想实现volumetric fog,这个方法也可以使你的其它post processing受益。
关于Volumetric Fog,文中详细列出了公式推导和HLSL代码,真棒。甚至如何处理透明物体,也有详细的说明,基本上就是在vertex上应用volumetric fog,然后blend into已经雾化处理过的frame buffer。
至于文中提到的Sky light渲染和Clouds渲染,都有比较详细的参考文章列举。这些特效,在xbox360,ps3和新一代pc上,都很容易实现。
Thursday, March 15, 2007
CryEngine2特性剖析 — 序
2007年GDC,CryEngine2无疑是亮点之一,在CryEngine2的官方Features Document中,列出的特性有;
- Real Time Lighting and Dynamic Soft Shadows;
- Volumetric, Layer and View Distance Fogging;
- Terrain 2.5D Ambient Occlusion Maps;
- Normal Maps and Parallax Occlusion Maps;
- Real Time Ambient Maps;
- Subsurface Scattering;
- Eye Adaptation & High Dynamic Range(HDR) Lighting;
- Light Beams & Shafts;
- Advanced Shader Technology;
- High Quality 3D Ocean Technology;
- Motion Blur & Depth of Field;
- Terrain LOD Management Feature;
- Polybump 2
- Integrated Multithreaded Physics Engine
- General Physics
- Advanced Rope Physics
- Interactive and Destructible Environments - Character Animation System
- Character Individualisation System
- Parametric Skeletal Animation
- Procedural Motion Warping
- High Quality Animation Compression - Integrated CryEngine Sandbox2 Editor
- Embedded Facial Animation Editor
- Integrated Vegetation and Terrain Cover Generation System
- Advanced Terrain System with Integrated Voxel Objects Technology
- Flow Graph
- Advanced Soft Particle System and Integrated FX Editor
- Dynamic Time of Day Settings
- Road and River Tools
- Vehicle Editor - Sound and Music
- Data-driven Sound System
- Interactive Dynamic Music System
- Dynamic World Sounds
- In Game Mixing
- Environmental Audio - Advanced AI System
- LUA Script Driven AI System
- Dynamic Path Finding
- Smart Objects - Performance Analysis
- Offline Rendering
- Modular C++ Design
- Multithreading Support
- Resource Compiler
- Streaming System
- Network Client and Server System
罗列的特性中很多不是CryEngine2特有的,抛开引擎架构不表,光这些特性就够人琢磨的了。小左打算利用业余时间对这些特性做一些资料搜集整理工作。至于能做到什么地步,先不管了。
此为该系列的序。
Thursday, March 8, 2007
索尼的家
GDC2007,索尼成“家”了。请看视频连接http://kotaku.com/gaming/clips/gdc07-clip-the-ps3s-home-242341.php。
是不是有些熟悉?有些像第二人生?正解!请看http://secondlife.com/。
索尼挺聪明的,Second Life也算是2.0系列的代表之一,自有大公司追捧,比如IBM。索尼将这一概念结合游戏推出,使得新一代的游戏机战争,扑朔迷离啊。
小左只有一个疑虑:目前的console游戏受众,跟Second Life的受众,会有很多交集吗?如果没有,他们会接受这个概念吗?
走着瞧吧!
Tuesday, March 6, 2007
如果你不觉得这个很酷
那么, 请你爬到比萨斜塔的顶端,闭上眼睛,然后自由落体;
如果你没有摔死,那么请重复以上行为。
这个很酷的东西叫做:perceptive pixel。视频以及文字介绍如下
视频:
http://link.brightcove.com/services/player/bcpid533361602?bctid=422563006
文字介绍:
http://www.fastcompany.com/magazine/112/open_features-canttouchthis.html
Saturday, February 17, 2007
我遭遇的nVidia和ATI driver的硬伤
nVidia和ATI无疑是优秀的,他们的芯片技术各展所长,各擅胜场。
我做Splinter Cell: Double Agent的图形优化的时候,遭遇了这两家各一个硬伤。有趣的是,两者都是Driver里的bug,而且表现也有几分相似。
先说nVidia的:场景中的某些位置,会突然“卡”(lag)一下;用NVPerfHUD“侦查”发现导致“卡”的瓶颈是pixel shader。而罪魁祸首,是nVidia显卡Driver中的一个小动作(据nVidia的专家说现在的Driver已经X掉这个bug了)。nVidia的专家说:vertex shader must be correctly setup in order to have the pixel shader not being re-optimized. This sounds weird but this is the way our driver works (for obscure reasons). 让我解释一下细节:在某些情况下,nVidia的driver可能会重新编译microcode来优化系统,因此即使你已经对所有能想到的事物做了cache,仍旧可能出现上述的“卡”的现象,因为driver在编译microcode。因此nVidia专家才会说你必须谨慎对待vertex shader的设置以便他们的driver不再做重新编译microcode来优化系统。那么你应该怎么处理vertex shader呢?专家如是说:To sum-up what can cause the Optimizer to recompile the microcode for optimization, here is a list of things that will trigger opmization if ever changed :
- whether fog is enabled or not- the exact fog mode (linear, exp, exp2)
- whether specular is enabled (tblend or TSS only)- whether sRGB writes are enabled
- the src/dst alpha blend modes (if alpha test and alpha blend are enabled)
- whether alpha test is enabled and the exact alpha test mode when using MRT
- whether you mix different formats when using MRT rendering
- whether the render target is floating point or not
- whether alpha is written (i.e, do we have an X8 buffer or an RGB-only writemask)
- whether RGB is written (is the writemask null or alpha-only?)
- whether projective textures are enabled (for TSS and PS <=1.3 only)
- whether a texture lookup references an FP32, FP16, or other format texture
- whether a texture lookup uses sRGB or not- whether a texture is 2D, 3D, or a cube map
- whether a texture is a shadow map or not
-whether a texture is any of several "special" formats (R32F, G16R16F, G32R32F, A16B16G16R16)- the 16 boolean constants
- the vertex shader
这会让人抓狂,按照我的经验,如果你妄图通过谨慎处理这些情况来避免Driver重新编译microcode,确实会让你抓狂!尤其当你的时间很紧,系统又很大。我的办法是:让pixel shader中的所有动态分支情况都运行一遍;换句话说,就是让程序模拟玩家在场景中跑上一遍。结论是:效果显著。
再说ATI的:场景的某些位置,转动camera,FPS会变得很低;停止转动,一段时间后FPS会突然跳高,恢复到正常水平。很显然,这不是cache的问题,极可能是Driver又做了不欲为人知的事情。
先描述我的经历:
那个时候ATI还没有类似nVidia的NVPerfHUD的工具。我用土方法,将问题定位到了pixel shader,是Global Illumination导致的问题。具体来说就是,我们使用了RGBe格式来做GI Light Map,然后运行时在pixel shader中做解压的工作。ATI的朋友曾经很肯定地跟我说:“我们的显卡运算能力比Nvidia要强,所以建议你们少用texture,多用计算。”那么为什么nVidia行,ATI却不行呢?那个解压缩的程序,并不复杂啊?这还不是最绝的,绝的是我们解决这个问题的方法:将pixel shader中调用的函数中的某条语句移出到函数外面。我能想到的是这种方法改变了编译器编译出的代码,因此性能表现上不同也就不足为奇了。可比较改动前后assembly代码发现并没有什么不同。还有更绝的,将那个被调用到的函数中的一个static flow control去掉,竟然会导致问题的再次出现。
因此我有理由做出猜测:ATI pixel shader的计算能力,是毋庸置疑的。我们所遇到的问题,并不是计算能力不行,因为问题解决前后所得到的assembly是相同的。因此问题的症结应该是Driver试图做的某些优化,反而使得芯片性能下降。辩证法啊!!!
后记:我在ATI的朋友后来证明了我的猜测,他们已经修掉了这个bug。
Friday, February 9, 2007
关于Shadow Map
Shadow Map技术最早由Lance Williams于1978在一篇题为"Casting Curved Shadow on Curved Surfaces"的论文中提出,其基本思想是(摘录):
反锯齿第一役,PCF(Percentage Closer Filtering),来自于Pixar的William T. Reeves, David H. Salesin 和 Robert L. Cook的一篇名为"Rendering Antialiased Shadows with Depth Maps"的论文。既然不能对Shadow Map做Filtering,那么就对比较结果做Filtering是PCF的精髓所在(摘录):
Our solution reverses the order of the filtering and comparison steps. The z values of the depth map across the entire region are first compared against the depth of the surface being rendered. This sample transformation converts the depth map under the region into a binary image, which is then filtered to give the proportion of the region in shadow. The resulting shadows have soft, antialiased edges.
值得一提的是,PCF可以产生soft shadow,虽然并不是真实的soft shadow,因为它与surface和光源的距离无关。
反锯齿第二役,Perspective Shadow Maps,来自于Marc Stamminger和George Drettakis。该方法的创新之处在于Shadow Map在normalized device coordinate空间生成,如此就:providing high resolution for near objects, and decreased resolution as we move away from the viewpoint.
反锯齿第三役,Variance Shadow Maps,来自于William Donnelly和Andrew Lauritzen。
- A view of the scene is constructed from the point of view of the light source. Only the Z values and not the shading values need be computed and stored.
- A view of the scene is then constructed from the point of view of the observer's eye. A linear transformation exists which maps X, Y, Z points in the observer's view into X, Y, Z coordinates in the light source view. As each point is generated in the observer's view, it is transformed into the computed view in the light source before computing its shading value. If the point is not visible to the light source, it is in shadow and is shaded accordingly.
反锯齿第一役,PCF(Percentage Closer Filtering),来自于Pixar的William T. Reeves, David H. Salesin 和 Robert L. Cook的一篇名为"Rendering Antialiased Shadows with Depth Maps"的论文。既然不能对Shadow Map做Filtering,那么就对比较结果做Filtering是PCF的精髓所在(摘录):
Our solution reverses the order of the filtering and comparison steps. The z values of the depth map across the entire region are first compared against the depth of the surface being rendered. This sample transformation converts the depth map under the region into a binary image, which is then filtered to give the proportion of the region in shadow. The resulting shadows have soft, antialiased edges.
值得一提的是,PCF可以产生soft shadow,虽然并不是真实的soft shadow,因为它与surface和光源的距离无关。
反锯齿第二役,Perspective Shadow Maps,来自于Marc Stamminger和George Drettakis。该方法的创新之处在于Shadow Map在normalized device coordinate空间生成,如此就:providing high resolution for near objects, and decreased resolution as we move away from the viewpoint.
反锯齿第三役,Variance Shadow Maps,来自于William Donnelly和Andrew Lauritzen。
VSM的实现相当简单,虽然它的原理涉及到一些统计学的东西,其思路是(摘录):
Instead of storing a single depth value, we store the mean and mean squared of a distribution of depths, from which we can efficiently compute the variance over any filter region. Using the variance, we derive an upper bound on the fraction of a shaded fragment that is occlueded. We show that this bound often provedes a good approximation to the true occlusion, and can be used as an approximate value for rendering.
另外文中提到的Mipmapping和Gaussian blur技术,是anti-aliasing和soften shadow很有效的手段,并且mipmapping对提高效率也有很大帮助。目前的shader可以很容易将上述技术与Variance Shadow Map很好的结合,产生更加逼真的shadow。
在Xbox360的XDK的samples中,有很好的Mipmapping和Variance Shadow Map的例子。
关于Shadow Map,还有很多相关技术;这里主要是针对游戏行业进行的选择。
Tuesday, February 6, 2007
呼应
求反平方根(reciprocal square root)的快速实用算法
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}
欲知算法详情,请看这里,希望你有耐性看完整篇推导。
{
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}
欲知算法详情,请看这里,希望你有耐性看完整篇推导。
Monday, February 5, 2007
关于Continuous Integration
推荐一篇Continuous Integration的文章,作者是Martin Fowler,请看这里。
Martin 对Continuous Integration的定义如下:
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.
我们公司用CruiseControl.NET来做Continuous Integration,效果不错。关于CruiseControl.NET的配置和应用,请直接google。至于Continuous Integration是否适用于你的项目,请大声阅读Martin的定义直至领悟。
Martin 对Continuous Integration的定义如下:
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.
我们公司用CruiseControl.NET来做Continuous Integration,效果不错。关于CruiseControl.NET的配置和应用,请直接google。至于Continuous Integration是否适用于你的项目,请大声阅读Martin的定义直至领悟。
Friday, February 2, 2007
explicit关键字
不常见的一个关键字,今天看到感觉有些陌生,因此写下来增进印象。:)
以下文字摘自于msdn:
This keyword is a declaration specifier that can only be applied to in-class constructor declarations.
An explicit constructor cannot take part in implicit conversions.
It can only be used to explicitly construct an object.
Note:
explicit on a constructor with multiple arguments has no effect, since such constructors cannot take part in implicit conversions.
However, for the purpose of implicit conversion, explicit will have an effect if a constructor has multiple arguments and all but one of the arguments has a default value.
以下文字摘自于msdn:
This keyword is a declaration specifier that can only be applied to in-class constructor declarations.
An explicit constructor cannot take part in implicit conversions.
It can only be used to explicitly construct an object.
Note:
explicit on a constructor with multiple arguments has no effect, since such constructors cannot take part in implicit conversions.
However, for the purpose of implicit conversion, explicit will have an effect if a constructor has multiple arguments and all but one of the arguments has a default value.
关于 (This+1)
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
inline void * operator new(size_t iSize, void *pMem) { return pMem; }
class ThisPlusOne
{
public:
ThisPlusOne();
~ThisPlusOne();
static ThisPlusOne* Create();
public:
const static int ArraySize;
int* ArrayVariable;
int MemberVariable;
};
const int ThisPlusOne::ArraySize = 20;
ThisPlusOne::ThisPlusOne():MemberVariable(0){}
ThisPlusOne::~ThisPlusOne(){}
ThisPlusOne* ThisPlusOne::Create()
{
int iSize= sizeof(ThisPlusOne) + ArraySize*sizeof(int);
ThisPlusOne* pThis = (ThisPlusOne*)malloc(iSize);
pThis = new(pThis) ThisPlusOne;
pThis->ArrayVariable = (int*)(pThis+1);
return pThis;
}
以此类推,如果有多个ArrayVariable,可按相同思路进行设置。
#include <stdio.h>
#include <malloc.h>
inline void * operator new(size_t iSize, void *pMem) { return pMem; }
class ThisPlusOne
{
public:
ThisPlusOne();
~ThisPlusOne();
static ThisPlusOne* Create();
public:
const static int ArraySize;
int* ArrayVariable;
int MemberVariable;
};
const int ThisPlusOne::ArraySize = 20;
ThisPlusOne::ThisPlusOne():MemberVariable(0){}
ThisPlusOne::~ThisPlusOne(){}
ThisPlusOne* ThisPlusOne::Create()
{
int iSize= sizeof(ThisPlusOne) + ArraySize*sizeof(int);
ThisPlusOne* pThis = (ThisPlusOne*)malloc(iSize);
pThis = new(pThis) ThisPlusOne;
pThis->ArrayVariable = (int*)(pThis+1);
return pThis;
}
以此类推,如果有多个ArrayVariable,可按相同思路进行设置。
Subscribe to:
Posts (Atom)


