首页 > 数据库技术 > 详细

Unity CommandBuffer

时间:2020-03-10 16:11:57      阅读:55      评论:0      收藏:0      [点我收藏+]

  它在Unity5中已经开始实装了的, 不过因为现在的开发在显示效果有什么需求的, 基本都是插件能找到的, 也是策划人员随大流的设计, 所以基本没有实际上的开发需求, 一直就没有关注过.

 

 

 

 

 

  补一些默认的计算过程, 系统未提供的封装 : 

  1. 简单光照计算(自身为光源)

    struct v2f {
        float4 pos : SV_POSITION;
        float4 uv : TEXCOORD0;
        float3 ray : TEXCOORD1;
    };    
    
    // Common lighting data calculation (direction, attenuation, ...)
    void DeferredCalculateLightParams(
        unity_v2f_deferred_instanced i,
        out float3 outWorldPos,
        out float2 outUV,
        out half3 outLightDir,
        out float outAtten,
        out float outFadeDist)
    {
        i.ray = i.ray * (_ProjectionParams.z / i.ray.z);
        float2 uv = i.uv.xy / i.uv.w;

        // read depth and reconstruct world position
        float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
        depth = Linear01Depth(depth);
        float4 vpos = float4(i.ray * depth, 1);
        float3 wpos = mul(unity_CameraToWorld, vpos).xyz;

        float fadeDist = UnityComputeShadowFadeDistance(wpos, vpos.z);

        float3 lightPos = float3(unity_ObjectToWorld[0][3], unity_ObjectToWorld[1][3], unity_ObjectToWorld[2][3]);
        float3 tolight = wpos - lightPos;
        half3 lightDir = -normalize(tolight);

        float att = dot(tolight, tolight) * (距离平方倒数); // 光源的最远照亮距离
        float atten = tex2D (_LightTextureB0, att.rr).UNITY_ATTEN_CHANNEL;

        atten *= UnityDeferredComputeShadow(tolight, fadeDist, uv);

        outWorldPos = wpos;
        outUV = uv;
        outLightDir = lightDir;
        outAtten = atten;
        outFadeDist = fadeDist;
    }

 

Unity CommandBuffer

原文:https://www.cnblogs.com/tiancaiwrk/p/12455578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!