Синтаксис:
Используется glsl
Shader "Custom/NewShader" {
Properties {
//_MainTex ("Base", 2D) = "white" {}
}
SubShader {
Pass{
ZTest Always
CGPROGRAM
#pragma target 3.0
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
//sampler2D _MainTex;
sampler2D _CameraDepthTexture;
float4 frag(v2f_img i) : COLOR{
return tex2D(_CameraDepthTexture, i.uv);
}
ENDCG
}
}
FallBack Off
}
Properties {
//_MainTex ("Base", 2D) = "white" {}
}
SubShader {
Pass{
ZTest Always
CGPROGRAM
#pragma target 3.0
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
//sampler2D _MainTex;
sampler2D _CameraDepthTexture;
float4 frag(v2f_img i) : COLOR{
return tex2D(_CameraDepthTexture, i.uv);
}
ENDCG
}
}
FallBack Off
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class NewBehaviourScript : MonoBehaviour {
public Material material;
void Awake(){
if(camera) camera.depthTextureMode = DepthTextureMode.Depth;
}
void OnRenderImage(RenderTexture source, RenderTexture destination){
if(material){
Graphics.Blit(source, destination, material);
}
}
}
using System.Collections;
[ExecuteInEditMode]
public class NewBehaviourScript : MonoBehaviour {
public Material material;
void Awake(){
if(camera) camera.depthTextureMode = DepthTextureMode.Depth;
}
void OnRenderImage(RenderTexture source, RenderTexture destination){
if(material){
Graphics.Blit(source, destination, material);
}
}
}
В режиме Deffered Rendering отображается нормально:
В режиме Forward Rendering результат почему-то обращается сверху-вних:
Почему так происходит?