Tag: rendering

Entries for tag "rendering", ordered from most recent. Entry count: 161.

Warning! Some information on this page is older than 5 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: > 1 2 3 4 5 ... 21 >

# Developing Graphics Driver

Thu
12
Jul 2012

Want to know what do I do at Intel? Obviously all details are secret, but generally, as a Graphics Software Engineer, I code graphics driver for our GPU. What does this software do? When you write a game these days, you usually use some game engine, but I'm sure you know that on a lower level, everything ends up as a bunch of textured 3D triangles rendered with hardware acceleration by the GPU. To render them, the engine uses one of standard graphics APIs. On Windows it can be DirectX or OpenGL, on Linux and Mac it is OpenGL, on mobile platforms it is OpenGL ES. On the other side, there are many hardware manufacturers - like NVIDIA, AMD, Intel or Imagination Technologies - that make discrete or embedded GPUs. These chips have different capabilities and instruction sets. So graphics driver is needed to translate calls to API (like IDirect3DDevice9::DrawIndexedPrimitive) and shader code to form specific to the hardware.

Want to know more? Intel recently published documentation of the GPU from the new Ivy Bridge processor - see this news. You can find this documentation on intellinuxgraphics.org website. It consists of more than 2000 pages in 17 PDF files. For example, in the last volume (Volume 4 Part 3) you can see how instructions of our programmable execution units look like. They are quite powerful :)

Comments | #intel #driver #rendering #hardware Share

# 4k Executable Graphics with Fractal

Fri
15
Jun 2012

There was a competition announced on forum.warsztat.gd in making a 4k executable graphics. In case you don't know what is it: It is a category well known on demoscene where you have to write a program - Windows executable in assembler, C, C++, Java, HTML or any other language, that fits into 4 KB size limit and generates a static, nice looking image. Obviously there is no way to store a bitmap inside such size, so the graphics must be generated procedurally. For list best prods in this category, see this search query on pouet.net.

I participated in this competition and here is my entry with source code: gfx_4k_Reg.zip. EXE file itself has 1259 bytes. Archive has password "demoscene" (needed because server of my hosting company rejects archives containing unusual EXE files like this, thinking it is a virus :)

Not very impressive, but keep in mind that I coded it in about 2-3 hours, with little previous experience in this kind of coding. If you are interested in how such program is made, I used:

Comments | #rendering #demoscene Share

# Direct2D Class Diagram

Sat
19
May 2012

I've made class diagram for Direct2D library. Enjoy :)

Direct2D Library Class Diagram

By the way, yEd is a free editor for all kinds of graphs, including UML diagrams like this. It may not allow you to enter list of fields and methods in classes like StarUML or Visio do. It may not allow to freely draw shapes like Inkscape or OpenOffice Draw do. But for creating, editing and arranging graphs of different kinds of nodes, interconnected with different kinds of links, it is really great. I especially like the way it snaps all positions and sizes to the neighbour nodes. Commands for automatic arranging of nodes, called Layout, also look impressive. Plus it supports different file formats, including XML-based, so you can easily generate such file and then open it in yEd to visualize some data.

Comments | #yed #graphs #rendering #direct2d Share

# Direct2D - Unboxing

Mon
07
May 2012

Just as some bloggers record unboxing of products, I'd like to share my first impressions from playing around with Direct2D library. What is it? As you can guess from its name, it is a library from Microsoft for efficient, hardware-accelerated drawing of immediate-mode 2D graphics. It is successor of the old GDI, as well as GDI+. It is native library, object-oriented, based on COM. It works on Windows 7, as well as Windows Vista (after installing SP2 and Platform Update) and Windows 2008. The API seems modern, clean and very elegant, much like Direct3D 10/11. But of course it could be just a matter of taste. You can find its documentation, as well as headers and libraries in DirectX SDK. Docs say something about Windows 7 SDK, so probably it's there too.

What can it interop with? You can create a render target that will send the graphics to either a window (using HWND), a GDI canvas (HDC), DXGI surface (interop with Direct3D 10/11) or WIC Bitmap. Interop with GDI is also possible in the opposite way - you can obtain a HDC from D2D render target. Microsoft advices using WIC (Windows Imaging Component) for loading bitmap files. Another important library that cooperates with Direct2D is DirectWrite, which enables text rendering.

I didn't find any good tutorial about Direct2D, but I haven't look for it very hard either. I think the official documentation is good enough teaching all aspects of the library. After reviewing the documentation, I'm very impressed not only by the looks of the API, but also by the list of features is supports, like:

Things I don't like so far about the library:

My first test, drawn using following code:

using namespace D2D1;
const D2D1_SIZE_F rtSize = m_RenderTarget->GetSize();
m_RenderTarget->BeginDraw();

m_RenderTarget->Clear(ColorF(ColorF::White));

m_Brush->SetColor(ColorF(ColorF::Silver));
const float gridStep = 24.f;
for(float x = gridStep; x < rtSize.width; x += gridStep)
    m_RenderTarget->DrawLine(Point2F(x, 0.f), Point2F(x, rtSize.height), m_Brush, 1.f);
for(float y = gridStep; y < rtSize.height; y += gridStep)
    m_RenderTarget->DrawLine(Point2F(0.f, y), Point2F(rtSize.width, y), m_Brush, 1.f);

m_Brush->SetColor(ColorF(ColorF::Navy));
m_RenderTarget->DrawRectangle(RectF(200.f, 400.f, 400.f, 550.f), m_Brush);
m_RenderTarget->DrawRectangle(RectF(240.f, 450.f, 280.f, 500.f), m_Brush);
m_RenderTarget->DrawRectangle(RectF(320.f, 450.f, 360.f, 550.f), m_Brush));
m_RenderTarget->DrawLine(Point2F(200.f, 400.f), Point2F(300.f, 300.f), m_Brush, 1.f);
m_RenderTarget->DrawLine(Point2F(300.f, 300.f), Point2F(400.f, 400.f), m_Brush, 1.f);

m_RenderTarget->EndDraw();

Comments | #rendering #direct2d Share

# Easiest Way to Generate a Bitmap

Wed
19
Oct 2011

I wanted to visualize results of some mathematical computations so I wondered what is the easiest way to generate and then show or save a bitmap? I considered Scilab, PHP with GD library, C++ with WinAPI GDI, C++ with some library that have image file formats support like FreeImage... Finally I've came up with the following solution, using only C++ and WinAPI to fill appropriate data structures and save the image as 24-bit BMP file.

// Width and height of the bitmap
unsigned size_x = 1280, size_y = 720;
// Rows top-down,
// for each row pixels from left to right,
// for each pixel components B, G, R = 0..255.
unsigned data_size = size_x * size_y * 3;
unsigned char *data = new unsigned char[data_size];

// Here fill the data, for example:
for (unsigned y = 0, i = 0; y < size_y; ++y) {
  for (unsigned x = 0; x < size_x; ++x) {
    data[i++] = 255; // G
    data[i++] = 255; // B
    data[i++] = 255; // R
  }
}

// Prepare data structures
DWORD data_offset = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
DWORD file_size = data_offset + data_size;
BITMAPFILEHEADER file_header = {
  0x4D42, // bfType = "BM"
  file_size, // bfSize
  0, 0, // bfReserved1, bfReserved2
  data_offset, // bfOffBits
};
BITMAPINFOHEADER info_header = {
  sizeof(BITMAPINFOHEADER), // biSize
  (LONG)size_x, -(LONG)size_y, // biWidth, biHeight
  1, // biPlanes
  24, // biBitCount
  BI_RGB, // biCompression
  0, // biSizeImage
  72, 72, // biXPelsPerMeter, biYPelsPerMeter
  0, 0, // biClrUsed, biClrImportant
};

// Save file
FILE *file = fopen("file_name.bmp", "wb");
fwrite(&file_header, sizeof(file_header), 1, file);
fwrite(&info_header, sizeof(info_header), 1, file);
fwrite(&data[0], 1, data_size, file);
fclose(file);

// Finalize
delete [] data;

Comments | #rendering #winapi #c++ Share

# Social Graph - Application on Facebook

Mon
11
Jul 2011

If you are active Facebook user and you like data visualisation just like me, then I strongly recommend you look at Social Graph application. When you run in, a Flash applet draws circles representing all your friends and connections between them. You are not there because, well, these are your friends so you are connected to all of them. You can only see how are they connected to each other. What's most interesting though is that they form some groups, which are clearly depicted thanks to graph visualisation algorithm used in this app. For example, my graph looks like this:

Facebook Social Graph

Several persons are not connected to anyone other I know. They are drawn somewhere outside the graph in a far distance. These are people who I know from some unusual place or who do not participate actively in Facebook and do not collect friends.

Rest of them forms clearly distinctive groups. The group on the right are people from my home town - mostly my friends from high school or university. The biggest group in the middle are passionate game developers from warsztat.gd community. Small group at the bottom consisting of four circles are contacts from my current job. On the left of Warsztat there is a group of professional game developers from Polish game industry. And finally the smaller group on the left consists of people I know from psytrance parties :)

What's also interesting is that there are some people who play role of a "center" of some group - are connected with almost everyone else in that group. Others are "connectors" that join two groups.

Comments | #rendering #web Share

# MRI Rendering

Mon
14
Feb 2011

Having injured arm is not a good thing, but for this reason I had MRI (Magnetic Resonance Imaging) and got results on a CD, so I've decided to try to render them in 3D as soon as I could move my arm a bit. Here is the final result:

Read full entry > | Comments | #directx #medicine #rendering Share

# Parallelizing Algorithms with Intel TBB and C++ Lambdas

Fri
27
Aug 2010

My demo for RiverWash is practically finished. I still could polish it or even make some big changes, because I know it's not great, but that's another story. What I want to write about today is how easily an algorithm can be changed to run in parallel on multicore processors when you use Intel Threading Building Blocks and C++ lambdas.

First, here is an algorithm. In one of my graphic effects I fill a 256x512 texture on CPU every frame. For each pixel I calculate a color based on some input data, which are constant during this operation. So the code looks like this:

void SaveToTexture(const D3DLOCKED_RECT &lockedRect)
{
  uint x, y;
  char *rowPtr = (char*)lockedRect.pBits;
  for (y = 0; y < TEXTURE_SIZEY; ++y)
  {
    XMCOLOR *pixelPtr = (XMCOLOR*)rowPtr;
    for (x = 0; x < TEXTURE_SIZEX; ++x)
    {
      *pixelPtr = CalcColorForPixel(x, y);
      ++pixelPtr;
    }
    rowPtr += lockedRect.Pitch;
  }
}

How to parallelize such loop? First, some theoretical background. Intel TBB is a free C++ library for high-level parallel programming. It has nice interface that makes extensive use of C++ language features but is very clean and simple. It provides many useful classes, from different kinds of mutexes and atomic operations, through thread-safe, scalable containers and memory allocators, till sophisticated task scheduler. But for my problem it was sufficient to use simple parallel_for function that utilizes the task scheduler internally. To start using TBB, I've just had to download and unpack this library, add appropriate paths as Include and Library directories in my Visual C++ and add this code:

#include <tbb/tbb.h>

#ifdef _DEBUG
#pragma comment(lib, "tbb_debug.lib")
#else
#pragma comment(lib, "tbb.lib")
#endif

Second topic I want to cover here are lambdas - new, great language feature from C++0x standard, available since Visual C++ 2010. Lambdas are simply unnamed functions defined inline inside some code. What's so great about them is they can capture the context of the caller. Selected variables can be passed by value or by reference, as well as this pointer or even "everything". It makes them ideal replacement for ugly functors that had to be used in C++ before.

Summing it all together, parallelized version of my algorithm is not much more complicated than the serial version:

void SaveToTexture(const D3DLOCKED_RECT &lockedRect)
{
  tbb::parallel_for(
    tbb::blocked_range<uint>(0, TEXTURE_SIZEY),
    [this, &lockedRect](const tbb::blocked_range<uint> &range)
  {
    uint x, y;
    char *rowPtr = (char*)lockedRect.pBits + lockedRect.Pitch * range.begin();
    for (y = range.begin(); y != range.end(); ++y)
    {
      XMCOLOR *pixelPtr = (XMCOLOR*)rowPtr;
      for (x = 0; x < TEXTURE_SIZEX; ++x)
      {
        *pixelPtr = CalcColorForPixel(x, y);
        ++pixelPtr;
      }
      rowPtr += lockedRect.Pitch;
    }
  } );
}

This simple change made all my 4 CPU cores busy for 90+% and gave almost 4x speedup in terms of frame time, which is good result. So as you can see, coding parallel applications is not necessarily difficult :)

Comments | #libraries #rendering #c++ Share

Pages: > 1 2 3 4 5 ... 21 >

[Download] [Dropbox] [pub] [Mirror] [Privacy policy]
Copyright © 2004-2020