浏览代码

Create branch for renderpass test scene

/mikko-renderpass
Mikko Strandborg 7 年前
当前提交
fa549add
共有 32 个文件被更改,包括 3498 次插入14 次删除
  1. 4
      Assets/TestScenes/HDTest/GraphicTest/Two Sided/Prefabs/Materials.meta
  2. 4
      Assets/TestScenes/HDTest/LayeredLitTest/Mesh/Materials.meta
  3. 16
      ProjectSettings/EditorBuildSettings.asset
  4. 2
      ProjectSettings/GraphicsSettings.asset
  5. 4
      ProjectSettings/ProjectSettings.asset
  6. 9
      Assets/RenderPassHDRRenderLoop.meta
  7. 73
      Assets/RenderPassHDRRenderLoop/BasicMat_Colors.mat
  8. 9
      Assets/RenderPassHDRRenderLoop/BasicMat_Colors.mat.meta
  9. 74
      Assets/RenderPassHDRRenderLoop/BasicMat_Glass.mat
  10. 9
      Assets/RenderPassHDRRenderLoop/BasicMat_Glass.mat.meta
  11. 73
      Assets/RenderPassHDRRenderLoop/BasicMat_Tiles.mat
  12. 9
      Assets/RenderPassHDRRenderLoop/BasicMat_Tiles.mat.meta
  13. 14
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.asset
  14. 9
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.asset.meta
  15. 261
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.cs
  16. 12
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.cs.meta
  17. 1001
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopScene.unity
  18. 8
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopScene.unity.meta
  19. 227
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopShader.shader
  20. 9
      Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopShader.shader.meta
  21. 46
      Assets/RenderPassHDRRenderLoop/SimpleTonemapper.shader
  22. 9
      Assets/RenderPassHDRRenderLoop/SimpleTonemapper.shader.meta
  23. 9
      Assets/RenderPassHDRRenderLoop/Textures.meta
  24. 14
      Assets/RenderPassHDRRenderLoop/Textures/ColorGrid.png
  25. 66
      Assets/RenderPassHDRRenderLoop/Textures/ColorGrid.png.meta
  26. 969
      Assets/RenderPassHDRRenderLoop/Textures/Glass.tif
  27. 66
      Assets/RenderPassHDRRenderLoop/Textures/Glass.tif.meta
  28. 338
      Assets/RenderPassHDRRenderLoop/Textures/TilesDiffuse.tif
  29. 66
      Assets/RenderPassHDRRenderLoop/Textures/TilesDiffuse.tif.meta
  30. 102
      Assets/RenderPassHDRRenderLoop/Textures/TilesNormal.png

4
Assets/TestScenes/HDTest/GraphicTest/Two Sided/Prefabs/Materials.meta


fileFormatVersion: 2
guid: 0e2aa881811d0644896d4b5a732945cc
guid: 5eaf4b3efc08d5548a43d9142ca58b31
timeCreated: 1485804900
timeCreated: 1486478081
licenseType: Pro
DefaultImporter:
userData:

4
Assets/TestScenes/HDTest/LayeredLitTest/Mesh/Materials.meta


fileFormatVersion: 2
guid: e8f6ad2e481134b4fa6108a280b52de7
guid: 12cc330c80c82b64fbd52f93cc0742e0
timeCreated: 1484331445
timeCreated: 1486478080
licenseType: Pro
DefaultImporter:
userData:

16
ProjectSettings/EditorBuildSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1045 &1
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1045 &1
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopScene.unity

2
ProjectSettings/GraphicsSettings.asset


m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_CustomRenderPipeline: {fileID: 11400000, guid: e185fecca3c73cd47a09f1092663ef32,
m_CustomRenderPipeline: {fileID: 11400000, guid: 6b90a6c4de9acf440a276d14c6920330,
type: 2}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}

4
ProjectSettings/ProjectSettings.asset


m_DynamicBatching: 0
m_BuildTargetGraphicsAPIs:
- m_BuildTarget: WindowsStandaloneSupport
m_APIs: 0200000001000000
m_Automatic: 1
m_APIs: 150000000200000001000000
m_Automatic: 0
- m_BuildTarget: MacStandaloneSupport
m_APIs: 1000000011000000
m_Automatic: 1

9
Assets/RenderPassHDRRenderLoop.meta


fileFormatVersion: 2
guid: 171f1ce6827ad024488756ab7f88bba0
folderAsset: yes
timeCreated: 1486480658
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

73
Assets/RenderPassHDRRenderLoop/BasicMat_Colors.mat


%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}

9
Assets/RenderPassHDRRenderLoop/BasicMat_Colors.mat.meta


fileFormatVersion: 2
guid: ac5bd18ba6332a54c8eae94fbbcb9e72
timeCreated: 1478093906
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: -1
userData:
assetBundleName:
assetBundleVariant:

74
Assets/RenderPassHDRRenderLoop/BasicMat_Glass.mat


%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}

9
Assets/RenderPassHDRRenderLoop/BasicMat_Glass.mat.meta


fileFormatVersion: 2
guid: a9bb6629ae058b14a8ec0c67c4398e6c
timeCreated: 1478093906
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: -1
userData:
assetBundleName:
assetBundleVariant:

73
Assets/RenderPassHDRRenderLoop/BasicMat_Tiles.mat


%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}

9
Assets/RenderPassHDRRenderLoop/BasicMat_Tiles.mat.meta


fileFormatVersion: 2
guid: 2abaf5136600ab148adbe0b6b697af7c
timeCreated: 1478093906
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: -1
userData:
assetBundleName:
assetBundleVariant:

14
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9f71e4d79e31d8644873e6436d3ed3dc, type: 3}
m_Name: RenderPassHDRRenderLoop
m_EditorClassIdentifier:
m_ToneMapper: {fileID: 4800000, guid: 3be0acbe82afada439627f85f60cc358, type: 3}

9
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.asset.meta


fileFormatVersion: 2
guid: 6b90a6c4de9acf440a276d14c6920330
timeCreated: 1485349998
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

261
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.cs


using System;
using System.Collections.Generic;
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 RenderPassHDRRenderLoop : RenderPipelineAsset
{
#if UNITY_EDITOR
[UnityEditor.MenuItem("RenderPipeline/Create RenderPassHDRRenderLoop")]
static void CreateRenderPassHDRRenderLoop()
{
var instance = ScriptableObject.CreateInstance<RenderPassHDRRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, "Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.asset");
}
#endif
protected override IRenderPipeline InternalCreatePipeline()
{
return new RenderPassHDRRenderLoopInstance(this);
}
protected int m_IntermediateRT;
protected int m_IntermediateZ;
public Shader m_ToneMapper;
protected Material m_ToneMapMat;
public void Build()
{
m_IntermediateRT = Shader.PropertyToID("_CameraHDRTarget");
m_IntermediateZ = Shader.PropertyToID("_CameraHDRDepth");
m_ToneMapMat = new Material(m_ToneMapper);
}
public void Cleanup()
{
}
// Main entry point for our scriptable render loop
public void Render(ScriptableRenderContext context, IEnumerable<Camera> cameras)
{
foreach (var camera in cameras)
{
// Culling
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))
continue;
CullResults cull = CullResults.Cull(ref cullingParams, context);
// Setup camera for rendering (sets render target, view/projection matrices and other
// per-camera built-in shader variables).
context.SetupCameraProperties(camera);
RenderPassSetup rpSetup = new RenderPassSetup(
new RenderPassSetup.SubPass[] {
new RenderPassSetup.SubPass(0, 1),
new RenderPassSetup.SubPass(new int[] { 0 }, new int[] { 2 }, new int[]{ }, new int[]{ }, 3)
},
new RenderPassSetup.Attachment[]
{
new RenderPassSetup.Attachment(new RenderTargetIdentifier(m_IntermediateRT), RenderBufferLoadAction.Clear, RenderBufferStoreAction.DontCare, 0, CubemapFace.Unknown, 0),
new RenderPassSetup.Attachment(new RenderTargetIdentifier(m_IntermediateZ), RenderBufferLoadAction.Clear, RenderBufferStoreAction.DontCare, 0, CubemapFace.Unknown, 0),
new RenderPassSetup.Attachment(new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget), RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, 0, CubemapFace.Unknown, 0),
new RenderPassSetup.Attachment(new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget, true), RenderBufferLoadAction.Clear, RenderBufferStoreAction.DontCare, 0, CubemapFace.Unknown, 0),
}
);
// clear depth buffer
var cmd = new CommandBuffer();
cmd.name = "RenderPass1";
cmd.EnableShaderKeyword("UNITY_HDR_ON");
cmd.GetTemporaryRT(m_IntermediateRT, camera.pixelWidth, camera.pixelHeight, 0, Color.green, 1.0f, FilterMode.Point, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Default, 1, false, true);
cmd.GetTemporaryRT(m_IntermediateZ, camera.pixelWidth, camera.pixelHeight, 24, Color.black, 1.0f, FilterMode.Point, RenderTextureFormat.Depth, RenderTextureReadWrite.Default, 1, false, true);
cmd.BeginRenderPass(rpSetup);
// cmd.ClearRenderTarget(true, false, Color.black);
context.ExecuteCommandBuffer(cmd);
cmd.Release();
// Setup global lighting shader variables
SetupLightShaderVariables(cull.visibleLights, context);
// Draw opaque objects using BasicPass shader pass
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("BasicPass"));
settings.sorting.flags = SortFlags.CommonOpaque;
settings.inputFilter.SetQueuesOpaque();
context.DrawRenderers(ref settings);
// Draw skybox
// context.DrawSkybox(camera);
// Draw transparent objects using BasicPass shader pass
settings.sorting.flags = SortFlags.CommonTransparent;
settings.inputFilter.SetQueuesTransparent();
context.DrawRenderers(ref settings);
cmd = new CommandBuffer();
cmd.name = "RenderPass2";
cmd.NextSubPass();
// cmd.SetGlobalTexture("_UnityFBInput0", new RenderTargetIdentifier(m_IntermediateRT));
cmd.DrawProcedural(new Matrix4x4(), m_ToneMapMat, 0, MeshTopology.Triangles, 3);
cmd.EndRenderPass();
context.ExecuteCommandBuffer(cmd);
cmd.Release();
context.Submit();
}
}
// Setup lighting variables for shader to use
private static void SetupLightShaderVariables(VisibleLight[] lights, ScriptableRenderContext context)
{
// 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);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Prepare L2 spherical harmonics values for efficient evaluation in a shader
private 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;
}
}
public class RenderPassHDRRenderLoopInstance : RenderPipeline
{
private readonly RenderPassHDRRenderLoop m_Owner;
public RenderPassHDRRenderLoopInstance(RenderPassHDRRenderLoop owner)
{
m_Owner = owner;
if (m_Owner != null)
m_Owner.Build();
}
public override void Dispose()
{
base.Dispose();
if (m_Owner != null)
m_Owner.Cleanup();
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);
m_Owner.Render(renderContext, cameras);
}
}

12
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoop.cs.meta


fileFormatVersion: 2
guid: 9f71e4d79e31d8644873e6436d3ed3dc
timeCreated: 1478093647
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopScene.unity
文件差异内容过多而无法显示
查看文件

8
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopScene.unity.meta


fileFormatVersion: 2
guid: a5178921b3c301748b6695113b966728
timeCreated: 1485347783
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

227
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopShader.shader


// 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"
}

9
Assets/RenderPassHDRRenderLoop/RenderPassHDRRenderLoopShader.shader.meta


fileFormatVersion: 2
guid: bb0982ffb7aedb64fa27bca0a4ce1f0b
timeCreated: 1485347783
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

46
Assets/RenderPassHDRRenderLoop/SimpleTonemapper.shader


Shader "Hidden/SimpleTonemapper"
{
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 5.0
#include "UnityCG.cginc"
struct v2f
{
float4 vertex : SV_Position;
};
UNITY_DECLARE_FRAMEBUFFER_INPUT(0);
v2f vert (uint id : SV_VertexID)
{
v2f o;
float2 ouv = float2((id << 1) & 2, id & 2);
o.vertex = float4(ouv * float2(2, -2) + float2(-1, 1), 0, 1);
return o;
}
// sampler2D _MainTex;
half4 frag (v2f i) : SV_Target
{
float _ExposureAdjustment = 0.5;
float4 exp = float4(1.0, 0.8, 0.7, 1.0) * _ExposureAdjustment;
// half4 col = tex2D(_MainTex, i.uv);
half4 col = UNITY_READ_FRAMEBUFFER_INPUT(0, i.vertex);
// half4 col = _UnityFBInput0.Load(int3(i.vertex.xy, 0));
return 1-exp2(-exp * col);
}
ENDCG
}
}
}

9
Assets/RenderPassHDRRenderLoop/SimpleTonemapper.shader.meta


fileFormatVersion: 2
guid: 3be0acbe82afada439627f85f60cc358
timeCreated: 1485350251
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/RenderPassHDRRenderLoop/Textures.meta


fileFormatVersion: 2
guid: a6443c880c7507a4da66252eb5ddf31b
folderAsset: yes
timeCreated: 1478162472
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

14
Assets/RenderPassHDRRenderLoop/Textures/ColorGrid.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 3.7 KiB

66
Assets/RenderPassHDRRenderLoop/Textures/ColorGrid.png.meta


fileFormatVersion: 2
guid: aba467571d5714f4ea09e94f2f54320b
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 1
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
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: 2
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
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
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

969
Assets/RenderPassHDRRenderLoop/Textures/Glass.tif
文件差异内容过多而无法显示
查看文件

66
Assets/RenderPassHDRRenderLoop/Textures/Glass.tif.meta


fileFormatVersion: 2
guid: f2bc0ab01fda17741943a86cb5a12ddc
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 1
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 512
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 0
nPOTScale: 1
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: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 512
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

338
Assets/RenderPassHDRRenderLoop/Textures/TilesDiffuse.tif
文件差异内容过多而无法显示
查看文件

66
Assets/RenderPassHDRRenderLoop/Textures/TilesDiffuse.tif.meta


fileFormatVersion: 2
guid: 4264dbfabdad4924a80d2cba37421ec9
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 1
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 0
nPOTScale: 1
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: 0
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
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

102
Assets/RenderPassHDRRenderLoop/Textures/TilesNormal.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 22 KiB
正在加载...
取消
保存