Code Snippets HLSL

Short texts HLSL 🧑‍💻 Code snippets HLSL ✍️ Reading lists HLSL 👀

Unity URP Custom Lit ShaderGraph – BlinnPhong (Wire in the inputs, then add Diffuse + Specular)

#ifndef CUSTOM_LIGHTING_INCLUDED #define CUSTOM_LIGHTING_INCLUDED /* IN(5): SpecColor(4), Smoothness(1), WPos(3), WNormal(3), WView(3) */ /* OUT(2): Diffuse(3), Specular(3) NdotL(1) for toon ramp: point fltr +clamp mode */ void CalculateLights_half(half4 SpecColor, half Smoothness, half3 WPos, half3 WNormal, half3 WView, out half3 Diffuse, out half3 Specular, out half NdotL) { Diffuse = 0; Specular = 0; NdotL = 0; […]

Ghost Of Fuji code snippet

float4x4 gWorldViewProj : WorldViewProjection; float4x4 gViewInverse : ViewInverse; Texture2D gParticleTexture; SamplerState samPoint { Filter = MIN_MAG_MIP_POINT; AddressU = WRAP; AddressV = WRAP; }; //STATES //****** BlendState AlphaBlending { BlendEnable[0] = TRUE; SrcBlend = SRC_ALPHA; DestBlend = INV_SRC_ALPHA; BlendOp = ADD; SrcBlendAlpha = ONE; DestBlendAlpha = ZERO; BlendOpAlpha = ADD; RenderTargetWriteMask[0] = 0x0f; }; DepthStencilState DisableDepthWriting […]

Ghost Of Fuji code snippet

float4x4 gWorld : WORLD; float4x4 gWorldViewProj : WORLDVIEWPROJECTION; float4x4 gWorldViewProj_Light; float3 gLightDirection = float3(-0.577f, -0.577f, 0.577f); float gShadowMapBias = 0.01f; Texture2D gDiffuseMap; Texture2D gShadowMap; SamplerComparisonState cmpSampler { // sampler state Filter = COMPARISON_MIN_MAG_MIP_LINEAR; AddressU = MIRROR; AddressV = MIRROR; // sampler comparison state ComparisonFunc = LESS_EQUAL; }; SamplerState samLinear { Filter = MIN_MAG_MIP_LINEAR; AddressU = […]

shaders.hlsl

//********************************************************* // // Copyright (c) Microsoft. All rights reserved. // This code is licensed under the MIT License (MIT). // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* Texture2D gScribbleTex […]

Simple custom ACES tonemapper that approximates the default UE4 filmic tonemapper in 11 instructions.

// Copyright 2021 Dmitry Molchanov and Julia Molchanova // This code is licensed under the MIT license const float ExposureMultiplier = 1.4; const float3x3 PRE_TONEMAPPING_TRANSFORM = { 0.575961650, 0.344143820, 0.079952030, 0.070806820, 0.827392350, 0.101774690, 0.028035252, 0.131523770, 0.840242300 }; const float3x3 EXPOSED_PRE_TONEMAPPING_TRANSFORM = ExposureMultiplier * PRE_TONEMAPPING_TRANSFORM; const float3x3 POST_TONEMAPPING_TRANSFORM = { 1.666954300, -0.601741150, -0.065202855, -0.106835220, 1.237778600, -0.130948950, […]