-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A direct sampler shader for debugging
- Loading branch information
Showing
54 changed files
with
3,733 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 6 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: SamplerMaterial | ||
m_Shader: {fileID: 4800000, guid: 48b99b800ea72b54da0df56e5c073d00, type: 3} | ||
m_ShaderKeywords: | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _BumpMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailAlbedoMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailMask: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailNormalMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _EmissionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MetallicGlossMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _OcclusionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _ParallaxMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Floats: | ||
- _BumpScale: 1 | ||
- _Cutoff: 0.5 | ||
- _DetailNormalMapScale: 1 | ||
- _DstBlend: 0 | ||
- _GlossMapScale: 1 | ||
- _Glossiness: 0.5 | ||
- _GlossyReflections: 1 | ||
- _Metallic: 0 | ||
- _Mode: 0 | ||
- _OcclusionStrength: 1 | ||
- _Parallax: 0.02 | ||
- _SmoothnessTextureChannel: 0 | ||
- _SpecularHighlights: 1 | ||
- _SrcBlend: 1 | ||
- _UVSec: 0 | ||
- _ZWrite: 1 | ||
m_Colors: | ||
- _Color: {r: 1, g: 1, b: 1, a: 1} | ||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
Shader "Unlit/SamplerShader" | ||
{ | ||
Properties | ||
{ | ||
_Color ("Color", Color) = (1,1,1,1) | ||
} | ||
SubShader | ||
{ | ||
Tags { "RenderType"="Opaque" } | ||
LOD 100 | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
#pragma target 4.5 | ||
/*#include "Assets/ShaderDebugger/debugger.cginc"*/ | ||
|
||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float3 normal : NORMAL; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float4 vertex : SV_POSITION; | ||
float4 worldPos : TEXCOORD0; | ||
float3 worldNormal : TEXCOORD1; | ||
}; | ||
|
||
float4 _Color; | ||
float4x4 _CVCT_WorldToLightLocalMatrix; | ||
float4 _CVCT_GridResolution; | ||
sampler3D _CVCT_LightTex3d; | ||
|
||
v2f vert (appdata v) | ||
{ | ||
v2f o; | ||
o.vertex = UnityObjectToClipPos(v.vertex); | ||
o.worldPos = mul(unity_ObjectToWorld, v.vertex); | ||
o.worldNormal = mul((float3x3)unity_ObjectToWorld, v.normal); | ||
return o; | ||
} | ||
|
||
float light_at_point(v2f i) | ||
{ | ||
float3 norm = mul((float3x3)_CVCT_WorldToLightLocalMatrix, i.worldNormal); | ||
if (norm.z >= 0) | ||
return 0; | ||
|
||
/* the scale in this matrix is such that the 0th cascade corresponds to | ||
the box from (-1,-1,-1) to (+1,+1,+1). */ | ||
float3 pos = mul(_CVCT_WorldToLightLocalMatrix, i.worldPos).xyz; | ||
|
||
float3 central_pos = abs(pos); | ||
float central_distance = max(central_pos.x, max(central_pos.y, central_pos.z)); | ||
/* central_distance => cascade: | ||
<= 1 0 | ||
<= 2 1 | ||
<= 4 2 | ||
<= 8 3 | ||
*/ | ||
float cascade = ceil(log2(max(1.0, central_distance))); | ||
|
||
pos *= pow(0.5, cascade); /* (-1,-1,-1) to (+1,+1,+1) in the right cascade */ | ||
pos = pos * 0.5 + 0.5; /* (0,0,0) to (1,1,1) */ | ||
pos.y += cascade; /* (0,c,0) to (1,1+c,1) */ | ||
pos.y *= _CVCT_GridResolution.y; /* rescale along y */ | ||
|
||
float light = pos.y < 1 ? tex3D(_CVCT_LightTex3d, pos).r : 1; | ||
|
||
/*uint root = DebugFragment(i.vertex); | ||
DbgValue4(root, float4(pos, light));*/ | ||
|
||
return light * (-normalize(norm).z); | ||
} | ||
|
||
fixed4 frag (v2f i) : SV_Target | ||
{ | ||
float4 col = _Color; | ||
col *= light_at_point(i); | ||
return col; | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.