Skip to content

Instantly share code, notes, and snippets.

View HarukaKajita's full-sized avatar

HarukaKajita HarukaKajita

View GitHub Profile
@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 {
@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
{
@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" }
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;
}

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

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