Skip to content

Instantly share code, notes, and snippets.

@tarob19
Created December 6, 2022 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarob19/9788db0d7d1807c49bc13f2f56dd9522 to your computer and use it in GitHub Desktop.
Save tarob19/9788db0d7d1807c49bc13f2f56dd9522 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Rendering;
public struct MyVector
{
public float foo;
public float bar;
public float baz;
}
/// <summary>
/// 型による変換
/// </summary>
[GenerateHLSL]
public unsafe struct TestA
{
public uint a1; // uint
public bool a2; // bool
public float a3; // float
public Vector2 a4; // vector
public Vector3 a5; // vector
public Vector4 a6; // vector
public Matrix4x4 a7; // matrix
public float4 a8; // mathematics vector
//public float4x4 a9; // float4を中で持っているのでコンバート失敗
public int a10;
//public ulong a11; // 64bitは不可
public MyVector a12; // 自前の構造体
[HLSLArray(32, typeof(Vector4))]
public fixed float a13[32 * 4]; // 配列
}
[GenerateHLSL(PackingRules.Aggressive, containsPackedFields = true)]
public struct TestB
{
public float b1;
public Vector3 b2;
public Vector4 b3;
public Matrix4x4 b4;
public float4 b5;
public MyVector b6;
public float b7;
public int b8;
public int b9;
public int b10;
public int b11;
}
[GenerateHLSL(needAccessors = false)]
public class TestC
{
public float c1;
}
[GenerateHLSL(needSetters = true)]
public class TestD
{
public float d1;
}
[GenerateHLSL(needParamDebug = true)]
public class TestE
{
public float e1;
}
[GenerateHLSL(omitStructDeclaration = true, needAccessors = false)]
public class TestF
{
public float f1;
}
[GenerateHLSL(containsPackedFields = true)]
public class TestG
{
[Packing("g1A", FieldPacking.PackedUint, 8)]
[Packing("g1B", FieldPacking.PackedUint, 8, 8)]
[Packing("g1C", FieldPacking.PackedUint, 8, 16)]
[Packing("g1D", FieldPacking.PackedUint, 8, 24)]
public uint g1;
}
[GenerateHLSL(generateCBuffer = true, needAccessors = false)]
public struct TestH
{
public Vector4 h1;
}
[GenerateHLSL(needParamDebug = true)]
public struct TestI
{
[SurfaceDataAttributes("foo")]
public Vector4 i1;
[SurfaceDataAttributes("bar", precision = FieldPrecision.Half)]
public Vector4 i2;
[SurfaceDataAttributes("baz", precision = FieldPrecision.Real)]
public Vector4 i3;
}
[GenerateHLSL]
public struct TestJ
{
public static int J1 = 123;
public static float s_J2 = 23.4f;
public static float k_J3 = 3.14f;
}
[GenerateHLSL]
public enum EnumA
{
E1,
E2,
E3 = 100,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment