Skip to content

A high performance software renderer written in C# and C++

License

Notifications You must be signed in to change notification settings

theproadam/XFDraw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XFDraw

XFDraw is a realtime, high performance, software renderer written in C++ controlled via a wrapper written in C#. It's shaders are written in C++, however they are nearly identical to the GLSL language.

Just like renderXF, XFDraw has been also designed to be as simple and user friendly as possible. Because of this most of the code is composed of super simple commands, and buffer, shader and framebuffer initialization is also very simple. There is also a Wiki available to help with a quick start.

Currently XFDraw is still WIP. v0.5.0 should be the first stable release.

Features

  • Fully programmable fragment shader
  • Programmable vertex shader (Projection is done internally)
  • Hardcoded performance features (FXAA, Vignette, Draw Skybox)
  • Dedicated programmable high performance screenspace shaders
  • Tangent, Bitangent normal mapping supported (demo included)
  • Parallax, shadow mapping and volumetric fog supported (demo included)
  • Screenspace and cubemap reflections supported
  • Advanced buffer critical and non-critical locking system
  • Multithreaded rendering support (Create multiple shaders from one dll)
  • MSAA Support (Triangles have gaps but its there)
  • Direct blit (No bitmaps required)
  • GDI+ Interoperability (blit bitmaps onto the drawbuffer)
  • GLSL like shader code
  • Correct perspective interpolation
  • Perspective, Orthographic and mixed modes supported
  • Built in safety features, should be impossible to segfault
  • Textures support nearest and bilinear interpolation, with wrapping modes

Screenshots

Phong Example. 926 Triangles ~1.2ms (>20ms if the viewport is filled due to forward rendering)

Phong Shader Demo

Skybox + Cubemap Example ~3ms (>30ms if the viewport is filled due to forward rendering)

Phong Shader Demo

XFDraw included demo. Parallax Mapping + Volumetric Fog + SSAO + FXAA + Deferred rendering

XFDemo

XFDraw updated demo. Parallax Mapping + SSAO + FXAA + Deferred Rendering + Cubemap reflections

XFDemo

Skybox + Cubemap + Screenspace Reflection ~35ms (50 ray count + inefficient SSR shader)

SSR Demo

Normal Example. 926 Triangles ~0.4ms

Depth Fill Demo

Depth Fill. 350k Triangles ~3.3ms

Depth Fill Demo

Shadow mapping support. (Not Optimized Yet)

Shadow Mapping

Shadow mapping example. (Not Optimized Yet)

Shadow Mapping

Parallax mapping example. (Not Optimized Yet, Tangent/Bitangent support not shown here)

Parallax

Vignette Shader. ~0.6ms (in 1080p, not shown)

Screenspace Shaders Example

Example Shader Code

Vertex shader: teapotVS.cpp:

//version 330 Core
layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 norm;

out vec3 norm_data;
out vec3 frag_pos;

uniform vec3 cameraPos;
uniform mat3 cameraRot;

void main()
{
	gl_Position = cameraRot * (pos - cameraPos); //projection is handled internally
	norm_data = norm;
	frag_pos = pos;
}

Fragment shader: teapotFS.cpp:

out byte4 FragColor;

in vec3 norm_data;
in vec3 frag_pos;

uniform samplerCube skybox;
uniform vec3 camera_Pos;

void main()
{
	vec3 I = (frag_pos - camera_Pos);
	vec3 R = reflect(I, norm_data);
	
	FragColor = texture(skybox, R);
}

C# Side:

//Parse and compile the shader ->
ShaderCompile sModule = ShaderParser.Parse("teapotVS.cpp", "teapotFS.cpp", "teapot");
Shader teapotShader; sModule.Compile(out teapotShader);

//Prepare framebuffers, vertex buffers and projection->
GLTexture colorBuffer = new GLTexture(viewportWidth, viewportHeight, typeof(Color4));
GLTexture depthBuffer = new GLTexture(viewportWidth, viewportHeight, typeof(float));
GLBuffer teapotObject = new GLBuffer(floatArrayThatHasXYZ_IJK_Normals, 6); //6=stride
GLMatrix projMatrix = GLMatrix.Perspective(90f, viewportWidth, viewportHeight);

//Assign uniforms and link buffers ->
teapotShader.AssignBuffer("FragColor", colorBuffer);
teapotShader.SetValue("skybox", skybox);
teapotShader.SetValue("cameraRot", rotationalMatrix);
teapotShader.SetValue("cameraPos", cameraPosition);

//When done, draw the object
GL.Draw(teapotObject, teapotShader, depthBuffer, projMatrix, GLMode.Triangle);

Compiling is done via cl.exe, however you can always compile your code manually.