浏览代码
Merge remote-tracking branch 'origin/master' into scriptablerenderloop-materialgraph
/scriptablerenderloop-materialgraph
Merge remote-tracking branch 'origin/master' into scriptablerenderloop-materialgraph
/scriptablerenderloop-materialgraph
Paul Demeulenaere
8 年前
当前提交
e26dbf64
共有 18 个文件被更改,包括 318 次插入 和 301 次删除
-
45Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
-
1Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/ShaderBase.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
-
88Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl
-
58Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader
-
58Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
-
4Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl
-
9Assets/ScriptableRenderLoop/common/ShaderBase.h
-
2Assets/ScriptableRenderLoop/common/TextureSettings.cs
-
6Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl
-
94Assets/TestScenes/HDTest/HDRenderLoopTest.unity
-
2ProjectSettings/ProjectVersion.txt
-
85Assets/ScriptableRenderLoop/HDRenderLoop/Material/MaterialUtilities.hlsl
-
10Assets/ScriptableRenderLoop/HDRenderLoop/Material/MaterialUtilities.hlsl.meta
-
125Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyProcedural.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyProcedural.shader.meta
|
|||
m_EditorVersion: 5.6.0a6 |
|||
m_EditorVersion: 5.6.0b1 |
|
|||
// In unity we can have a mix of fully baked lightmap (static lightmap) + enlighten realtime lightmap (dynamic lightmap) |
|||
// for each case we can have directional lightmap or not. |
|||
// Else we have lightprobe for dynamic/moving entity. Either SH9 per object lightprobe or SH4 per pixel per object volume probe |
|||
float3 SampleBakedGI(float3 positionWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap) |
|||
{ |
|||
// If there is no lightmap, it assume lightprobe |
|||
#if !defined(LIGHTMAP_ON) && !defined(DYNAMICLIGHTMAP_ON) |
|||
|
|||
// TODO: Confirm with Ionut but it seems that UNITY_LIGHT_PROBE_PROXY_VOLUME is always define for high end and |
|||
// unity_ProbeVolumeParams always bind. |
|||
if (unity_ProbeVolumeParams.x == 0.0) |
|||
{ |
|||
// TODO: pass a tab of coefficient instead! |
|||
float4 SHCoefficients[7]; |
|||
SHCoefficients[0] = unity_SHAr; |
|||
SHCoefficients[1] = unity_SHAg; |
|||
SHCoefficients[2] = unity_SHAb; |
|||
SHCoefficients[3] = unity_SHBr; |
|||
SHCoefficients[4] = unity_SHBg; |
|||
SHCoefficients[5] = unity_SHBb; |
|||
SHCoefficients[6] = unity_SHC; |
|||
|
|||
return SampleSH9(SHCoefficients, normalWS); |
|||
} |
|||
else |
|||
{ |
|||
// TODO: Move all this to C++! |
|||
float4x4 identity = 0; |
|||
identity._m00_m11_m22_m33 = 1.0; |
|||
float4x4 WorldToTexture = (unity_ProbeVolumeParams.y == 1.0f) ? unity_ProbeVolumeWorldToObject : identity; |
|||
|
|||
float4x4 translation = identity; |
|||
translation._m30_m31_m32 = -unity_ProbeVolumeMin.xyz; |
|||
|
|||
float4x4 scale = 0; |
|||
scale._m00_m11_m22_m33 = float4(unity_ProbeVolumeSizeInv.xyz, 1.0); |
|||
|
|||
WorldToTexture = mul(mul(scale, translation), WorldToTexture); |
|||
|
|||
return SampleProbeVolumeSH4(TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionWS, normalWS, WorldToTexture, unity_ProbeVolumeParams.z); |
|||
} |
|||
|
|||
#else |
|||
|
|||
float3 bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
#ifdef LIGHTMAP_ON |
|||
#ifdef DIRLIGHTMAP_COMBINED |
|||
bakeDiffuseLighting += SampleDirectionalLightmap(TEXTURE2D_PARAM(unity_Lightmap, samplerunity_Lightmap), |
|||
TEXTURE2D_PARAM(unity_LightmapInd, samplerunity_Lightmap), |
|||
uvStaticLightmap, unity_LightmapST, normalWS); |
|||
#else |
|||
bakeDiffuseLighting += SampleSingleLightmap(TEXTURE2D_PARAM(unity_Lightmap, samplerunity_Lightmap), uvStaticLightmap, unity_LightmapST); |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef DYNAMICLIGHTMAP_ON |
|||
#ifdef DIRLIGHTMAP_COMBINED |
|||
bakeDiffuseLighting += SampleDirectionalLightmap(TEXTURE2D_PARAM(unity_DynamicLightmap, samplerunity_DynamicLightmap), |
|||
TEXTURE2D_PARAM(unity_DynamicDirectionality, samplerunity_DynamicLightmap), |
|||
uvDynamicLightmap, unity_DynamicLightmapST, normalWS); |
|||
#else |
|||
bakeDiffuseLighting += SampleSingleLightmap(TEXTURE2D_PARAM(unity_DynamicLightmap, samplerunity_DynamicLightmap), uvDynamicLightmap, unity_DynamicLightmapST); |
|||
#endif |
|||
#endif |
|||
|
|||
return bakeDiffuseLighting; |
|||
|
|||
#endif |
|||
} |
|||
|
|||
float2 CalculateVelocity(float4 positionCS, float4 previousPositionCS) |
|||
{ |
|||
// This test on define is required to remove warning of divide by 0 when initializing empty struct |
|||
// TODO: Add forward opaque MRT case... |
|||
#if (SHADERPASS == SHADERPASS_VELOCITY) || (SHADERPASS == SHADERPASS_GBUFFER && SHADEROPTIONS_VELOCITY_IN_GBUFFER) |
|||
// Encode velocity |
|||
positionCS.xy = positionCS.xy / positionCS.w; |
|||
previousPositionCS.xy = previousPositionCS.xy / previousPositionCS.w; |
|||
|
|||
return (positionCS.xy - previousPositionCS.xy) * _ForceNoMotion; |
|||
#else |
|||
return float2(0.0, 0.0); |
|||
#endif |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 79a3fb95997b9d54d98b5888a5082570 |
|||
timeCreated: 1481202371 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/HDRenderLoop/SkyProcedural" |
|||
{ |
|||
SubShader |
|||
{ |
|||
Pass |
|||
{ |
|||
ZWrite Off |
|||
ZTest LEqual |
|||
Blend One Zero |
|||
|
|||
HLSLPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
#pragma multi_compile _ ATMOSPHERICS_DEBUG |
|||
#pragma multi_compile _ ATMOSPHERICS_OCCLUSION_FULLSKY |
|||
#pragma multi_compile _ PERFORM_SKY_OCCLUSION_TEST |
|||
|
|||
#ifndef PERFORM_SKY_OCCLUSION_TEST |
|||
#define IS_RENDERING_SKY |
|||
#endif |
|||
|
|||
#include "Color.hlsl" |
|||
#include "Common.hlsl" |
|||
#include "CommonLighting.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl" |
|||
#include "AtmosphericScattering.hlsl" |
|||
|
|||
TEXTURECUBE(_Cubemap); |
|||
SAMPLERCUBE(sampler_Cubemap); |
|||
|
|||
float4x4 _InvViewProjMatrix; |
|||
float4 _SkyParam; // x exposure, y multiplier, z rotation |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionCS : POSITION; |
|||
float3 eyeVector : NORMAL; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS : SV_POSITION; |
|||
float3 eyeVector : TEXCOORD0; |
|||
}; |
|||
|
|||
Varyings Vert(Attributes input) |
|||
{ |
|||
// TODO: implement SV_vertexID full screen quad |
|||
Varyings output; |
|||
output.positionCS = float4(input.positionCS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0); |
|||
output.eyeVector = input.eyeVector; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
float4 Frag(Varyings input) : SV_Target |
|||
{ |
|||
float3 dir = normalize(input.eyeVector); |
|||
|
|||
// Rotate direction |
|||
float phi = DegToRad(_SkyParam.z); |
|||
float cosPhi, sinPhi; |
|||
sincos(phi, sinPhi, cosPhi); |
|||
float3 rotDirX = float3(cosPhi, 0, -sinPhi); |
|||
float3 rotDirY = float3(sinPhi, 0, cosPhi); |
|||
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir)); |
|||
|
|||
Coordinate coord = GetCoordinate(input.positionCS.xy, _ScreenSize.zw); |
|||
|
|||
// If the sky box is too far away (depth set to 0), the resulting look is too foggy. |
|||
const float skyDepth = 0.01; |
|||
|
|||
#ifdef PERFORM_SKY_OCCLUSION_TEST |
|||
// Determine whether the sky is occluded by the scene geometry. |
|||
// Do not perform blending with the environment map if the sky is occluded. |
|||
float rawDepth = max(skyDepth, LOAD_TEXTURE2D(_CameraDepthTexture, coord.unPositionSS).r); |
|||
float skyTexWeight = (rawDepth > skyDepth) ? 0.0 : 1.0; |
|||
#else |
|||
float rawDepth = skyDepth; |
|||
float skyTexWeight = 1.0; |
|||
#endif |
|||
|
|||
float3 positionWS = UnprojectToWorld(rawDepth, coord.positionSS, _InvViewProjMatrix); |
|||
|
|||
float4 c1, c2, c3; |
|||
VolundTransferScatter(positionWS, c1, c2, c3); |
|||
|
|||
float4 coord1 = float4(c1.rgb + c3.rgb, max(0.f, 1.f - c1.a - c3.a)); |
|||
float3 coord2 = c2.rgb; |
|||
|
|||
float sunCos = dot(normalize(dir), _SunDirection); |
|||
float miePh = MiePhase(sunCos, _MiePhaseAnisotropy); |
|||
|
|||
float2 occlusion = float2(1.0, 1.0); // TODO. |
|||
float extinction = coord1.a; |
|||
float3 scatter = coord1.rgb * occlusion.x + coord2 * miePh * occlusion.y; |
|||
|
|||
#ifdef ATMOSPHERICS_DEBUG |
|||
switch (_AtmosphericsDebugMode) |
|||
{ |
|||
case ATMOSPHERICS_DBG_RAYLEIGH: return c1; |
|||
case ATMOSPHERICS_DBG_MIE: return c2 * miePh; |
|||
case ATMOSPHERICS_DBG_HEIGHT: return c3; |
|||
case ATMOSPHERICS_DBG_SCATTERING: return float4(scatter, 0.0); |
|||
case ATMOSPHERICS_DBG_OCCLUSION: return float4(occlusion.xy, 0.0, 0.0); |
|||
case ATMOSPHERICS_DBG_OCCLUDEDSCATTERING: return float4(scatter, 0.0); |
|||
} |
|||
#endif |
|||
|
|||
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y); |
|||
|
|||
// Apply extinction to the scene color when performing alpha-blending. |
|||
return float4(skyColor * (skyTexWeight * extinction) + scatter, extinction); |
|||
} |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
} |
|||
Fallback Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f96d105ca709d5c499b4886b48313d60 |
|||
timeCreated: 1481041226 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue