浏览代码
Deleted LightweightUtils. Moved work to Core (partial class). Normalized files with the autoformat tool to be consistent to the convention.
/main
Deleted LightweightUtils. Moved work to Core (partial class). Normalized files with the autoformat tool to be consistent to the convention.
/main
Felipe Lira
7 年前
当前提交
5d3094de
共有 10 个文件被更改,包括 167 次插入 和 193 次删除
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineEditorResources.cs
-
6ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs
-
46ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
134ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
-
4ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs
-
4ScriptableRenderPipeline/LightweightPipeline/LWRP/SceneViewDrawMode.cs
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl
-
13ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs.meta
-
147ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 1556a6d19597541c8bed4b90c704fb06 |
|||
timeCreated: 1505115136 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class CameraComparer : IComparer<Camera> |
|||
{ |
|||
public int Compare(Camera lhs, Camera rhs) |
|||
{ |
|||
return (int)(lhs.depth - rhs.depth); |
|||
} |
|||
} |
|||
|
|||
[Flags] |
|||
public enum FrameRenderingConfiguration |
|||
{ |
|||
None = 0, |
|||
Stereo = (1 << 0), |
|||
Msaa = (1 << 1), |
|||
BeforeTransparentPostProcess = (1 << 2), |
|||
PostProcess = (1 << 3), |
|||
DepthPrePass = (1 << 4), |
|||
DepthCopy = (1 << 5), |
|||
DefaultViewport = (1 << 6), |
|||
IntermediateTexture = (1 << 7) |
|||
} |
|||
|
|||
public static class LightweightUtils |
|||
{ |
|||
static Mesh s_FullscreenMesh = null; |
|||
public static Mesh fullscreenMesh |
|||
{ |
|||
get |
|||
{ |
|||
if (s_FullscreenMesh != null) |
|||
return s_FullscreenMesh; |
|||
|
|||
float topV = 1.0f; |
|||
float bottomV = 0.0f; |
|||
|
|||
Mesh mesh = new Mesh {name = "Fullscreen Quad"}; |
|||
mesh.SetVertices(new List<Vector3> |
|||
{ |
|||
new Vector3(-1.0f, -1.0f, 0.0f), |
|||
new Vector3(-1.0f, 1.0f, 0.0f), |
|||
new Vector3( 1.0f, -1.0f, 0.0f), |
|||
new Vector3( 1.0f, 1.0f, 0.0f) |
|||
}); |
|||
|
|||
mesh.SetUVs(0, new List<Vector2> |
|||
{ |
|||
new Vector2(0.0f, bottomV), |
|||
new Vector2(0.0f, topV), |
|||
new Vector2(1.0f, bottomV), |
|||
new Vector2(1.0f, topV) |
|||
}); |
|||
|
|||
mesh.SetIndices(new[] { 0, 1, 2, 2, 1, 3 }, MeshTopology.Triangles, 0, false); |
|||
mesh.UploadMeshData(true); |
|||
return mesh; |
|||
} |
|||
} |
|||
|
|||
public static void DrawFullScreen(CommandBuffer commandBuffer, Material material, |
|||
MaterialPropertyBlock properties = null, int shaderPassId = 0) |
|||
{ |
|||
commandBuffer.DrawMesh(fullscreenMesh, Matrix4x4.identity, material, 0, shaderPassId, properties); |
|||
} |
|||
|
|||
public static void StartStereoRendering(Camera camera, ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration) |
|||
{ |
|||
if (HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo)) |
|||
context.StartMultiEye(camera); |
|||
} |
|||
|
|||
public static void StopStereoRendering(Camera camera, ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration) |
|||
{ |
|||
if (HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo)) |
|||
context.StopMultiEye(camera); |
|||
} |
|||
|
|||
public static void GetLightCookieMatrix(VisibleLight light, out Matrix4x4 cookieMatrix) |
|||
{ |
|||
cookieMatrix = Matrix4x4.Inverse(light.localToWorld); |
|||
|
|||
if (light.lightType == LightType.Directional) |
|||
{ |
|||
float scale = 1.0f / light.light.cookieSize; |
|||
|
|||
// apply cookie scale and offset by 0.5 to convert from [-0.5, 0.5] to texture space [0, 1]
|
|||
Vector4 row0 = cookieMatrix.GetRow(0); |
|||
Vector4 row1 = cookieMatrix.GetRow(1); |
|||
cookieMatrix.SetRow(0, new Vector4(row0.x * scale, row0.y * scale, row0.z * scale, row0.w * scale + 0.5f)); |
|||
cookieMatrix.SetRow(1, new Vector4(row1.x * scale, row1.y * scale, row1.z * scale, row1.w * scale + 0.5f)); |
|||
} |
|||
else if (light.lightType == LightType.Spot) |
|||
{ |
|||
// we want out.w = 2.0 * in.z / m_CotanHalfSpotAngle
|
|||
// c = cotHalfSpotAngle
|
|||
// 1 0 0 0
|
|||
// 0 1 0 0
|
|||
// 0 0 1 0
|
|||
// 0 0 2/c 0
|
|||
// the "2" will be used to scale .xy for the cookie as in .xy/2 + 0.5
|
|||
float scale = 1.0f / light.range; |
|||
float halfSpotAngleRad = Mathf.Deg2Rad * light.spotAngle * 0.5f; |
|||
float cs = Mathf.Cos(halfSpotAngleRad); |
|||
float ss = Mathf.Sin(halfSpotAngleRad); |
|||
float cotHalfSpotAngle = cs / ss; |
|||
|
|||
Matrix4x4 scaleMatrix = Matrix4x4.identity; |
|||
scaleMatrix.m00 = scaleMatrix.m11 = scaleMatrix.m22 = scale; |
|||
scaleMatrix.m33 = 0.0f; |
|||
scaleMatrix.m32 = scale * (2.0f / cotHalfSpotAngle); |
|||
|
|||
cookieMatrix = scaleMatrix * cookieMatrix; |
|||
} |
|||
|
|||
// Remaining light types don't support cookies
|
|||
} |
|||
|
|||
public static bool IsSupportedShadowType(LightType lightType) |
|||
{ |
|||
return lightType == LightType.Directional || lightType == LightType.Spot; |
|||
} |
|||
|
|||
public static bool IsSupportedCookieType(LightType lightType) |
|||
{ |
|||
return lightType == LightType.Directional || lightType == LightType.Spot; |
|||
} |
|||
|
|||
public static bool PlatformSupportsMSAABackBuffer() |
|||
{ |
|||
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SAMSUNGTV
|
|||
return true; |
|||
#else
|
|||
return false; |
|||
#endif
|
|||
} |
|||
|
|||
public static bool HasFlag(FrameRenderingConfiguration mask, FrameRenderingConfiguration flag) |
|||
{ |
|||
return (mask & flag) != 0; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue