浏览代码
Merge remote-tracking branch 'origin/master' into scriptablerenderloop-materialgraph
/scriptablerenderloop-materialgraph
Merge remote-tracking branch 'origin/master' into scriptablerenderloop-materialgraph
/scriptablerenderloop-materialgraph
当前提交
d6e910a1
共有 60 个文件被更改,包括 3992 次插入 和 1265 次删除
-
14Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
3Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader
-
3Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Deferred.shader
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl
-
34Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitCommon.hlsl
-
69Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
-
118Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.hlsl
-
67Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader
-
48Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitUI.cs
-
53Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitData.hlsl
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitDefault.shader
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassGBuffer.hlsl
-
39Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl
-
66Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
-
24Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
22Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl
-
6Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
-
2Assets/ScriptableRenderLoop/common/ShaderBase.h
-
41Assets/ScriptableRenderLoop/common/TextureCache.cs
-
4Assets/ScriptableRenderLoop/fptl/ClusteredUtils.h
-
1001Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
-
5Assets/ScriptableRenderLoop/fptl/LightBoundsDebug.shader
-
3Assets/ScriptableRenderLoop/fptl/LightDefinitions.cs
-
4Assets/ScriptableRenderLoop/fptl/LightDefinitions.cs.hlsl
-
4Assets/ScriptableRenderLoop/fptl/LightingConvexHullUtils.hlsl
-
4Assets/ScriptableRenderLoop/fptl/LightingUtils.hlsl
-
8Assets/ScriptableRenderLoop/fptl/lightlistbuild-bigtile.compute
-
14Assets/ScriptableRenderLoop/fptl/lightlistbuild-clustered.compute
-
4Assets/ScriptableRenderLoop/fptl/lightlistbuild.compute
-
6Assets/ScriptableRenderLoop/fptl/scrbound.compute
-
9Assets/BasicRenderLoopTutorial.meta
-
112Assets/ScriptableRenderLoop/ShaderLibrary/EntityLighting.hlsl
-
9Assets/ScriptableRenderLoop/ShaderLibrary/EntityLighting.hlsl.meta
-
73Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/anisoTest.mat
-
8Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/anisoTest.mat.meta
-
73Assets/BasicRenderLoopTutorial/BasicMat_Colors.mat
-
8Assets/BasicRenderLoopTutorial/BasicMat_Colors.mat.meta
-
74Assets/BasicRenderLoopTutorial/BasicMat_Glass.mat
-
8Assets/BasicRenderLoopTutorial/BasicMat_Glass.mat.meta
-
73Assets/BasicRenderLoopTutorial/BasicMat_Tiles.mat
-
8Assets/BasicRenderLoopTutorial/BasicMat_Tiles.mat.meta
-
12Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs.meta
-
1001Assets/BasicRenderLoopTutorial/BasicRenderLoopScene.unity
-
8Assets/BasicRenderLoopTutorial/BasicRenderLoopScene.unity.meta
-
227Assets/BasicRenderLoopTutorial/BasicRenderLoopShader.shader
-
9Assets/BasicRenderLoopTutorial/BasicRenderLoopShader.shader.meta
-
9Assets/BasicRenderLoopTutorial/Textures.meta
-
14Assets/BasicRenderLoopTutorial/Textures/ColorGrid.png
-
31Assets/BasicRenderLoopTutorial/Textures/ColorGrid.png.meta
-
969Assets/BasicRenderLoopTutorial/Textures/Glass.tif
-
56Assets/BasicRenderLoopTutorial/Textures/Glass.tif.meta
-
338Assets/BasicRenderLoopTutorial/Textures/TilesDiffuse.tif
-
56Assets/BasicRenderLoopTutorial/Textures/TilesDiffuse.tif.meta
-
102Assets/BasicRenderLoopTutorial/Textures/TilesNormal.png
-
100Assets/BasicRenderLoopTutorial/Textures/TilesNormal.png.meta
-
178Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
1001
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 129d9c5b5ed1a6147a8bc74f844e4d2e |
|||
folderAsset: yes |
|||
timeCreated: 1478093341 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_ENTITY_LIGHTING_INCLUDED |
|||
#define UNITY_ENTITY_LIGHTING_INCLUDED |
|||
|
|||
#include "common.hlsl" |
|||
|
|||
// TODO: Check if PI is correctly handled! |
|||
|
|||
// Ref: "Efficient Evaluation of Irradiance Environment Maps" from ShaderX 2 |
|||
float3 SHEvalLinearL0L1(float3 N, float4 shAr, float4 shAg, float4 shAb) |
|||
{ |
|||
float4 vA = float4(N, 1.0); |
|||
|
|||
float3 x1; |
|||
// Linear (L1) + constant (L0) polynomial terms |
|||
x1.r = dot(shAr, vA); |
|||
x1.g = dot(shAg, vA); |
|||
x1.b = dot(shAb, vA); |
|||
|
|||
return x1; |
|||
} |
|||
|
|||
float3 SHEvalLinearL2(float3 N, float4 shBr, float4 shBg, float4 shBb, float4 shC) |
|||
{ |
|||
float3 x2; |
|||
// 4 of the quadratic (L2) polynomials |
|||
float4 vB = N.xyzz * N.yzzx; |
|||
x2.r = dot(shBr, vB); |
|||
x2.g = dot(shBg, vB); |
|||
x2.b = dot(shBb, vB); |
|||
|
|||
// Final (5th) quadratic (L2) polynomial |
|||
float vC = N.x * N.x - N.y * N.y; |
|||
float3 x3 = shC.rgb * vC; |
|||
|
|||
return x2 + x3; |
|||
} |
|||
|
|||
float3 SampleSH9(float4 SHCoefficients[7], float3 N) |
|||
{ |
|||
float4 shAr = SHCoefficients[0]; |
|||
float4 shAg = SHCoefficients[1]; |
|||
float4 shAb = SHCoefficients[2]; |
|||
float4 shBr = SHCoefficients[3]; |
|||
float4 shBg = SHCoefficients[4]; |
|||
float4 shBb = SHCoefficients[5]; |
|||
float4 shCr = SHCoefficients[6]; |
|||
|
|||
// Linear + constant polynomial terms |
|||
float3 res = SHEvalLinearL0L1(N, shAr, shAg, shAb); |
|||
|
|||
// Quadratic polynomials |
|||
res += SHEvalLinearL2(N, shBr, shBg, shBb, shCr); |
|||
|
|||
return res; |
|||
} |
|||
|
|||
// This sample a 3D volume storing SH |
|||
// Volume is store as 3D texture with 4 R, G, B, X set of 4 coefficient store atlas in same 3D texture. X unused. |
|||
// TODO: the packing here is innefficient as we will fetch values far away from each other and they may not fit into the cache |
|||
// Suggest we pack only RGB not X and continuous |
|||
float3 SampleProbeVolumeSH4(TEXTURE3D_ARGS(SHVolumeTexture, SHVolumeSampler), float3 positionWS, float3 normalWS, float4x4 WorldToTexture, float texelSizeX) |
|||
{ |
|||
float3 texCoord = mul(WorldToTexture, float4(positionWS, 1.0)).xyz; |
|||
// Each component is store in the same texture 3D. Each use one quater on the x axis |
|||
// Here we get R component then increase by step size (0.25) to get other component. This assume 4 component |
|||
// but last one is not used. |
|||
// Clamp to edge of the "internal" texture, as R is from half texel to size of R texture minus half texel. |
|||
// This avoid leaking |
|||
texCoord.x = clamp(texCoord.x * 0.25, 0.5 * texelSizeX, 0.25 - 0.5 * texelSizeX); |
|||
|
|||
float4 shAr = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord); |
|||
texCoord.x += 0.25; |
|||
float4 shAg = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord); |
|||
texCoord.x += 0.25; |
|||
float4 shAb = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord); |
|||
|
|||
return SHEvalLinearL0L1(normalWS, shAr, shAg, shAb); |
|||
} |
|||
|
|||
// Following functions are to sample enlighten lightmaps (or lightmaps encoded the same way as our |
|||
// enlighten implementation). They assume use of RGB9E5 for illuminance map. |
|||
// It is required for other platform that aren't supporting this format to implement variant of these functions |
|||
// (But these kind of platform should use regular render loop and not news shaders). |
|||
|
|||
float3 SampleSingleLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), float2 uv, float4 transform) |
|||
{ |
|||
// transform is scale and bias |
|||
uv = uv * transform.xy + transform.zw; |
|||
// Remark: Lightmap is RGB9E5 |
|||
return SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgb; |
|||
} |
|||
|
|||
float3 SampleDirectionalLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), TEXTURE2D_ARGS(lightmapDirTex, lightmapDirSampler), float2 uv, float4 transform, float3 normalWS) |
|||
{ |
|||
// In directional mode Enlighten bakes dominant light direction |
|||
// in a way, that using it for half Lambert and then dividing by a "rebalancing coefficient" |
|||
// gives a result close to plain diffuse response lightmaps, but normalmapped. |
|||
|
|||
// Note that dir is not unit length on purpose. Its length is "directionality", like |
|||
// for the directional specular lightmaps. |
|||
|
|||
// transform is scale and bias |
|||
uv = uv * transform.xy + transform.zw; |
|||
|
|||
float4 direction = SAMPLE_TEXTURE2D(lightmapDirTex, lightmapDirSampler, uv); |
|||
// Remark: Lightmap is RGB9E5 |
|||
float3 illuminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgb; |
|||
float halfLambert = dot(normalWS, direction.xyz - 0.5) + 0.5; |
|||
return illuminance * halfLambert / max(1e-4, direction.w); |
|||
} |
|||
|
|||
#endif // UNITY_ENTITY_LIGHTING_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 0303be75670325342b4bf5697686e77b |
|||
timeCreated: 1477930471 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: anisoTest |
|||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} |
|||
m_ShaderKeywords: _EMISSION |
|||
m_LightmapFlags: 1 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
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} |
|
|||
fileFormatVersion: 2 |
|||
guid: eaec57fbf2cf08c4e8f4b6322cb0a015 |
|||
timeCreated: 1478226940 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: BasicMat_Colors |
|||
m_Shader: {fileID: 4800000, guid: 6d46db48cdecd4d4cbc2b28521fa4feb, type: 3} |
|||
m_ShaderKeywords: _EMISSION _METALLICGLOSSMAP |
|||
m_LightmapFlags: 1 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
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: 2, y: 2} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 2800000, guid: 4e96aadeab75a4745b17d60a1fea54c5, type: 3} |
|||
m_Scale: {x: 2, y: 2} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 2800000, guid: 4e96aadeab75a4745b17d60a1fea54c5, type: 3} |
|||
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.474 |
|||
- _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} |
|
|||
fileFormatVersion: 2 |
|||
guid: d3d4ee74007ca504baacdf86a59dd991 |
|||
timeCreated: 1478093906 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: BasicMat_Glass |
|||
m_Shader: {fileID: 4800000, guid: 6d46db48cdecd4d4cbc2b28521fa4feb, type: 3} |
|||
m_ShaderKeywords: _ALPHABLEND_ON _EMISSION _METALLICGLOSSMAP |
|||
m_LightmapFlags: 1 |
|||
m_CustomRenderQueue: 3000 |
|||
stringTagMap: |
|||
RenderType: Transparent |
|||
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: 2, y: 2} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 2800000, guid: 894ecea3849c1417180f79a5ca555a6a, type: 3} |
|||
m_Scale: {x: 2, y: 2} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 2800000, guid: 894ecea3849c1417180f79a5ca555a6a, type: 3} |
|||
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: 10 |
|||
- _GlossMapScale: 1 |
|||
- _Glossiness: 0.474 |
|||
- _GlossyReflections: 1 |
|||
- _Metallic: 0 |
|||
- _Mode: 2 |
|||
- _OcclusionStrength: 1 |
|||
- _Parallax: 0.02 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 5 |
|||
- _UVSec: 0 |
|||
- _ZWrite: 0 |
|||
m_Colors: |
|||
- _Color: {r: 1, g: 1, b: 1, a: 1} |
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2fee9f51314ef4046b13d8291efdbc6d |
|||
timeCreated: 1478093906 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: BasicMat_Tiles |
|||
m_Shader: {fileID: 4800000, guid: 6d46db48cdecd4d4cbc2b28521fa4feb, type: 3} |
|||
m_ShaderKeywords: _EMISSION |
|||
m_LightmapFlags: 1 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
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: 2, y: 2} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 2800000, guid: 57e020d5e89e349a7b1db77f3f80db54, type: 3} |
|||
m_Scale: {x: 2, y: 2} |
|||
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.474 |
|||
- _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} |
|
|||
fileFormatVersion: 2 |
|||
guid: fe33d2a6bf672f44b8cc1f2da95e8454 |
|||
timeCreated: 1478093906 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 22228a1bd982b864ea6c84db2fc11dd1 |
|||
timeCreated: 1478093647 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Assets/BasicRenderLoopTutorial/BasicRenderLoopScene.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 3b0ce1a6123f2ad4dafc215e41e43949 |
|||
timeCreated: 1478094608 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Example shader for a scriptable render loop that calculates multiple lights |
|||
// in a single forward-rendered shading pass. Uses same PBR shading model as the |
|||
// Standard shader. |
|||
// |
|||
// The parameters and inspector of the shader are the same as Standard shader, |
|||
// for easier experimentation. |
|||
Shader "RenderLoop/Basic/Standard" |
|||
{ |
|||
// Properties is just a copy of Standard.shader. Our example shader does not use all of them, |
|||
// but the inspector UI expects all these to exist. |
|||
Properties |
|||
{ |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_MainTex("Albedo", 2D) = "white" {} |
|||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5 |
|||
_GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0 |
|||
[Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0 |
|||
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0 |
|||
_MetallicGlossMap("Metallic", 2D) = "white" {} |
|||
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 |
|||
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 |
|||
_BumpScale("Scale", Float) = 1.0 |
|||
_BumpMap("Normal Map", 2D) = "bump" {} |
|||
_Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02 |
|||
_ParallaxMap ("Height Map", 2D) = "black" {} |
|||
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0 |
|||
_OcclusionMap("Occlusion", 2D) = "white" {} |
|||
_EmissionColor("Color", Color) = (0,0,0) |
|||
_EmissionMap("Emission", 2D) = "white" {} |
|||
_DetailMask("Detail Mask", 2D) = "white" {} |
|||
_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} |
|||
_DetailNormalMapScale("Scale", Float) = 1.0 |
|||
_DetailNormalMap("Normal Map", 2D) = "bump" {} |
|||
[Enum(UV0,0,UV1,1)] _UVSec("UV Set for secondary textures", Float) = 0 |
|||
[HideInInspector] _Mode("__mode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite("__zw", Float) = 1.0 |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType" = "Opaque" "PerformanceChecks" = "False" } |
|||
LOD 300 |
|||
|
|||
// Include forward (base + additive) pass from regular Standard shader. |
|||
// They are not used by the scriptable render loop; only here so that |
|||
// if we turn off our example loop, then regular forward rendering kicks in |
|||
// and objects look just like with a Standard shader. |
|||
UsePass "Standard/FORWARD" |
|||
UsePass "Standard/FORWARD_DELTA" |
|||
|
|||
|
|||
// Multiple lights at once pass, for our example Basic render loop. |
|||
Pass |
|||
{ |
|||
Tags { "LightMode" = "BasicPass" } |
|||
|
|||
// Use same blending / depth states as Standard shader |
|||
Blend[_SrcBlend][_DstBlend] |
|||
ZWrite[_ZWrite] |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma shader_feature _METALLICGLOSSMAP |
|||
#include "UnityCG.cginc" |
|||
#include "UnityStandardBRDF.cginc" |
|||
#include "UnityStandardUtils.cginc" |
|||
|
|||
|
|||
// Global lighting data (setup from C# code once per frame). |
|||
CBUFFER_START(GlobalLightData) |
|||
// The variables are very similar to built-in unity_LightColor, unity_LightPosition, |
|||
// unity_LightAtten, unity_SpotDirection as used by the VertexLit shaders, except here |
|||
// we use world space positions instead of view space. |
|||
half4 globalLightColor[8]; |
|||
float4 globalLightPos[8]; |
|||
float4 globalLightSpotDir[8]; |
|||
float4 globalLightAtten[8]; |
|||
int4 globalLightCount; |
|||
// Global ambient/SH probe, similar to unity_SH* built-in variables. |
|||
float4 globalSH[7]; |
|||
CBUFFER_END |
|||
|
|||
|
|||
// Surface inputs for evaluating Standard BRDF |
|||
struct SurfaceInputData |
|||
{ |
|||
half3 diffColor, specColor; |
|||
half oneMinusReflectivity, smoothness; |
|||
}; |
|||
|
|||
|
|||
// Compute attenuation & illumination from one light |
|||
half3 EvaluateOneLight(int idx, float3 positionWS, half3 normalWS, half3 eyeVec, SurfaceInputData s) |
|||
{ |
|||
// direction to light |
|||
float3 dirToLight = globalLightPos[idx].xyz; |
|||
dirToLight -= positionWS * globalLightPos[idx].w; |
|||
// distance attenuation |
|||
float att = 1.0; |
|||
float distSqr = dot(dirToLight, dirToLight); |
|||
att /= (1.0 + globalLightAtten[idx].z * distSqr); |
|||
if (globalLightPos[idx].w != 0 && distSqr > globalLightAtten[idx].w) att = 0.0; // set to 0 if outside of range |
|||
distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light |
|||
dirToLight *= rsqrt(distSqr); |
|||
// spotlight angular attenuation |
|||
float rho = max(dot(dirToLight, globalLightSpotDir[idx].xyz), 0.0); |
|||
float spotAtt = (rho - globalLightAtten[idx].x) * globalLightAtten[idx].y; |
|||
att *= saturate(spotAtt); |
|||
|
|||
// Super simple diffuse lighting instead of PBR would be this: |
|||
//half ndotl = max(dot(normalWS, dirToLight), 0.0); |
|||
//half3 color = ndotl * s.diffColor * globalLightColor[idx].rgb; |
|||
//return color * att; |
|||
|
|||
// Fill in light & indirect structures, and evaluate Standard BRDF |
|||
UnityLight light; |
|||
light.color = globalLightColor[idx].rgb * att; |
|||
light.dir = dirToLight; |
|||
UnityIndirect indirect; |
|||
indirect.diffuse = 0; |
|||
indirect.specular = 0; |
|||
half4 c = BRDF1_Unity_PBS(s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, normalWS, -eyeVec, light, indirect); |
|||
return c.rgb; |
|||
} |
|||
|
|||
|
|||
// Evaluate 2nd order spherical harmonics, given normalized world space direction. |
|||
// Similar to ShadeSH9 in UnityCG.cginc |
|||
half3 EvaluateSH(half3 n) |
|||
{ |
|||
half3 res; |
|||
half4 normal = half4(n, 1); |
|||
// Linear (L1) + constant (L0) polynomial terms |
|||
res.r = dot(globalSH[0], normal); |
|||
res.g = dot(globalSH[1], normal); |
|||
res.b = dot(globalSH[2], normal); |
|||
// 4 of the quadratic (L2) polynomials |
|||
half4 vB = normal.xyzz * normal.yzzx; |
|||
res.r += dot(globalSH[3], vB); |
|||
res.g += dot(globalSH[4], vB); |
|||
res.b += dot(globalSH[5], vB); |
|||
// Final (5th) quadratic (L2) polynomial |
|||
half vC = normal.x*normal.x - normal.y*normal.y; |
|||
res += globalSH[6].rgb * vC; |
|||
return res; |
|||
} |
|||
|
|||
|
|||
// Vertex shader |
|||
struct v2f |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
float3 positionWS : TEXCOORD1; |
|||
float3 normalWS : TEXCOORD2; |
|||
float4 hpos : SV_POSITION; |
|||
}; |
|||
|
|||
float4 _MainTex_ST; |
|||
|
|||
v2f vert(appdata_base v) |
|||
{ |
|||
v2f o; |
|||
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex); |
|||
o.hpos = UnityObjectToClipPos(v.vertex); |
|||
o.positionWS = mul(unity_ObjectToWorld, v.vertex).xyz; |
|||
o.normalWS = UnityObjectToWorldNormal(v.normal); |
|||
return o; |
|||
} |
|||
|
|||
|
|||
|
|||
sampler2D _MainTex; |
|||
sampler2D _MetallicGlossMap; |
|||
float _Metallic; |
|||
float _Glossiness; |
|||
|
|||
|
|||
// Fragment shader |
|||
half4 frag(v2f i) : SV_Target |
|||
{ |
|||
i.normalWS = normalize(i.normalWS); |
|||
half3 eyeVec = normalize(i.positionWS - _WorldSpaceCameraPos); |
|||
|
|||
// Sample textures |
|||
half4 diffuseAlbedo = tex2D(_MainTex, i.uv); |
|||
half2 metalSmooth; |
|||
#ifdef _METALLICGLOSSMAP |
|||
metalSmooth = tex2D(_MetallicGlossMap, i.uv).ra; |
|||
#else |
|||
metalSmooth.r = _Metallic; |
|||
metalSmooth.g = _Glossiness; |
|||
#endif |
|||
|
|||
// Fill in surface input structure |
|||
SurfaceInputData s; |
|||
s.diffColor = DiffuseAndSpecularFromMetallic(diffuseAlbedo.rgb, metalSmooth.x, s.specColor, s.oneMinusReflectivity); |
|||
s.smoothness = metalSmooth.y; |
|||
|
|||
// Ambient lighting |
|||
half4 color = half4(0,0,0, diffuseAlbedo.a); |
|||
UnityLight light; |
|||
light.color = 0; |
|||
light.dir = 0; |
|||
UnityIndirect indirect; |
|||
indirect.diffuse = EvaluateSH(i.normalWS); |
|||
indirect.specular = 0; |
|||
color.rgb += BRDF1_Unity_PBS(s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, i.normalWS, -eyeVec, light, indirect); |
|||
|
|||
// Add illumination from all lights |
|||
for (int il = 0; il < globalLightCount.x; ++il) |
|||
{ |
|||
color.rgb += EvaluateOneLight(il, i.positionWS, i.normalWS, eyeVec, s); |
|||
} |
|||
return color; |
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
CustomEditor "StandardShaderGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6d46db48cdecd4d4cbc2b28521fa4feb |
|||
timeCreated: 1478093850 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7cb98251ab4712a4fafbd54b0606ea87 |
|||
folderAsset: yes |
|||
timeCreated: 1478162472 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e96aadeab75a4745b17d60a1fea54c5 |
|||
TextureImporter: |
|||
importerVersion: 2 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
correctGamma: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.250000 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 1 |
|||
generateCubemap: 0 |
|||
textureFormat: -1 |
|||
maxTextureSize: 1024 |
|||
textureSettings: |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1.000000 |
|||
wrapMode: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
textureType: 0 |
|||
buildTargetSettings: [] |
969
Assets/BasicRenderLoopTutorial/Textures/Glass.tif
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 894ecea3849c1417180f79a5ca555a6a |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 2 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
linearTexture: 0 |
|||
correctGamma: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapFadeDistanceStart: 2 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 1 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 0 |
|||
cubemapConvolution: 0 |
|||
cubemapConvolutionSteps: 7 |
|||
cubemapConvolutionExponent: 1.5 |
|||
seamlessCubemap: 0 |
|||
textureFormat: -1 |
|||
maxTextureSize: 512 |
|||
textureSettings: |
|||
filterMode: 1 |
|||
aniso: 1 |
|||
mipBias: 0 |
|||
wrapMode: 0 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
rGBM: 0 |
|||
compressionQuality: 50 |
|||
allowsAlphaSplitting: 0 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
buildTargetSettings: [] |
|||
spriteSheet: |
|||
sprites: [] |
|||
outline: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
338
Assets/BasicRenderLoopTutorial/Textures/TilesDiffuse.tif
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 57e020d5e89e349a7b1db77f3f80db54 |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 2 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
linearTexture: 0 |
|||
correctGamma: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapFadeDistanceStart: 2 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 1 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 0 |
|||
cubemapConvolution: 0 |
|||
cubemapConvolutionSteps: 7 |
|||
cubemapConvolutionExponent: 1.5 |
|||
seamlessCubemap: 0 |
|||
textureFormat: -1 |
|||
maxTextureSize: 1024 |
|||
textureSettings: |
|||
filterMode: 1 |
|||
aniso: 1 |
|||
mipBias: 0 |
|||
wrapMode: 0 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
rGBM: 0 |
|||
compressionQuality: 50 |
|||
allowsAlphaSplitting: 0 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
buildTargetSettings: [] |
|||
spriteSheet: |
|||
sprites: [] |
|||
outline: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 248293ea5aa814673970690d6f0707f1 |
|||
timeCreated: 1468422114 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapFadeDistanceStart: 2 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 1 |
|||
externalNormalMap: 1 |
|||
heightScale: 0.213871 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 0 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: -1 |
|||
maxTextureSize: 1024 |
|||
textureSettings: |
|||
filterMode: 1 |
|||
aniso: 1 |
|||
mipBias: 0 |
|||
wrapMode: 0 |
|||
nPOTScale: 0 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 1 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 1024 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
- buildTarget: iPhone |
|||
maxTextureSize: 1024 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
- buildTarget: Standalone |
|||
maxTextureSize: 1024 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
- buildTarget: tvOS |
|||
maxTextureSize: 1024 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
- buildTarget: WebGL |
|||
maxTextureSize: 1024 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
// Very basic scriptable rendering loop example:
|
|||
// - Use with BasicRenderLoopShader.shader (the loop expects "BasicPass" pass type to exist)
|
|||
// - Supports up to 8 enabled lights in the scene (directional, point or spot)
|
|||
// - Does the same physically based BRDF as the Standard shader
|
|||
// - No shadows
|
|||
// - This loop also does not setup lightmaps, light probes, reflection probes or light cookies
|
|||
|
|||
[ExecuteInEditMode] |
|||
public class BasicRenderLoop : MonoBehaviour |
|||
{ |
|||
private ShaderPassName shaderPassBasic; |
|||
|
|||
public void OnEnable () |
|||
{ |
|||
shaderPassBasic = new ShaderPassName ("BasicPass"); |
|||
RenderLoop.renderLoopDelegate += Render; |
|||
} |
|||
|
|||
public void OnDisable () |
|||
{ |
|||
RenderLoop.renderLoopDelegate -= Render; |
|||
} |
|||
|
|||
|
|||
// Main entry point for our scriptable render loop
|
|||
bool Render (Camera[] cameras, RenderLoop loop) |
|||
{ |
|||
foreach (var camera in cameras) |
|||
{ |
|||
// Culling
|
|||
CullingParameters cullingParams; |
|||
if (!CullResults.GetCullingParameters (camera, out cullingParams)) |
|||
continue; |
|||
CullResults cull = CullResults.Cull (ref cullingParams, loop); |
|||
|
|||
// Setup camera for rendering (sets render target, view/projection matrices and other
|
|||
// per-camera built-in shader variables).
|
|||
loop.SetupCameraProperties (camera); |
|||
|
|||
// Setup global lighting shader variables
|
|||
SetupLightShaderVariables (cull.visibleLights, loop); |
|||
|
|||
// Draw opaque objects using BasicPass shader pass
|
|||
var settings = new DrawRendererSettings (cull, camera, shaderPassBasic); |
|||
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh; |
|||
settings.inputFilter.SetQueuesOpaque (); |
|||
loop.DrawRenderers (ref settings); |
|||
|
|||
// Draw skybox
|
|||
loop.DrawSkybox (camera); |
|||
|
|||
// Draw transparent objects using BasicPass shader pass
|
|||
settings.sorting.sortOptions = SortOptions.BackToFront; // sort back to front
|
|||
settings.inputFilter.SetQueuesTransparent (); |
|||
loop.DrawRenderers (ref settings); |
|||
|
|||
loop.Submit (); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
// Setup lighting variables for shader to use
|
|||
static void SetupLightShaderVariables (VisibleLight[] lights, RenderLoop loop) |
|||
{ |
|||
// We only support up to 8 visible lights here. More complex approaches would
|
|||
// be doing some sort of per-object light setups, but here we go for simplest possible
|
|||
// approach.
|
|||
const int kMaxLights = 8; |
|||
// Just take first 8 lights. Possible improvements: sort lights by intensity or distance
|
|||
// to the viewer, so that "most important" lights in the scene are picked, and not the 8
|
|||
// that happened to be first.
|
|||
int lightCount = Mathf.Min (lights.Length, kMaxLights); |
|||
|
|||
// Prepare light data
|
|||
Vector4[] lightColors = new Vector4[kMaxLights]; |
|||
Vector4[] lightPositions = new Vector4[kMaxLights]; |
|||
Vector4[] lightSpotDirections = new Vector4[kMaxLights]; |
|||
Vector4[] lightAtten = new Vector4[kMaxLights]; |
|||
for (var i = 0; i < lightCount; ++i) |
|||
{ |
|||
VisibleLight light = lights[i]; |
|||
lightColors[i] = light.finalColor; |
|||
if (light.lightType == LightType.Directional) |
|||
{ |
|||
// light position for directional lights is: (-direction, 0)
|
|||
var dir = light.localToWorld.GetColumn (2); |
|||
lightPositions[i] = new Vector4 (-dir.x, -dir.y, -dir.z, 0); |
|||
} |
|||
else |
|||
{ |
|||
// light position for point/spot lights is: (position, 1)
|
|||
var pos = light.localToWorld.GetColumn (3); |
|||
lightPositions[i] = new Vector4 (pos.x, pos.y, pos.z, 1); |
|||
} |
|||
// attenuation set in a way where distance attenuation can be computed:
|
|||
// float lengthSq = dot(toLight, toLight);
|
|||
// float atten = 1.0 / (1.0 + lengthSq * LightAtten[i].z);
|
|||
// and spot cone attenuation:
|
|||
// float rho = max (0, dot(normalize(toLight), SpotDirection[i].xyz));
|
|||
// float spotAtt = (rho - LightAtten[i].x) * LightAtten[i].y;
|
|||
// spotAtt = saturate(spotAtt);
|
|||
// and the above works for all light types, i.e. spot light code works out
|
|||
// to correct math for point & directional lights as well.
|
|||
|
|||
float rangeSq = light.range * light.range; |
|||
|
|||
float quadAtten = (light.lightType == LightType.Directional) ? 0.0f : 25.0f / rangeSq; |
|||
|
|||
// spot direction & attenuation
|
|||
if (light.lightType == LightType.Spot) |
|||
{ |
|||
var dir = light.localToWorld.GetColumn (2); |
|||
lightSpotDirections[i] = new Vector4 (-dir.x, -dir.y, -dir.z, 0); |
|||
|
|||
float radAngle = Mathf.Deg2Rad * light.spotAngle; |
|||
float cosTheta = Mathf.Cos (radAngle * 0.25f); |
|||
float cosPhi = Mathf.Cos (radAngle * 0.5f); |
|||
float cosDiff = cosTheta - cosPhi; |
|||
lightAtten[i] = new Vector4 (cosPhi, (cosDiff != 0.0f) ? 1.0f / cosDiff : 1.0f, quadAtten, rangeSq); |
|||
} |
|||
else |
|||
{ |
|||
// non-spot light
|
|||
lightSpotDirections[i] = new Vector4 (0, 0, 1, 0); |
|||
lightAtten[i] = new Vector4 (-1, 1, quadAtten, rangeSq); |
|||
} |
|||
} |
|||
|
|||
// ambient lighting spherical harmonics values
|
|||
const int kSHCoefficients = 7; |
|||
Vector4[] shConstants = new Vector4[kSHCoefficients]; |
|||
SphericalHarmonicsL2 ambientSH = RenderSettings.ambientProbe * RenderSettings.ambientIntensity; |
|||
GetShaderConstantsFromNormalizedSH (ref ambientSH, shConstants); |
|||
|
|||
// setup global shader variables to contain all the data computed above
|
|||
CommandBuffer cmd = new CommandBuffer(); |
|||
cmd.SetGlobalVectorArray ("globalLightColor", lightColors); |
|||
cmd.SetGlobalVectorArray ("globalLightPos", lightPositions); |
|||
cmd.SetGlobalVectorArray ("globalLightSpotDir", lightSpotDirections); |
|||
cmd.SetGlobalVectorArray ("globalLightAtten", lightAtten); |
|||
cmd.SetGlobalVector ("globalLightCount", new Vector4 (lightCount, 0, 0, 0)); |
|||
cmd.SetGlobalVectorArray ("globalSH", shConstants); |
|||
loop.ExecuteCommandBuffer (cmd); |
|||
cmd.Dispose (); |
|||
} |
|||
|
|||
|
|||
// Prepare L2 spherical harmonics values for efficient evaluation in a shader
|
|||
static void GetShaderConstantsFromNormalizedSH (ref SphericalHarmonicsL2 ambientProbe, Vector4[] outCoefficients) |
|||
{ |
|||
for (int channelIdx = 0; channelIdx < 3; ++channelIdx) |
|||
{ |
|||
// Constant + Linear
|
|||
// In the shader we multiply the normal is not swizzled, so it's normal.xyz.
|
|||
// Swizzle the coefficients to be in { x, y, z, DC } order.
|
|||
outCoefficients[channelIdx].x = ambientProbe[channelIdx, 3]; |
|||
outCoefficients[channelIdx].y = ambientProbe[channelIdx, 1]; |
|||
outCoefficients[channelIdx].z = ambientProbe[channelIdx, 2]; |
|||
outCoefficients[channelIdx].w = ambientProbe[channelIdx, 0] - ambientProbe[channelIdx, 6]; |
|||
// Quadratic polynomials
|
|||
outCoefficients[channelIdx + 3].x = ambientProbe[channelIdx, 4]; |
|||
outCoefficients[channelIdx + 3].y = ambientProbe[channelIdx, 5]; |
|||
outCoefficients[channelIdx + 3].z = ambientProbe[channelIdx, 6] * 3.0f; |
|||
outCoefficients[channelIdx + 3].w = ambientProbe[channelIdx, 7]; |
|||
} |
|||
// Final quadratic polynomial
|
|||
outCoefficients[6].x = ambientProbe[0, 8]; |
|||
outCoefficients[6].y = ambientProbe[1, 8]; |
|||
outCoefficients[6].z = ambientProbe[2, 8]; |
|||
outCoefficients[6].w = 1.0f; |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue