WCG MV

Saturday, March 17, 2007

HLSL Tips 1: Pseudo-random Number Generator

Preface
PRNG on the GPU. Two pseudo random numbers per iteration (from the BA channels). Inspired by Pete Warden's fragment program for pseudo-random number generation. In turn based on an algorithm described by Francois Grieu, sci.crypt, 5th February 2004. Implementd in Cg by Alex Campbell. 7th August 2006. Thanks for their works. I implement it in HLSL now.
Function
#define cMult 0.0001002707309736288
#define aSubtract 0.2727272727272727
float4 randGrieu(float4 t)
{
float a=t.x+t.z*cMult+aSubtract-floor(t.x);
a*=a;
float b=t.y+a;
b-=floor(b);
float c=t.z+b;
c-=floor(c);
float d=c;
a+=c*cMult+aSubtract-floor(a);
a*=a;
b+=a;
b-=floor(b);
c+=b;
c-=floor(c);
return float4(a,b,c,d);
}
Application
Code snippet:
float4 color=tex2D(TextureSampler, In.TexCoord0);
color=randGrieu(color);
Out.color=color;

The original texture is as follows:


After called randGrieu() once, the result texture is:

Friday, March 16, 2007

A Nursery Rhyme

When I was very young, I often played together with accompaniers in my village. Those days we didn't have TV, computer, PS2, XBox, Wii, etc, but we didn't feel even less happy than nowadays. We also played many amused games.

Some days ago, my colleague sent an article in Sina Games to me through POPO, and its title is "The Memorable Games Played by Children in 1970s and 1980s". I felt going back to the childhood while reading. Especially, the game named "Ding Lao Tou" aroused me. I remembered my hometown's version immediately.

Now, I post it out in order to commemorate my elapsed childhood. The game is a nursery rhyme. while we are singing it, we draw the figure at the same time. When we finish singing, we finish the figure, too. The figure is a man, named "Ding Lao Tou". Lol!

The nursery rhyme is as follows:


One worker
Borrowed two eggs from me
He didn't give back after three days
He didn't give back after four days
Then I shut him in the house
Then I locked him in the house
He didn't give back after eight days
He gave back after eleven days


The figure corresponding the nursery rhyme is as follows:

Saturday, March 03, 2007

SM's D3D Tutorial 2: Create Texture with User-defined Image Data

Usually we use D3DXCreateTextureFromFile() function to create a texture from external file, but how do we create it with user-defined image data? The way is as follows:
1. Create an empty texture:
LPDIRECT3DTEXTURE9 pTexture = NULL;
LPDIRECT3DSURFACE9 pRenderSurface = NULL;

D3DXCreateTexture(pDevice,
256, // width
256, // height
0, // number of mip levels(0 - a complete mipmap chain is created)
0, // usage
D3DFMT_A8R8G8B8, // format
D3DPOOL_MANAGED, // pool(cannot be D3DPOOL_DEFAULT here)
&pTexture);
2. Retrieve this texture surface level:
pTexture->GetSurfaceLevel(0, &pRenderSurface);
D3DSURFACE_DESC surfaceDesc;
pRenderSurface->GetDesc(&surfaceDesc);
3. Lock a rectangle on the surface:
D3DLOCKED_RECT lockedRect;
pRenderSurface->LockRect(&lockedRect, 0, 0); // entire surface

NOTE: This method cannot retrieve data from a surface that is is contained by a texture resource created with D3DUSAGE_RENDERTARGET because such a texture must be assigned to D3DPOOL_DEFAULT memory and is therefore not lockable. In this case, use instead GetRenderTargetData to copy texture data from device memory to system memory.
4. Retrieve and modify the surface's data :
DWORD* imageData = (DWORD*)lockedRect.pBits;
for(int i = 0; i < surfaceDesc.Height; i++)
{
for(int j = 0; j < surfaceDesc.Width; j++)
{
int index = i * (lockedRect.Pitch / 4) + j; // because pitch is in bytes, and 4 bytes per DWORD
imageData[index] = 0xffffff00;
}
}
5. Unlock the rectangle:
pRenderSurface->UnlockRect();

Friday, March 02, 2007

SM's D3D Tutorial 1: Render-To-Texture

Rendering to a texture is one of the advanced techniques in Direct3D. On the one hand it is simple, on the other hand it is powerful and enables numerous special effects, such as glow effect, environment mapping, shadow mapping, and many more. Rendering to a texture is simply an extension to rendering to a surface.
1. Create the texture:
LPDIRECT3DTEXTURE9 pRenderTexture = NULL;
LPDIRECT3DSURFACE9 pRenderSurface = NULL, pBackBuffer = NULL;

pDevice()->CreateTexture(256, // width
256, // height
1, // number of mip levels
D3DUSAGE_RENDERTARGET, // must be!
D3DFMT_R8G8B8, // format
D3DPOOL_DEFAULT, // memory pool(must be!)
&pRenderTexture,
NULL);
2. Get the surface:
In order to access the texture memory a surface object is needed, because a texture object in Direct3D always uses such a surface to store its data.

pRenderTexture->GetSurfaceLevel(0,&pRenderSurface); // top-level surface
3. Render to the texture:
pDevice()->GetRenderTarget(0,&pBackBuffer); // back buffer

// render-to-texture
// set new render target
pDevice()->SetRenderTarget(0,pRenderSurface);
//clear texture
pDevice()->Clear(0,
NULL,
D3DCLEAR_TARGET D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(255,255,255),
1.0f,
0);
// render the scene
pDevice()->BeginScene();
...
pDevice()->EndScene();
4. Render the final scene using the texture:
// render scene with texture
// set back buffer
pDevice()->SetRenderTarget(0,pBackBuffer);
pDevice()->Clear(0,
NULL,
D3DCLEAR_TARGET D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0,0,0),
1.0f,
0);
pDevice()->BeginScene();
// set rendered texture
pDevice()->SetTexture(0,pRenderTexture);
// render the final scene
...
pDevice()->EndScene();
pDevice()->Present(NULL,NULL,NULL,NULL);

Lastly, there are some restrictions you have to take care of: (1) the depth stencil surface must always be greater or equal to the size of the render target; (2) the format of the render target and the depth stencil surface must be compatible and the multisample type must be the same.

Introduction to the Hardware Graphics Pipeline

Cyril Zeller, NVIDIA









Critical Reception: Capcom's/Clover Studio's Okami (From Gamasutra)



This week's edition of the regular Critical Reception column examines online reaction to the Capcom-published, Clover Studio-developed Okami for the PlayStation 2, a unique action/adventure title featuring a wolf as its protagonist.

In Okami, players assume the role of the sun goddess Amaterasu, newly reincarnated in the form of a white wolf. With the help of a nature-restoring "celestial brush," Amaterasu must revitalize Japan's landscape, which is in a state of ruin following years of demonic influence.

Stateside hopes are high for Okami, as the Japanese game review magazine Famitsu awarded the title a near-perfect score of 39 out of 40, following its release in Japan in April of this year. The game's distinct Eastern influence has some concerned that Okami will not have as great an impact in other parts of the world, however. Will American gamers be as impressed with Okami as Japanese players were?

Okami's current review score average of 93% at GameRankings.com indicates that this may in fact be the case.

GameSpy's Bryn Williams is as impressed by Okami's watercolor-like graphical style as he is by its gameplay. "This is more than likely the best game released for the PS2 this year," says Williams, "and certainly one of the most visually stunning games of all time."

Awarding Okami a perfect score of five stars, Williams cites the celestial brush mechanic as being a particularly brilliant innovation, claiming that, "It adds a whole new dimension to the 3D action-adventure genre."

Few complaints can be found in Williams' review. "Okami is currently my top pick for best game of 2006," concludes Williams -- a bold statement, considering that Okami's debut comes so late in the year, after nine solid months of video game releases.

Chris Roper of IGN is similarly fond of Okami, scoring it at 9.1 out of 10, but warning that the title does have its flaws. "It isn't perfect by any means," admits Roper, "but what it does right it does extremely well.

"Okami's epic scope and large game world are occasional detriments, according to Roper. He elaborates: "One problem that we do have with the main mission structure is that it can sometimes be difficult to figure out exactly where you need to be or who you need to talk to in order to continue."

In the end, however, the claimed simplicity of Okami's combat and the slow pace of its first few hours fail to affect Roper's enjoyment of the title. "Okami is a game we've been waiting on for a long, long time, and for the most part it has lived up to our extremely high expectations," says Roper. "It's beautiful, charismatic, engaging and one of the most original games you'll play anytime soon."

Brett Elston of Games Radar agrees with much of Roper's positive assessment in his 9-out-of-10 review. Elston summarizes: "Absolutely everything about this adventure is top of the line, blending the very best puzzle aspects of Zelda with a visual style that no other title can match."

Elston also echoes much of the same criticism present in IGN's review, with particular complaints leveled at Okami's limited combat and sometimes confusing objectives. Despite this, however, Elston emphasizes that, "You'll never once discover some glaring flaw that yanks you out of the mood."

"If you consider yourself a gamer in any way," Elston concludes, "buy this right now. You will not be disappointed."

All three reviewers also make special mention of Okami's localization, which they claim is witty, charming, and full of personality. This, perhaps, could prove to be the most important factor in determining Okami's success in America. Gamers previously feared that Okami could have been an impenetrably Japanese experience, with much of its cultural significance lost on Western audiences. So far, however, Okami's overwhelmingly positive reviews indicate that these fears should be put to rest.
- Danny Cowan -

Planet GameCube Editorial:Cel-Shading: Why all the Fuss?

From: Planet GameCube Worldwide Nintendo Coverage 24-7-365

Some love it. Some hate it. Why should you care? Read on to find out!
It's been about six months since Miyamoto-san unveiled the infamous new look that would grace The Legend of Zelda. Some loved it, some reviled it and some sat upon the fence. The situation remains much the same today, though now both polarized parties are deeply entrenched within their opinions. However, this editorial has little to do with the notorious change in Zelda, so you haters can put away the nasty e-mail, at least for the moment. Instead, I'd rather talk about the reasons why I think cel-shading is an excellent opportunity to revitalize the gaming industry.
And it all comes down to one word: Style.
I'll admit it now: I'm not a fan of polygons. While I enjoy and love many 3D games, I have never truly liked the sight of polygonal characters. I remember first seeing screenshots and movies of Super Mario64 and thinking "I'm going to pay over 250$ for that?" Of course, when I actually played the game I was totally in awe of the variety of polished gameplay and fell in love with Mario's new adventure. However the same reasons for which I was underwhelmed by Mario's first foray into 3D still apply today. Those I'll get to in a moment.
Let's talk about sprites. Those little 2D caricatures that have been used in games since before there were even consoles. From PONG to the GBA, Sprites have been a mainstay of the gaming industry since its inception. A mere collection of coloured pixels, and yet they managed to convey emotions and atmosphere. I love sprites. They exude a charm, and truly express much more than people give credit. A good example of this is the characters in Grandia. The way Justin will fall flat on his face after being tripped, or how Feena flips her hair back when annoyed. There is life to these motions, something that I can't quite pinpoint. However, sprites must be painstakingly animated frame by frame to make its characters appear larger than life.
On the other hand we have 3D models. No matter how well animated or crafted, 3D models always appear mannequin like, mere dolls. Even with the most sophisticated computer rendering technology, the problems are still there. Look at the models from Biohazard. Perfect in every detail, and yet in gameplay they still look wrong somehow. The S.T.A.R.S. officers look as lifeless as the zombies they're trying to exterminate. Or how about Square's Final Fantasy movie? Both have superbly modeled characters, and yet they look fake, stilted and plastic-like. The animations may be smooth, the graphics flawless, but there's something missing from all that complexity: warmth, life and a soul.
And those are the inherent problems with both styles: Sprites have a warm, personal feeling to them, but they take much time to animate, and they aren't feasible in high quality 3D graphics. Meanwhile 3D models are easily manipulated by computers, yet they're lifeless and "cold."
Where am I taking this? To the technique that has bridged the gap between the two and combines the strengths of either technique: Cel-shading.
At the simplest level, cel-shading takes 3D models and flattens their textures, giving them a hand drawn look. This technique is quite processor intensive, requiring much more power than traditional rendering methods. The first game to use this technique effectively was the DreamCast's Jet Set Radio. Cel-shaded characters glided about in a normally rendered 3D world. What was most impressive wasn't the technical marvel that Sega's team pulled off (and it was quite a feat) but the incredible visual style. Each character looked remarkably like the original artwork, and they animated just as smoothly as you'd expect a 3D model to. The only flaw of course was that the DC did not have the horsepower required to cel-shade the entire game.
Let's look at Zelda again. It is probably one of the most graphically impressive games ever to be produced. Watch the expressions on the Moblin's faces. The way Link's fearful face brightens up into a grin as he gets an idea. The incredible amount of animation. It's like sprites brought to 3D, a full animated feature where you are in control. And of course, cel-shading isn't limited to the cartoony antics of Cel Damage or the whimsical nature of Zelda. Games such as Capcom's upcoming Auto Modellista and Sega's JSRF show that the technique is limited only to the amount of artistic styles there are. More and more games seem to be utilizing the technique too; House of the Dead 3 was surprisingly revealed sporting normal textures, along with cel-shaded elements and the new Robotech video game also has a cel-shaded look, matching its animated roots. Cel-shading is undeniably something we can expect to see more of in future video games.
In an age where games are no longer graphically chained to polygon counts or how many effects are on-screen, art direction becomes all that more important.
Cel-shading is just one of many tools to bring a gameworld to life. While it's not likely that cel-shading will ever become more popular than the realistic 3D look most developers are going for, it's encouraging to see some taking the risk and opting for the more compelling game worlds that cel-shading provides.
Certainly, it helps me sleep at night when I see a chibi Link running around causing trouble instead of being a mindless, lifeless-looking drone cutting a swath of destruction across Hyrule like some braindead zombie.
Pierre est le brun poisson! Sing to Pierre!
Zosha Arushan, Staff Writer

Wednesday, February 28, 2007

Tuesday, February 27, 2007

Graphical and Interactive Methods for Computer Games

Original article: http://www.gamesconference.org/digra2003/2003/index.php?Abstracts/Masuch

Maic Masuch
Otto-von-Guericke University of Magdeburg
Department of Simulation and Graphics
masuch@isg.cs.uni-magdeburg.de

Graphical and Interactive Methods for Computer Games
Game Graphics Beyond Realism: Then, Now and Tomorrow

What makes a game interesting and fun to play? This is probably one of the most difficult questions to answer in the field of game development. From the gamers' point of view great graphics does not necessarily comes along with a great gaming experience. The time when astonishing graphics alone could sell a game is probably over. Due to constantly evolving graphics hardware, new visual effects are possible which more and more increase visual realism and immersion. Most games try to simulate the visual impression of reality as closely as possible. But this realism stretches only to a certain degree. In games we want to see heroes with superior abilities and hence, we are able to bend the laws of physics to fit the needs of the story. Why not also break the laws of graphical realism in order to enhance the visual experience? This paper encourages the use of alternative, more artistic rendering styles, such as non-photorealistic rendering. Some games already make use of a cartoon style rendering, but so far no other non-photorealistic rendering techniques have been adopted. These methods can be used for artistic purposes to capture the style of other media (e.g. comics), and to assist in storytelling by changing the style used throughout the game (e.g. to evoke emotions or establish moods). Thus these techniques carry the potential to move the design focus from pure graphics to game design and fun while playing.

The paper is outlined as follows: First it surveys the broad variety of graphical styles used in games and presents an overview of different visual perspectives. Modern games have departed from their primitive graphical roots and much too often, players notice that the game developer had put more emphasis on neat rendering techniques than on innovative game ideas. This will be shown by a historical comparison of the relation between gameplay and game graphics. Strictly speaking, no game developed so far can truly be called "photorealistic", but many games try to achieve "photorealism". Then we discuss the use of visual realism introducing the use of non-photorealistic graphics and its existing techniques applied in games. The paper concludes with a discussion of possible graphical styles in future games.

About the Author:
Maic Masuch, (*1966) PhD in computer animation, graduated at University of Magdeburg, Germany. There, he holds Germany's first professor for computer games at the faculty of computer science. He has been teaching computer game programming for five years (Lectures on real-time graphics, design, programming and development of computer games). Research focus lies on innovative UI and graphics for games, especially non-photorealistic rendering techniques. He is working as a game consultant for game development companies and supervised a number of game-related student projects. In addition, Prof. Masuch is co-founder of Impara, a spin-off-edutainment-company that currently is developing its first gaming title.

Wednesday, February 14, 2007

What Is Artistic Rendering (From Answers.com)

Rendering in visual art and technical drawing means the process of shading and texturing of an image, especially a realistic one. It can also be used to describe the quality of execution of that process.

The emphasis of the term is on the correct reproduction of light-and-shadow and the surface properties of the depicted objects, not on the emotional impact, composition, or other more generic qualities. Unsurprisingly, most often it is used in relation to the more exacting, meticulous techniques like pencil or airbrush.

In an artistic rendering visual information is interpreted by the artist and displayed accordingly using the chosen medium. The non-photorealistic rendering area of computer graphics develops tools and techniques to enable interpretive rendering in digital media.