Skip to content

Instantly share code, notes, and snippets.

@polar1225
polar1225 / wgsl_noise.md
Created March 28, 2024 02:17 — forked from munrocket/wgsl_noise.md
WGSL Noise Algorithms

WGSL Noise Algorithms

Operator % has changed, probably current code with it need a fix

Good and fast integer hash

// https://www.pcg-random.org/
fn pcg(n: u32) -> u32 {
    var h = n * 747796405u + 2891336453u;
    h = ((h >> ((h >> 28u) + 4u)) ^ h) * 277803737u;
@polar1225
polar1225 / SinglePassMipPyramid.hlsl
Created December 13, 2022 02:27 — forked from sebbbi/SinglePassMipPyramid.hlsl
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]
@polar1225
polar1225 / download.cpp
Created November 29, 2022 02:12 — forked from nem0/download.cpp
Donwload file on windows without 3rd party
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
bool download(const char* url, OutputMemoryStream& blob) {
IStream* stream = nullptr;
if (S_OK != URLOpenBlockingStream(nullptr, url, &stream, 0, nullptr)) {
return false;
}
char buffer[4096];
ULONG read = 0;
@polar1225
polar1225 / BoundingFrustum.cs
Created June 8, 2021 03:11
Bounding Frustum implementation in C# for Unity.
namespace StagPoint.Math
{
using System;
using UnityEngine;
using Mono.Simd;
public class BoundingFrustum
{
#region Public fields
@polar1225
polar1225 / WorldNormalFromDepthTexture.shader
Created March 1, 2021 02:22 — forked from bgolus/WorldNormalFromDepthTexture.shader
Different methods for getting World Normal from Depth Texture, without any external script dependencies.
Shader "WorldNormalFromDepthTexture"
{
Properties {
[KeywordEnum(3 Tap, 4 Tap, Improved, Accurate)] _ReconstructionMethod ("Normal Reconstruction Method", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100