Unityでshaderを書くときに参考になる公式リンク

Surface Shaderのサンプル集

Unity – Manual: Surface Shader examples
https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

SurfaceOutputSurfaceOutputStandardの定義と#pragma surfaceディレクティブに書けるキーワード

Unity – Manual: Writing Surface Shaders
https://docs.unity3d.com/Manual/SL-SurfaceShaders.html

Surface Shadersでlighting modelsを自作するサンプル集

Unity – Manual: Surface Shader lighting examples
https://docs.unity3d.com/Manual/SL-SurfaceShaderLightingExamples.html

vertex shader、fragment shaderのサンプル集

Unity – Manual: Vertex and fragment shader examples
https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html

vertex shader、fragment shaderのサンプル集
appdata_baseappdata_tanappdata_fullについて

Unity – Manual: Providing vertex data to vertex programs
https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html

UNITY_MATRIXunity_ObjectToWorld_TimeなどのBuilt-in変数

Unity – Manual: Built-in shader variables
https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html

??演算子(null合体演算子)

C#には??演算子(null合体演算子)という便利な演算子があるそうです。

x ?? y

のようにして、xnullでない場合はxを返し、xnullの場合はyを返す演算子になっています。

使い方はこんな感じです。

using System;

public class Example
{
  static public void Main ()
  {
    int? a = null;
    int? b = 10;
    int x = (a ?? b).Value;
    Console.WriteLine("x = " + x);
  }
}

実行結果

x = 10

これまで?:演算子で

int x = ((a != null) ? a : b).Value;

のようにしていたのが簡単に書けるみたいです。

リンク

C# 演算子 | Microsoft Docs
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/operators/

2直線の交点を計算するアルゴリズム

ゲームを作っていると2直線の交点が知りたいこともあるかなと思います。

そんな時に役立つ2直線の交点を計算するC#のコードです。

Line Intersection | Unity Community
https://forum.unity.com/threads/line-intersection.17384/

算数・数学の時間に勉強した範囲でコード化できる内容ですが自分で作るとなると結構な手間かなと思います。