Gregory Igehy

Dancing at hemisphere coordinate

Notes of GPU Tessellation

GPU Pro

Notes of Houdini

Houdini to UE4



Houdini fracture




UE4

UE4 vertex animation

Notes of flipbook shaders

Notes of 2d Fluid simluation

the Little Grashopper

Notes of postprocess with stencil in Unity

Unity 5.6.X のグラフィックスの雑記

OnRenderImage(src,dst) で送られる引数

  • Forward LDR, Deferred LDR
    • src : ARGB_32, depth 24bit with stencil
    • dst : null
  • Forward HDR, Deferred HDR
    • src : ARGBHalf, depth 24bit with stencil
    • dst : null

ポストエフェクトでデフォルトのデプスバッファで EarlyZ は使えるか ?

  • Forward : OK
  • Deferred : NG??

ポストエフェクトでデフォルトのデプスバッファでステンシルテストは使えるか?

  • Forward : NG?
  • Deferred : NG?
  • 自分で RenderTexture (Color + Depth24bit)を用意してそれを使った場合は大丈夫

Forward の CameraDepthNormalTexture について

  • 中身は頂点シェーダで計算した法線
  • 従って, 法線マップが適用されていないのもの
// UnityCG.cginc
#define COMPUTE_VIEW_NORMAL normalize(mul((float3x3)UNITY_MATRIX_IT_MV, v.normal))


// AmbientOccusion.cginc
// https://github.com/Unity-Technologies/PostProcessing/blob/v1/PostProcessing/Resources/Shaders/AmbientOcclusion.cginc
sampler2D _CameraDepthNormalsTexture;

// Depth/normal sampling functions
float SampleDepth(float2 uv)
{
#if defined(SOURCE_GBUFFER) || defined(SOURCE_DEPTH)
    float d = LinearizeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv));
#else
    float4 cdn = tex2D(_CameraDepthNormalsTexture, uv);
    float d = DecodeFloatRG(cdn.zw);
#endif
    return d * _ProjectionParams.z + CheckBounds(uv, d);
}

float3 SampleNormal(float2 uv)
{
#if defined(SOURCE_GBUFFER)
    float3 norm = tex2D(_CameraGBufferTexture2, uv).xyz;
    norm = norm * 2 - any(norm); // gets (0,0,0) when norm == 0
    norm = mul((float3x3)unity_WorldToCamera, norm);
#if defined(VALIDATE_NORMALS)
    norm = normalize(norm);
#endif
    return norm;
#else
    float4 cdn = tex2D(_CameraDepthNormalsTexture, uv);
    return DecodeViewNormalStereo(cdn) * float3(1.0, 1.0, -1.0);
#endif
}

float SampleDepthNormal(float2 uv, out float3 normal)
{
#if defined(SOURCE_GBUFFER) || defined(SOURCE_DEPTH)
    normal = SampleNormal(uv);
    return SampleDepth(uv);
#else
    float4 cdn = tex2D(_CameraDepthNormalsTexture, uv);
    normal = DecodeViewNormalStereo(cdn) * float3(1.0, 1.0, -1.0);
    float d = DecodeFloatRG(cdn.zw);
    return d * _ProjectionParams.z + CheckBounds(uv, d);
#endif
}
// http://unlicense.org/

float4 cdn            = tex2D( _CameraDepthNormalsTexture, uv );
float3 view_normal    = DecodeViewNormalStereo( cdn ) * float3( 1.0f, 1.0f, - 1.0f );
float4 world_normal4  = mul( unity_CameraToWorld, float4( view_normal, 0.0 ) );
float3 world_normal   = normalize( world_normal4.rgb );

float  abs_view_pos_z = DecodeFloatRG( cdn.zw );
float  view_pos_z     = ( - abs_view_pos_z );