Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
G-Bufferを見てみる
#ifndef GBUFFER_VARIANT
#define GBUFFER_VARIANT
sampler2D _CameraGBufferTexture0;
sampler2D _CameraGBufferTexture1;
sampler2D _CameraGBufferTexture2;
sampler2D _CameraGBufferTexture3;
#endif //GBUFFER_VARIANT
using System.Collections;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class PostProcess : MonoBehaviour
{
public Material mat;
public void Start()
{
GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
}
[ImageEffectOpaque]
public void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination, mat);
}
}
Shader "DeferedShadingTest/ShowGBuffer"
{
Properties
{
[KeywordEnum(DIFF, SPEC, NORM, LIGHT, DEPTH)]
_GB("G-Buffer Selecter", Float) = 0
}
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma shader_feature _GB_DIFF _GB_SPEC _GB_NORM _GB_LIGHT _GB_DEPTH
#include "UnityCG.cginc"
#include "GBufferVariant.cginc"
#include "UnityDeferredLibrary.cginc"
fixed4 frag (v2f_img i) : SV_Target
{
#ifdef _GB_DIFF
return tex2D(_CameraGBufferTexture0, i.uv);
#elif _GB_SPEC
return tex2D(_CameraGBufferTexture1, i.uv);
#elif _GB_NORM
return tex2D(_CameraGBufferTexture2, i.uv);
#elif _GB_LIGHT
return tex2D(_CameraGBufferTexture3, i.uv);
#else
return Linear01Depth(tex2D(_CameraDepthTexture, i.uv).r);
#endif
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment