Skip to content

Instantly share code, notes, and snippets.

@pixelsnafu
pixelsnafu / CloudsResources.md
Last active July 10, 2024 08:04
Useful Resources for Rendering Volumetric Clouds

Volumetric Clouds Resources List

  1. A. Schneider, "Real-Time Volumetric Cloudscapes," in GPU Pro 7: Advanced Rendering Techniques, 2016, pp. 97-127. (Follow up presentations here, and here.)

  2. S. Hillaire, "Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite" in Physically Based Shading in Theory and Practice course, SIGGRAPH 2016. [video] [course notes] [scatter integral shadertoy]

  3. [R. Högfeldt, "Convincing Cloud Rendering – An Implementation of Real-Time Dynamic Volumetric Clouds in Frostbite"](https://odr.chalmers.se/hand

@mmozeiko
mmozeiko / ods.c
Created April 16, 2019 19:20
Example how to capture OutputDebugString on Windows
#include <windows.h>
#include <intrin.h>
#define Assert(x) do { if (!(x)) __debugbreak(); } while (0)
static struct
{
DWORD process_id;
char data[4096 - sizeof(DWORD)];
}* ods_buffer;
@shorttermmem
shorttermmem / rootsignature.error
Last active January 4, 2024 20:02
Common root signature errors compilation.
Root Signature doesn't match Compute Shader: A Shader is declaring a resource object as a texture using a register mapped to a root descriptor SRV (RegisterSpace=0, ShaderRegister=0).
SRV or UAV root descriptors can only be Raw or Structured buffers.
[ STATE_CREATION ERROR #882: CREATECOMPUTEPIPELINESTATE_CS_ROOT_SIGNATURE_MISMATCH]
When binding a texture object directly to root signature rather than through descriptor table.
D3D12 CORRUPTION: ID3D12CommandList::CopyTextureRegion: pResource in the first parameter is corrupt. [ MISCELLANEOUS CORRUPTION #3: CORRUPTED_PARAMETER1]
@BeRo1985
BeRo1985 / astronomy.glsl
Last active July 31, 2018 20:29
GLSL Astronomy compute shader
// Copyright (C) 2018, Benjamin "BeRo" Rosseaux (benjamin@rosseaux.de) - License: CC0
// Hint: It's not super accurate, but it should be good enough for games and demos with sky rendering.
#version 430
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
uniform vec3 tc; // Time constant
layout(std430) buffer ssboAstronomy {
vec3 sunPosition;
float sunDistance;
@Erkaman
Erkaman / taa.frag
Last active April 25, 2023 02:32
rudimentary temporal anti-aliasing solution, that is good as a starting point for more advanced TAA techniques.
/*
The MIT License (MIT)
Copyright (c) 2018 Eric Arnebäck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@jspohr
jspohr / microsecs.c
Last active June 2, 2024 18:10
Avoid overflow when converting time to microseconds
// Taken from the Rust code base: https://github.com/rust-lang/rust/blob/3809bbf47c8557bd149b3e52ceb47434ca8378d5/src/libstd/sys_common/mod.rs#L124
// Computes (value*numer)/denom without overflow, as long as both
// (numer*denom) and the overall result fit into i64 (which is the case
// for our time conversions).
int64_t int64MulDiv(int64_t value, int64_t numer, int64_t denom) {
int64_t q = value / denom;
int64_t r = value % denom;
// Decompose value as (value/denom*denom + value%denom),
// substitute into (value*numer)/denom and simplify.
// r < denom, so (denom*numer) is the upper bound of (r*numer)
@paniq
paniq / perfect_spatial_hashing.txt
Last active June 21, 2024 14:56
Perfect Spatial Hashing
# forays into
Perfect Spatial Hashing (Lefebvre & Hoppe)
http://hhoppe.com/perfecthash.pdf
how it works:
There are two parts: a slow encoding step, and a fast decoding step.
Encoding
@sebbbi
sebbbi / SinglePassMipPyramid.hlsl
Last active January 12, 2024 07:16
Single pass globallycoherent mip pyramid generation
// NOTE: Must bind 8x single mip RWTexture views, because HLSL doesn't have .mips member for RWTexture2D. (SRVs only have .mips member)
// NOTE: globallycoherent attribute is needed. Without it writes aren't guaranteed to be seen by other groups
globallycoherent RWTexture2D<float> MipTextures[8];
RWTexture2D<uint> Counters[8];
groupshared uint CounterReturnLDS;
[numthreads(16, 16, 1)]
void GenerateMipPyramid(uint3 Tid : SV_DispatchThreadID, uint3 Group : SV_GroupId, uint Gix : SV_GroupIndex)
{
[unroll]
@sebbbi
sebbbi / fast_spheres.txt
Created February 18, 2018 19:31
Fast way to render lots of spheres
Setup:
1. Index buffer containing N quads (each 2 triangles), where N is the max amount of spheres. Repeating pattern of {0,1,2,1,3,2} + K*4.
2. No vertex buffer.
Render N*2 triangles, where N is the number of spheres you have.
Vertex shader:
1. Sphere index = N/4 (N = SV_VertexId)
2. Quad coord: Q = float2(N%2, (N%4)/2) * 2.0 - 1.0
3. Transform sphere center -> pos
@paniq
paniq / ellipsoid_frustum.md
Last active December 30, 2021 20:13
Ellipsoid Frustum Intersection

Ellipsoid Frustum Intersection

Yesterday I posted a problem to math stack exchange that bothered me for a while now, and right after I've had a few exchanges on Twitter, I got inspired to attempt a solution.

Here it goes. It's 100% untested but I'm fairly certain that it will work.

The problem is about a form of refining raytracing where we render a big list of convex 3D brushes (and I decided to start with Ellipsoids, since they're so useful) to the screen or a shadow map, without any prebuilt accelleration structure. How does it work? Well, if we had a way to figure out for a portion of the frustum whether it contained a brush, we could

  1. Start with a very low resolution