Sunday, June 5, 2011

Cg Shader Tutorial For Emulators

copyright Hans-Kristian "Themaister" Arntzen
04.06.2011 (reposted with permission)

Introduction

This document is for a (fresh) shader developer that wants to develop shader programs for use in various emulators. Shader programs run on your GPU, and thus enables very sophisticated effects to be performed on the picture which might not be possible in real-time on the CPU. Some introduction to shader programming in general is given, so more experienced developers that only need reference for the specification may just skip ahead.

Current emulators that supports the specification explained here to a certain degree are:
– SSNES
– Various PlayStation 3 emulators (SNES9x, Genesis GX, FCEU, VBA)
– SNES9x Win32

There are three popular shader languages in use today:
– HLSL (High-Level Shading Language, Direct3D)
– GLSL (GL Shading Language, OpenGL)
– Cg (HLSL/GLSL, nVidia)

The spec is for the Cg shading language developed by nVidia. It «wraps» around OpenGL and HLSL to make shaders written in Cg quite portable. It is also the shading language implemented on the PlayStation 3, thus increasing the popularity of it. The specification itself can be found here:

The Rendering Pipeline

With shaders you are able to take control over a large chunk of the GPUs inner workings by writing your own programs that are uploaded and run on the GPU. In the old days, GPUs were a big black box that was highly configurable using endless amount of API calls. In more modern times, rather than giving you endless amounts of buttons, you are expected to implement the few «buttons» you actually need, and have a streamlined API.

The rendering pipeline is somewhat complex, but we can in general simplify it to:
– Vertex processing
– Rasterization
– Fragment processing
– Framebuffer blend

We are allowed to take control of what happens during vertex processing, and fragment processing.

A Cg Program

If you were to process an image on a CPU, you would most likely do something like this:
for (unsigned y = 0; y < height; y++) {
for (unsigned x = 0; x < width; x++) {
out_pixel[y][x] = process_pixel(in_pixel[y][x], y, x);
}
}
We quickly realize that this is highly serial and slow. We see that out_pixel[y][x] isn't dependent on out_pixel[y + k][x + k], so we see that we can parallelize quite a bit.

Essentially, we only need to implement process_pixel() as a single function, which is called thousands, even millions of time every frame. The only purpose in life for process_pixel() is to process an input, and produce an output. No state is needed, thus, a «pure» function in CS terms.

For the Cg program, we need to implement two different functions.

main_vertex() takes care of transforming every incoming vertex from camera space down to clip space. This essentially means projection of 3D (coordinates on GPU) down to 2D (your screen). Since we're dealing with old school emulators here, which are already 2D, the vertex shading is very trivial.

Vertex shaders get various coordinates as input, and uniforms. Every vertex emitted by the emulator is run through main_vertex which calculates the final output position. For our emulators this is just 4 times, since we're rendering a quad on the screen :D 3D games would obviously have a lot more vertices.

While coordinates differ for each invocation, uniforms are constant throughout every call. Think of it as a global variable that you're not allowed to change.

Vertex shading can almost be ignored altogether, but since the vertex shader is run only 4 times, and the fragment shader is run millions of times per frame, it is a good idea to precalculate values in vertex shader that can later be used in fragment shader. There are some limitations to this which will be mentioned later.

main_fragment() takes care of calculating a pixel color for every single output pixel on the screen. If you're playing at 1080p, the fragment shader will have to be run 1920 * 1080 times! This is obviously straining on the GPU unless the shader is written efficiently.

Obviously, main_fragment is where the real action happens. For many shaders we can stick with a «dummy» vertex shader which does some very simple stuff.

The fragment shader receives a handle to a texture (the game frame itself), and the texture coordinate for the current pixel, and a bunch of uniforms.

A fragment shaders final output is a color, simple as that. Processing ends here.

Hello World!

We'll start off with the basic vertex shader. No fancy things are being done. You'll see a similiar vertex shader in most of the Cg programs out there in the wild.
void main_vertex(
float4 pos : POSITION,
out float4 out_pos : POSITION,

uniform float4x4 modelViewProj,

float4 color : COLOR,
out float4 out_color : COLOR,

float2 tex : TEXCOORD,
out float2 out_tex : TEXCOORD
)
{
out_pos = mul(modelViewProj, pos);
out_color = color;
out_tex = tex;
}
This looks vaguely familiar to C, and it is. Cg stands for «C for graphics» after all. We notice some things are happening, notable some new types.

float4 is a vector type. It contains 4 elements. It could be colors, positions, whatever. It's used for vector processing which the GPUs are extremely efficient at.

We see various semantics. The POSITION semantic means that the variable is tied to vertex coordinates. We see that we have an input POSITION, and an output (out) POSITION. We thus transform the input to the output with a matrix multiply with the current model-view projection. Since this matrix is the same for every vertex, it is a uniform. Remember that the variable names DO matter. modelViewProj has to be called exactly that, as the emulator will pass the MVP to this uniform. It is in the specification.

Since we have semantics for the POSITION, etc, we can call them whatever we want, as the Cg environment figures out what the variables mean.

The transformation happens here:
out_pos = mul(modelViewProj, pos);
The COLOR semantic isn't very interesting for us, but the example code in nVidias Cg documentation includes it, so we just follow along :)

TEXCOORD is the texture coordinate we get from the emulator, and generally we just pass it to the fragment shader directly. The coordinate will then be linearly interpolated across the fragments. More complex shaders can output (almost) as many variables they want, that will be linearly interpolated for free to the fragment shader.

We also need a fragment shader to go along with the vertex shader, and here's a basic shader that only outputs the pixel as-is. This is pretty much the result you'd get if you didn't run any shader (fixed-function) at all.

float4 main_fragment(uniform sampler2D s0 : TEXUNIT0, float2 tex : TEXCOORD) : COLOR
{
return tex2D(s0, tex);
}
This is arguably simpler than the vertex shader :D Important to notice are:

sampler2D is a handle to a texture in Cg. The semantic here is TEXUNIT0, which means that it refers to the texture in texture unit 0. This is also part of the specification.

float2 tex : TEXCOORD is the interpolated coordinate we received from the vertex shader.

tex2D(s0, tex); simply does texture lookup and returns a COLOR, which is emitted to the framebuffer. Simple enough. Practically every fragment does more than one texture lookup. For example, classic pixel shaders look at the neighbor pixels as well to determine the output. But where is the neighbor pixel? We'll revise the fragment shader and try to make a really blurry shader to demonstrate. We now need to pull up some uniforms. We need to know how to modify our tex coordinates so that it points to a neighbor pixel.
struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
};

float4 main_fragment(uniform sampler2D s0 : TEXUNIT0, uniform input IN, float2 tex :
TEXCOORD) : COLOR
{
float4 result = float4(0.0);
float dx = 1.0 / IN.texture_size.x;
float dy = 1.0 / IN.texture_size.y;

// Grab some of the neighboring pixels and blend together for a very mushy blur.
result += tex2D(s0, tex + float2(-dx, -dy));
result += tex2D(s0, tex + float2(dx, -dy));
result += tex2D(s0, tex + float2(0.0, 0.0));
result += tex2D(s0, tex + float2(-dx, 0.0));
return result / 4.0;
}
Here we use IN.texture_size to determine the the size of the texture. Since GL maps the whole texture to the interval [0.0, 1.0], 1.0 / IN.texture_size means we get the offset for a single pixel, simple enough. Almost every shader uses this. We can calculate these offsets in vertex shader to improve performance since the coordinates are linearly interpolated anyways, but that is for another time ... ;)

Putting It Together

The final runnable product is a single .cg file with the main_vertex and main_fragment functions added together. Not very complicated. For the icing on the cake, you should add a license header. It's just a comment ;)
/*
Stupid blur shader.
Author: Your friendly neighbor.
License: We don't have those things! :(
*/

struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
};

void main_vertex(
float4 pos : POSITION,
out float4 out_pos : POSITION,

uniform float4x4 modelViewProj,

float4 color : COLOR,
out float4 out_color : COLOR,

float2 tex : TEXCOORD,
out float2 out_tex : TEXCOORD
)
{
out_pos = mul(modelViewProj, pos);
out_color = color;
out_tex = tex;
}

float4 main_fragment(uniform sampler2D s0 : TEXUNIT0, uniform input IN, float2 tex :
TEXCOORD) : COLOR
{
float4 result = float4(0.0);
float dx = 1.0 / IN.texture_size.x;
float dy = 1.0 / IN.texture_size.y;

// Grab some of the neighboring pixels and blend together for a very mushy blur.
Result of the shader shown:
As you can see, it's not a practical shader, but it shows the blurring effect to the extreme :)

Expanding Further

It doesn't stop here. A single .cg shader like this is by far the most common way to distribute a shader, but it has some problems.

– There is no way to set the filtering used for the texture. Some filters require nearest filtering, some require linear, although nearest is by far the most common.
– No way to set custom output scale. We're forced to output to full viewport size, which hurts some filters like HQx and friends.
– No way to use multiple shaders. (multi-pass, FBO).
– No way to grab external lookup textures. (Borders, etc)

This has been solved in various ways for the different emulators. The way to do metadata like this varies for the Cg implementations. As of writing, SNES9x Win32 hasn't addressed this, but will hopefully in the near future.

SSNES and the PS3 emulators solve this with a config file.

Lookup textures

We'll first mention a very popular feature among the PS3 emulators, the ability to access external textures. This means we have several samplers available for use. In the config file, we define the textures as so:
textures = "foo;bar"
foo = path_foo.png # In SSNES this is relative, but PS3 emus are absolute path for now.
bar = bar_foo.png
foo_linear = true # Linear filtering for foo.
bar_linear = true # Linear filtering for bar.
PS3 emus use PNG as the main format, SSNES can use whatever if Imlib2 support is compiled in. If not, it's restricted to lop-left ordered, non-RLE TGA.

From here on, «foo» and «bar» can be found as uniforms in the shaders. The texture coordinates for the lookup texture will be found in TEXCOORD1. This can simply be passed along with TEXCOORD0 in the vertex shader as we did with TEXCOORD0. Here we make a fragment shader that blends in two background picture at a reduced opacity. Do NOT assign lookup textures to a certain TEXUNIT, Cg will assign a fitting texture unit to the sampler.
float4 main_fragment(uniform sampler2D s0 : TEXUNIT0,
uniform sampler2D foo, uniform sampler2D bar,
float2 tex : TEXCOORD0, float2 tex_lut : TEXCOORD1) : COLOR
{
float4 bg_sum = (tex2D(foo, tex_lut) + tex2D(bar, tex_lut)) * 0.15;
return lerp(tex2D(s0, tex), bg_sum, bg_sum.a); // Alpha blending. :D
}
In the PS3 emus there is a magic «bg» sampler that is assigned to the current border selected in the menu. It is not needed to define this in any config file.

Here's an example of what can be achieved using borders (which are just a simple lookup texture):

Multipass

It is sometimes feasible to process an effect in several steps. SSNES and PS3 emus differ here.
SSNES uses the same config file where you can do:
shaders = 2
shader0 = pass1.cg
shader1 = pass2.cg

scale_type0 = source
scale0 = 2.0
filter_linear0 = true
filter_linear1 = false
The PS3 emulators handle the same case in the menu generally. There is however a new config system on the way that will handle these kinds of configs.

Game-aware Shaders

This is a new and exiting feature. It allows shaders to grab data from the emulator state itself, such as RAM data. This is only implemented for SNES so far, but the idea is quite extendable and portable.

The basic idea is that we capture RAM data in a certain way (semantic if you will) from the SNES, and pass it as a uniform to the shader. The shader can thus act on game state in interesting ways.

As a tool to show this feature, we'll focus on replicating the simple tech demo shown on YouTube:

What happens is that when Mario jumps in the water, the screen gets a «watery» effect applied to it, with a rain lookup texture, and a wavy effect. When he jumps out of the water, the water effect slowly fades away.

We thus need to know two things:
– Is Mario currently in water or not?
– If not, how long time was it since he jumped out?

Since shaders do not have state associated with it, we have to let the environment provide the state we need in a certain way. We'll call this concept a semantic.

To capture a RAM value directly, we can use the «capture» semantic. To record the time when the RAM value last changed, we can use the «transition» semantic. We obviously also need to know where in RAM we can find this information. Luckily, the guys over at SMW Central know the answer:

We see:
$7E:0075, byte, Flag, Player is in water flag. #$00 = No; #$01 = Yes.

Bank $7E and $7F are mapped to WRAM $0000-$FFFF and $10000-$1FFFF respectively. Thus, our WRAM address is $0075.

In the config file, we can now set up the uniforms we'll want to be captured in the config file.
imports = "mario_water;mario_water_time"
mario_water_semantic = capture # Capture the RAM value as-is.
mario_water_wram = 0075 # This value is hex!
mario_water_time_semantic = transition # Capture the frame count when this variable last
changed. Use with IN.frame_count, to create a fade-out effect.
mario_water_time_wram = 0075
The amount of possible «semantics» are practically endless. It might be worthwhile to attempt some possibility to run custom code that keeps track of the shader uniforms in more sophisticated ways later on. Do note that there is also a %s_mask value which will let you bitmask the RAM value to check for bit-flags more easily.

Now that we got that part down, let's work on the shader design. In the fragment shader we simply render both the full water effect, and the «normal» texture, and let a «blend» variable decide. We can say that 1.0 is full water effect, 0.0 is no effect. We can start working on our vertex shader. We will do something useful here for once.
struct input
{
float frame_count; // We only need frame count. :D
};

void main_vertex(
float4 pos : POSITION,
out float4 out_pos : POSITION,
uniform float4x4 modelViewProj,
float4 color : COLOR,
out float4 out_color : COLOR,
float2 tex : TEXCOORD0,
out float2 out_tex : TEXCOORD0,
float2 tex1 : TEXCOORD1,
out float2 out_tex1 : TEXCOORD1,

uniform float mario_water, // Even if the data should have been int, Cg doesn't seem to
support integer uniforms :(
uniform float mario_water_time,
uniform input IN,
out float blend_factor // Blend factor is passed to fragment shader. We'll output the
same value in every vertex, so every fragment will get the same value for blend_factor
since there is nothing to interpolate.
)
{
out_pos = mul(modelViewProj, pos);
out_color = color;
out_tex = tex;
out_tex1 = tex1;
float transition_time = 0.5 * (IN.frame_count – mario_water_time) / 60.0;
if (mario_water > 0.0)
blend_factor = 1.0; // If Mario is in the water ($0075 != 0), it's always 1 ...
else
blend_factor = exp(-transition_time); // Fade out from 1.0 towards 0.0 as
transition_time grows larger.
}
All fine and dandy so far, now we just need to use this blend_factor in our fragment shader somehow ... Let's move on to the fragment shader where we blend :D
const float2 src0 = float2(0.6, 0.7);
const float2 src1 = float2(0.9, 0.9);
const float2 src2 = float2(-0.6, 0.3);
const float2 src3 = float2(0.1, 0.4);
const float2 src4 = float2(0.1, 0.4);
const float2 src5 = float2(0.5, 0.5);
const float2 src6 = float2(-1.0, 1.0);
float apply_wave(float2 pos, float2 src, float cnt)
{
float2 diff = pos - src;
float dist = 300.0 * sqrt(dot(diff, diff));
dist -= 0.15 * cnt;
return sin(dist);
}
// Fancy shizz to create a wave.
float4 water_texture(float4 output, float2 scale, float cnt)
{
float res = apply_wave(scale, src0, cnt);
res += apply_wave(scale, src1, cnt);
res += apply_wave(scale, src2, cnt);
res += apply_wave(scale, src3, cnt);
res += apply_wave(scale, src4, cnt);
res += apply_wave(scale, src5, cnt);
res += apply_wave(scale, src6, cnt);
return output * (0.95 + 0.012 * res);
}
float4 main_fragment
(
uniform input IN,
float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0,
uniform sampler2D rain, float2 tex1 : TEXCOORD1,
in float blend_factor // Passed from vertex
) : COLOR
{
float4 water_tex = water_texture(tex2D(s0, tex), tex1, IN.frame_count);
float4 normal_tex = tex2D(s0, tex);
float4 rain_tex = tex2D(rain, tex1);
// First, blend normal and water texture together,
// then add the rain texture with alpha blending on top :)
return lerp(lerp(normal_tex, water_tex, blend_factor), rain_tex, rain_tex.a *
blend_factor * 0.5);
}
The SNES9x-PS3 config file:
imports = "mario_water;mario_water_time"
mario_water_semantic = capture
mario_water_time_semantic = transition
mario_water_wram = 0075
mario_water_time_wram = 0075
textures = rain
rain = "/dev_hdd0/game/SNES90000/USRDIR/borders/Centered-1080p/overlays/none-overlay.png"
rain_linear = true
The shader itself could be added to this config, but it can also be used from the regular menus in case you want to test different approaches to the same RAM value.

SSNES config file:
shaders = 1
shader0 = mario.cg
filter_linear0 = true
imports = "mario_water;mario_water_time"
mario_water_semantic = capture
mario_water_time_semantic = transition
mario_water_wram = 0075
mario_water_time_wram = 0075
textures = rain
rain = rain.tga
rain_linear = true
As you can see, these formats are very similiar. The differences are mostly for historical reasons, and might become closer in the future.

How to test when developing for SNES9x-PS3?

To develop these kinds of shaders, I'd recommend using SSNES w/ Cg support, and bSNES as a SNES debugger to peek at RAM values (build it yourself with options=debugger). After written, the shader should translate nicely over to SNES9x-PS3 with some slight changes to the config.

Here are some screenshots of the mario effect we developed. Obviously this is a very simple example showing what this thing can do :) It's not confined to overlays. The imagination is the limit here.

Before water ...
In water :D

Tuesday, May 31, 2011

Heart-Shaped Eggless Strawberry Cheesecake قلوب تشيز كيك الفراولة بدون بيض أو جيلاتين

Heart-Shaped Eggless Strawberry Cheesecake قلوب تشيز كيك الفراولة بدون بيض أو جيلاتين

Scroll down for English post
اليوم سوف أريكم كيفية عمل تشيز كيك بسيطة جداً بدون خبز، من منا لا يحب التشيز كيك؟ خاصة بطعم الفراولة، سوف أقوم بعمل نوعين من التشيز كيك، إحداهما بطعم الفانيليا مغطاه بصوص الفراولة (سأريكم كيفية عمل أفضل صوص فراولة خاص بالتشيز كيك)، والنوع الآخر هو تشيز كيك بطعم الفراولة والذي أحبه كثيراً.

نصيحة الوصفة:
1- يمكنكم استبدال الكريمة الحامضة بنفس المقدار زبادي مصفى من الماء.
2- لعمل تشيز كيك بطعم الفراولة يمكن استخدام طعم الفراولة الجاهز كما بالوصفة أو استبداله ببعض من صوص الفراولة الذي سنقوم بتجهيزه.
3- يمكن استخدام صينية التشيز كيك الصغيرة بدلاً من استخدام القوالب.

الوصفة تكفي: 3 إلى 4 أشخاص (4 قوالب متوسطة إلى صغيرة)
وقت التحضير: 15 دقيقة

وقت التبريد: 30 إلى 60 دقيقة
 Today I'm going to show you how to make a simple delicious eggless no-bake cheesecake, who doesn't love it? specially strawberry cheesecake, I'm going to make two flavors, one with Vanilla topped with strawberry sauce (I'm going to show you how to make a perfect strawberry sauce for cheesecake), the other flavor is strawberry flavor which I love so much.

Recipe tip:
1- You can use 50g well drained yogurt as a substitute for 50 ml sour cream.
2- To make strawberry flavor you can use the strawberry sauce and mix with cheese instead of using strawberry flavor.
3- You can use a small cheesecake pan instead of the heart molds.

Serves: 3 to 4 people (4 medium to small molds)
Prep. time: 15 minutes
Chill time: 30 to 60 minutes
Click here for the recipe اضغط هنا للوصفة »

Saturday, May 28, 2011

Programs Won't Launch in Win7 64-bit

UPDATE (10/7/11): I never did find an actual solution for this problem. Every time I thought I had something, it would always come back. In the end, I had to reinstall the system. :/

So, I've been running into an issue on my Lenovo Thinkpad X120e when booted into Windows 7 where programs won't launch from the taskbar when I click on them. The little transparent box shows up around it, it sits for a second, then fades away.

I found, however, that I could run things from the command line, though that was not a good fix. After futzing around with the startup applications in msconfig, I found that it would start programs just fine if I turned off all of my startup items. This was also suboptimal, so I set to tracking down the culprit from the startup items by enabling them one-by-one and restarting each time.

UPDATE (6/5/11): Turns out my below "fix" may have just been coincidental, because my issue returned. It hung around through several reboots until I ran Windows Update and updated my video card driver, after which it went away again. Whether this fixes things permanently, we'll have to see.

I'll update this post if anything changes.

Original, ineffectual post:
Eventually, I found the problem to be related to the Sidebar application, which powers the CPU frequency and weather widgets I like to have sitting on my desktop. :(

I haven't had any problems since I turned it off.

Thursday, May 26, 2011

Vegetable Stuffed Roast Beef روزبيف / روست بيف محشي بالخضار

Vegetable Stuffed Roast Beef روزبيف / روست بيف محشي بالخضار

Scroll down for English post
مرحباً بكم جميعاً، وصفة اليوم هي وصفة كلاسيكية رائعة أحبها كثيراً، فكرة هذه الوصفة أتت لي عندما قمت بطبخ لحمة باردة في أحد الأيام، وقال زوجي أنه يفضل أن يكون الطعم أقوى من الداخل من مجرد ثوم وفلفل أسود وبعض التوابل الأخرى، لذا قررت أن أقوم بتقطيع قطعة اللحم هذه بشكل دائري بحيث أحافظ على نفس شكلها مع حشوها ببعض الخضروات، وحقاً كان اللحم لذيذ طري وصحي أيضاً. أتمنى أن تجربوا هذا الطبق وأن تخبروني إذا أعجبكم :)

نصيحة الوصفة:
1- من المهم استخدام أداة تنعيم اللحم والدق عليه بها أو بأي أداة مشابهة لأن ذلك يعمل على طبخ اللحم جيداً وجعل اللحم طري وسهل الأكل بعد الطبخ.
2- ورق الفويل يحافظ على شكل اللحم المطلوب ولكنه ليس صحياً لذا فضلت وضع كيس الفرن بينه وبين اللحم.
3- عند سلق أو طهي البازلاء والجزر على البخار توضع البازلاء أولاً لأنها تأخذ وقت أطول في الطهي.
4- يمكنكم اختيار الطبق الجانبي المفضل كالأرز، السلطة الخضراء أو بيوريه البطاطس.

الوصفة تكفــي: شخصين.
وقت التحضير: 15 دقيقة.
وقت الطهــــي: 40 دقيقة تقريباً
Hello everyone, today's recipe is a gourmet dish which I love so much, the idea of making it came to me when I made the roast beef once but my husband said that he would love to have something with more flavor inside more than garlic, black pepper and other spices, so I decided to cut the beef in a round cut to stuff it with vegetables, it was so yummy, tender, juicy, and healthy too. Hope you try it and tell me when you find it delicious :)

Recipe tips: 

1- It's important to use the beef tenderizer or anything like it to tender the meat so it's cooked perfectly and becomes tender after cooking in the oven.
2- The foil keeps the beef in shape but it's not healthy, that's why I used oven bag to put it between the meat and foil.
3- When boiling or steaming peas and carrots, add the peas first because it needs more cooking time.
4- The side dish is up to you, you can eat it with rice, salad or mashed potato.

Serves: 2 people.
Prep. time: 15 minutes.
Cooking time: 40 minutes approx.
Click here for the recipe اضغط هنا للوصفة »

Monday, May 16, 2011

Profiled, optimized libsnes builds for win32

I've been playing around with mingw, doing cross-compiles of libsnes with profile-guided optimizations (PGO) for use with SSNES in Windows and I think I've gotten it down pretty well.

I used the following C-flags at compile time:
-msse2 -fmerge-all-constants -fmodulo-sched -fgcse-sm -fgcse-las -funsafe-loop-optimizations -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -ftree-loop-linear -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvariable-expansion-in-unroller -ffast-math -fbranch-target-load-optimize -maccumulate-outgoing-args -combine
This means it's only going to work on CPUs that support the SSE2 SIMD instructions, but that includes pretty much every processor manufactured in the past 8 years, so I figured that was good enough.

If you want to give them a try, you can get them from my mediafire.

Sunday, May 15, 2011

More Emulator Pixel Shaders (CRT updated and more)

I'm just going to dive right in with the pictures in this post. If you want/need some backstory, read my previous CRT shader post. These shaders are all available in Screwtape's bsnes git repo, except for Beam4, which can be downloaded here, and NTSC, which can be downloaded here (both mirrored in my mediafire in case the pastebins expire before Screwtape adds them to his repo).

Update (01/11/12): bsnes support is back! Plus, the Win32 and GTK+ ports of snes9x support these shaders, as well. :D

UPDATE (9/20/11): Themaister has written an awesome little WebGL applet that enables shader testing and combining (up to 2 separate shaders) quickly and easily. Check it out! (requires browser with support for WebGL, such as newer versions of Google Chrome and Mozilla Firefox; only supports single-pass shaders at the time of this writing)

Here's a good picture to test with (320x240 resolution with point filtering, mimics raw SNES output):


UPDATE (5/30/11): Added shots of caligari's phosphor21x shader (a.k.a. caligari's scanlines in Screwtape's repo). UPDATE (6/3/11): Added Themaister's Dot 'n' Bloom, available from Screwtape's repo. UPDATE (6/18/11): Added caligari's scanlines - rgb triad. UPDATE (9/29/11): Added Themaister's phosphorish. UPDATE (11/22/11): Added edge detection and ALovelyBloom.

All images are taken at 3x scale, followed by that same image blown up 400% with no further interpolation. As always, click the thumbnails to embiggen.

4xBR

This one uses an algorithm similar to HQ4x and it shows.

ALovelyBloom

Unfortunately, this one's just a big flare-out on Super Mario World, but it looks pretty good on darker games, if you're into bloom. You can stack it with some other shaders to soften up phosphor effects and so on.

Beam4
This is a multipass scanline shader from cgwg that also simulates an electron beam that takes longer to rise than to fall. It is perfect for producing the pseudo-hires transparency used in Kirby's Dreamland 3 and Jurassic Park. Sadly, it only works in emulators that support shader spec 1.1 (at the time of this writing, Themaister's SSNES and PS3 homebrew emus written by Dante Ali).

Bicubic

This one's pretty straightforward, using an algorithm similar to that of bilinear filtering (aka, 'smooth video'). It's a little sharper and preserves edges a little better.

CRT.OpenGL

This is the latest and greatest version of the collaborative CRT shader. The screen curvature is user-definable, based on changing a single value in the helpfully commented shader code. As you can see, it looks totally amazing. It also runs a lot faster than it used to, so give it a shot even if your machine couldn't handle it before.

CRT-simple.OpenGL

This one is very closely related to the aforementioned CRT shader, only this one is optimized for weaker cards while only sacrificing a tiny bit of accuracy. If your machine can't run the full-fledged CRT shader, this one is your last good chance.

Dot 'n' Bloom

Another cool one from Themaister, Dot 'n' Bloom treats each pixel like a single, distinct dot and then adjusts its size based on brightness, such that brighter dots appear larger than darker ones, similar to a CRT electron beam (though this shader is not attempting to reproduce a CRT, it resembles one). He then added a bit of bloom to blend things together some. The results look really nice in motion (especially on Super Metroid :D) and the shader runs extremely fast.

Edge Detection

This one is more stylized than most of the others I've covered. As you might have guessed by the title, it finds the edges of colors and presents them as an outline. On SMW's cartoony, hard outlines, it makes a crazy quadruple outline.

Lanczos 4-tap

Another fairly straightforward interpolation filter, this one runs quite fast even on weaker hardware. You can learn more about the Lanczos algorithm and its use in resampling at the Wikipedia.

Lanczos 6-tap

As you might have guessed, this one is very similar to the 4-tap Lanczos, but it is further sharpened, which leads to the ringing/halo effect around sprites.

NTSC

This multipass shader is the result of cgwg and Themaister porting blargg's awesome NTSC filter to GLSL. It looks quite nice and doesn't bog down the CPU like the regular filter version. Unfortunately, it only works on shader spec 1.1-compatible emus.

Phosphor21x
This is caligari's implementation of an algorithm originally written by xythen in Matlab, which served as the inspiration for the work that later became CRT.OpenGL. This shader builds on xythen's work to be essentially scale factor-independent, except it looks a little weird at 2x in my experience; everything larger looks great. An interesting note: the scanlines that appear with this shader are not simply added in. Instead, they are naturally occurring as a result of the phosphor simulation. Pretty cool stuff :D

By uncommenting some lines in caligari's code, you can enable one of three phosphor/shadow mask arrangements, of which the RGB triad option is the nicest (I recommend clicking these thumbnails to see in full size):

As you can see, this option causes some serious dimming of the picture brightness, which was also a technological obstacle for actual CRT engineers when shadow masks were first being designed and implemented. In bsnes, you should be able to just increase the gamma in the picture settings to compensate. You can download this shader variation from my mediafire account.

Phosphorish












A simple, single-pass shader that makes a nice phosphor effect. This shader runs fast and works with both bsnes and SSNES. It is available here or in my mediafire.

Quilez

This fast, crisp interpolation filter is totally new to the emulation scene. It's based on some fancy math demonstrated by Inigo Quilez and represents a good compromise between the pixelate2x and bicubic shaders.

Simple TV Blur

This one's rather subtle, but is intended to do the minimum amount of work required to reproduce the pseudo-hires transparency.

Beam4+NTSC
Just for fun, I used SSNES' shader stacking support to combine the new NTSC shader with the Beam4 shader. It's almost indistinguishable from Beam4 alone (except for some really slight changes to the color palette), so I wouldn't bother trying it yourself.

CRT+NTSC

As above, I tried stacking the NTSC shader with the new CRT shader and this was the result. It's kinda cool in a way, like newsprint. :P According to cgwg, this is happening because it's only picking up the first pass of the NTSC shader, which has no color values.

CRT-Flat+Caligari's Scanlines - RGB Triad
When the regular CRT shader (edited to have 0.0 for the distortion value) is paired with caligari's scanlines - RGB triad variant, you end up with a pretty neat result:

The colors are off by a good bit (I think because of the double gamma correction) and it's very dark, but the phosphor triads from caligari's are still clearly discernible over the CRT shader's already-awesome result. Still not perfect, obviously, but getting close in a lot of ways.

Wednesday, May 4, 2011

Brazilian Chocolate bonbon: Brigadeiro كرات الشوكولاتة البرازيلية بريجاديرو

Brazilian Chocolate bonbon: Brigadeiro كرات الشوكولاتة البرازيلية بريجاديرو

Scroll down for English post
بريجاديرو هي حلوى بسيطة عبارة عن بونبون شوكولاتة وهي مشهورة جدا في البرازيل، في العادة يتم تقديمها في حفلات أعياد الميلاد، وحفلات الأطفال، وأي نوع من الحفلات عموماً، يتم عمل هذه الحلوى بخلط الحليب المركز المحلى مع الكاكاو والزبدة وتسخين الخليط جيداً إلى أن يثقل قوامه، ويتم تشكيله على شكل كرات صغيرة مغطاة بفرماسيلا الشوكولاتة (حبيبات صغيرة من الشوكولاتة)، يمكن أيضاً تقديم هذا الخليط دون تشكيله ويؤكل بالملعقة أو يمكن استخدامه كغطاء أو حشوة للكيك أو البراونيز أو أي نوع من الحلوى المخبوزة.

نصيحة الوصفة:
1- يجب ترك الخليط ليبرد جيداً في درجة حرارة الغرفة فالخليط وهو دافئ يكون شديد الالتصاق بالأيدي وطري جداً بحيث يصعب تشكيله بالشكل المطلوب.
2- يمكنكم استخدام الكاكاو المُحلى إذا لم يتوافر الخام لكن الطعم سيزيد حلاوة (سُكّر).

الوصفة تكفــي: حسب الحجم 20 كرة تقريباً
وقت التحضير: 2 دقيقة
وقت الطهــــي: 20 دقيقة
وقت التــــبريد: ساعة إلى ساعتين
Brigadeiro is a simple chocolate bonbon which is a very popular candy in Brazil, it is usually served at birthday parties, kids party and can also be found at any kind of party. This candy is made by mixing sweetened condensed milk, butter and cocoa powder together. The mixture is then heated in a pan on the stove or in a microwave oven to obtain a smooth, sticky texture. It usually rolled into balls which are covered in granulated chocolate. It can also be consumed unrolled, with a spoon or used as a topping or filling for cakes, brownies and other pastries.
Recipe Tips:
1- You have to let the chocolate mix cool very well at room temperature, because if it's warm it will be too mushy and sticky to shape in balls.
2- You could use sweetened cocoa powder but it would be more sweet and sugary.

Recipe serves: Depends on size, 20 balls approx.
Prep. time: 2 minutes
Cooking time: 20 minutes
Cooling time: 1 to 2 hours
Click here for the recipe اضغط هنا للوصفة »

Cari Farmasi

Farmasi Di Kuala Lumpur dan Selangor Selangor / KL Area NO SHOPS NAMES ...