#UNITY_MATRIX_IT_MVの使い方とか
View空間座標から、Object空間座標に変換する。
float4 objectSpacePos = mul(viewSpacePos, UNITY_MATRIX_IT_MV);
Projection空間座標から、View空間座標に変換 これは違った!!
float4 viewSpacePos = mul(eyeSpacePos, UNITY_MATRIX_P);
| 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 { |
| Shader "Custom/OnlyShadowsAndAtten" | |
| { | |
| SubShader | |
| { | |
| Tags { "RenderType"="Opaque" } | |
| LOD 200 | |
| // Forward rendering base (main directional light) pass. | |
| Pass | |
| { |
| 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);