Skip to content

Instantly share code, notes, and snippets.

@Arlorean
Arlorean / UsingCsCodeInHLSL.cs
Created January 5, 2025 14:34 — forked from kraj0t/UsingCsCodeInHLSL.cs
How to include C# code in an HLSL file - useful for sharing code between CPU and shader without duplicating any files
// Share code between HLSL (shaders) and C#
//
// Limitations:
// - Cannot use #include
// - Must use defines to hide certain keywords, such as public, private, protected, or any other object-oriented programming keywords
// - Use defines to convert half or fixed to your desired C# equivalent
// - Must always write f after float literals
// - Use #if !MY_DEFINE instead of #ifndef MY_DEFINE
// - #define cannot be used with a value in C#, not even inside an '#if SHADER_TARGET' block. Therefore, you have two options for declaring valued constants:
// a. Declare each constant separately in HLSL (using 'static const float MyConstant = 1.0f') and in C# (using 'const float MyConstant = 1.0f'). C# does not support 'static const'.
@Arlorean
Arlorean / fonts_to_css.py
Created July 23, 2024 14:26
FontsToCss: Convert a font or zip of fonts to a .css with embedded @font-face base64 data
# FONTS TO CSS
#
# Convert a font or zip of fonts to a .css with embedded @font-face base64 data.
#
# Install Python: https://www.python.org/downloads/
# NOTE: Check "Add Python to environment variables" during Windows install
# Using Command Line:
# pip install fonttools
# python convert.py <path_to_font_or_zip_of_fonts>
import base64
@Arlorean
Arlorean / Profile.cs
Created March 27, 2023 08:43
Profile a block of C# code in Unity
using System;
using System.IO;
using System.Runtime.CompilerServices;
using UnityEngine;
/// <summary>
/// Log the time taken to execute a block of code to the Unity console.<br/>
/// <example>
/// Here is an example of how to use it in a script.<br/>
/// The result is the total time taken to execute <c>CallMyMethod()</c> and <c>CallAnotherMethod()</c>.
@Arlorean
Arlorean / UnityLitPBRShaderGraph.shadergraph
Created November 11, 2021 14:17
Unity Lit PBR ShaderGraph
{
"m_SGVersion": 3,
"m_Type": "UnityEditor.ShaderGraph.GraphData",
"m_ObjectId": "772d48923d4842b6b8a7dabccb0f5c30",
"m_Properties": [
{
"m_Id": "3713953109a3e78d88280c504d504dfc"
},
{
"m_Id": "47f5c92615528b8f8e05489b72b57dff"
using System;
using number = System.Decimal;
namespace Fibonacci {
class Program {
// Recursion
static number fibr(number n) {
if (n == 0) { return 0; }
/*
* Copyright (C) 2013 Gotham City. All rights reserved.
* Copyright (C) 2017 Arlorean. All rights reserved. (C#/MediaFoundation.NET port)
*/
using System;
using System.Diagnostics;
using MediaFoundation;
using MediaFoundation.Misc;
using static MediaFoundation.CLSID;
@Arlorean
Arlorean / MainWindow.xaml.cs
Created December 17, 2016 16:02
View SVG in WPF Window using SkiaSharp
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication2 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
var svg = new SkiaSharp.SKSvg();
var picture = svg.Load("Tiger.svg");