Skip to content

Instantly share code, notes, and snippets.

View HarukaKajita's full-sized avatar

HarukaKajita HarukaKajita

View GitHub Profile

#UNITY_MATRIX_IT_MVの使い方とか View空間座標から、Object空間座標に変換する。
float4 objectSpacePos = mul(viewSpacePos, UNITY_MATRIX_IT_MV);

Projection空間座標から、View空間座標に変換 これは違った!!
float4 viewSpacePos = mul(eyeSpacePos, UNITY_MATRIX_P);

void vert(inout appdata_full v){
half4 worldPos = mul(_Object2World, v.vertex);
half4 viewPos = mul(UNITY_MATRIX_V, worldPos);
half4 eyePos = mul(UNITY_MATRIX_P, viewPos);
viewPos = mul(unity_CameraInvProjection, eyePos);
half4 localPos = mul(viewPos, UNITY_MATRIX_IT_MV);
v.vertex = localPos;
}
@sugi-cho
sugi-cho / ViewPortToPos.shader
Last active April 8, 2022 00:28
クリップ座標系から、ワールド座標へ変換するやつ。理解を深めた http://www.songho.ca/opengl/gl_projectionmatrix.html
Shader "Unlit/ViewPortToPos"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_VP ("viewport position", Vector) = (0.5,0.5,1,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
@aras-p
aras-p / OnlyShadowsAndAtten.shader
Created December 9, 2015 14:08
Shadows and Attenuation Only Shader
Shader "Custom/OnlyShadowsAndAtten"
{
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
// Forward rendering base (main directional light) pass.
Pass
{
@danielbierwirth
danielbierwirth / OffscreenRendering.cs
Last active April 9, 2024 21:32
Offscreen rendering script (unity | c#) | render camera view to texture | save texture as png
using System.Collections; using System.Collections.Generic;
using System.IO; using UnityEngine;
/// <summary>
/// Attach this script to an empty gameObject. Create a secondary camera
/// gameObject for offscreen rendering (not your main camera) and connect it
/// with this script. Offscreen camera should have a texture object attached to it.
/// OffscreenCamera texture object is used for rendering (please see camera properties).
/// </summary>
public class OffscreenRendering : MonoBehaviour {
@douduck08
douduck08 / README.md
Last active May 17, 2025 19:06
The general GetValue extension of SerializedProperty in Unity Editor.

Unity's SerializedProperty not support custom type value setting. This extension use Reflection to get target instance of SerializedProperty in Custom Editor, made value setting of general type is posible.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using System.IO;
using UnityEditor;
using UnityEngine.Assertions;
using System.Linq;
[ScriptedImporter(1, "cube")]
@deebrol
deebrol / ShowWhenAttribute.cs
Last active November 6, 2024 03:30
Property Drawer for Unity used to show or hide the Field depending on certain conditions
// DONT PUT IN EDITOR FOLDER
using System;
using UnityEngine;
/// <summary>
/// Attribute used to show or hide the Field depending on certain conditions
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class ShowWhenAttribute : PropertyAttribute {
@HarukaKajita
HarukaKajita / Noise.cginc
Last active June 5, 2020 16:12
ノイズ関数のまとめ
//関数内で大量に変数を定義するとGPU時間がめちゃ遅くなるのでスコープを使って書き直している部分があるので可読性が少し落ちている。ので注意。
///ret : 0.0 - <1.0
float rand(float n)
{
return frac(sin(n) * 63452.5453123);
}
///ret : 0.0 - <1.0
float rand(float2 co)
{
@gatosyocora
gatosyocora / GatoMaterialPropertyDrawer.cs
Last active April 20, 2023 08:41
ShaderLabのCustomMaterialPropertyDrawerのサンプル(区切り線, Texture2Dの1行表示, foldout)
using UnityEngine;
using UnityEditor;
using System;
namespace GatoMaterialPropertyDrawer
{
internal class LineDecorator : MaterialPropertyDrawer
{
private float spaceSize;