Skip to content

Instantly share code, notes, and snippets.

@d7samurai
d7samurai / .readme.md
Last active July 8, 2024 13:57
Minimal D3D11 pt3

Minimal D3D11 pt3

An elaboration on Minimal D3D11 pt2, adding shadowmapping and incorporating various improvements and alternative approaches to the rendering setup, such as manual vertex fetching, samplerless texture lookup, null shader depth map rendering and procedurally generated texture and instance data.

As before, this is intended to be an an "API familiarizer" - an uncluttered Direct3D 11 setup & basic rendering reference implementation, in the form of a complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion. No modern C++ / OOP / obscuring cruft, only ~190 LOC. View on YouTube

minimald3d11pt3

@d7samurai
d7samurai / .readme.md
Last active March 27, 2024 17:50
Minimal D3D11 pt2

Minimal D3D11 pt2

Follow-up to Minimal D3D11, adding instanced rendering. As before: An uncluttered Direct3D 11 setup & basic rendering primer / API familiarizer. Complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion. No modern C++ / OOP / obscuring cruft.

The main difference here is that the hollow cube is rendered using DrawIndexedInstanced (which saves a lot of vertices compared to the original, so model data is now small enough to be included in the source without being too much in the way), but also all trigonometry and matrix math is moved to the vertex shader, further simplifying the main code.

Each instance is merely this piece of geometry, consisting of 4 triangles:

instanced1

..which is th

@mmozeiko
mmozeiko / pcg32.h
Last active February 5, 2024 10:46
simple standalone C headers for PCG random number generator
#pragma once
#include <stdint.h>
#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
#define PCG_DEFAULT_INCREMENT_64 1442695040888963407ULL
typedef struct {
uint64_t state;
} pcg32;
@mmozeiko
mmozeiko / win32_d3d11.c
Last active May 17, 2024 08:42
setting up and using D3D11 in C
// example how to set up D3D11 rendering on Windows in C
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_3.h>
#include <d3dcompiler.h>
#include <dxgidebug.h>
@mmozeiko
mmozeiko / d3d11_pixels.c
Last active June 18, 2023 20:42
drawing pixels in software & showing them to window by uploading via D3D11
#define COBJMACROS
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <stdint.h>
#include <string.h>
#include <intrin.h>
@NoelFB
NoelFB / routine.h
Last active November 7, 2022 07:19
Simple C++ Coroutine using a switch statement internally
#pragma once
namespace YourNamespace
{
struct Routine
{
// Current "waiting time" before we run the next block
float wait_for = 0;
// Used during `rt_for`, which repeats the given block for X time
@nakst
nakst / maths.cpp
Last active January 20, 2023 16:40
// NOTE Compile without fast math flags.
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
@binaryfoundry
binaryfoundry / ShaderLabPBR.shader
Last active April 27, 2023 10:18
Unity PBR Shader
Shader "CustomPBRShader"
{
Properties
{
[NoScaleOffset] _Albedo("Albedo", Color) = (1.0, 1.0, 1.0, 1.0)
[NoScaleOffset] _Metalness("Conductivity", Range(0.0, 1.0)) = 0.0
[NoScaleOffset] _Roughness("Roughness", Range(0.0, 1.0)) = 0.0
[NoScaleOffset][HDR] _RadianceMap("RadianceMap", CUBE) = "" {}
[NoScaleOffset][HDR] _IrradianceMap("IrradianceMap", CUBE) = "" {}
}
@d7samurai
d7samurai / .readme.md
Last active July 14, 2024 04:23
Minimal D3D11

Minimal D3D11

Minimal D3D11 reference implementation: An uncluttered Direct3D 11 setup + basic rendering primer and API familiarizer. Complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion that should be easy to follow from the code alone. ~200 LOC. No modern C++, OOP or (other) obscuring cruft. View on YouTube

hollowcube

Also check out Minimal D3D11 pt2, reconfigured for instanced rendering and with a smaller, tighter, simplified overall code structure, or Minimal D3D11 pt3, with shadowmapping + showcasing a range of alternative setup and rendering techniques.