浏览代码
First set of files
First set of files
First set of files submit to iniate the project and be able to work from home :) This is WIP and files will move/change. For now just a set of file mostly empty, setup name etc.../main
sebastienlagarde
8 年前
当前提交
1ec6d8b9
共有 41 个文件被更改,包括 1198 次插入 和 0 次删除
-
9Assets/ScriptableRenderLoop/ShaderLibrary.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/API.meta
-
8Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl.meta
-
109Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl.meta
-
203Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl.meta
-
69Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl.meta
-
6Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Lighting.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Material.meta
-
148Assets/ScriptableRenderLoop/ShaderLibrary/Material/Material.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Material/Material.hlsl.meta
-
85Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/ParticipatingMedia.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Platform.meta
-
0Assets/ScriptableRenderLoop/ShaderLibrary/Platform/XboxOne.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Platform/XboxOne.hlsl.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Postprocress.meta
-
6Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl.meta
-
6Assets/ScriptableRenderLoop/ShaderLibrary/SHMath.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/SHMath.hlsl.meta
-
6Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl.meta
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Shaders.meta
-
134Assets/ScriptableRenderLoop/ShaderLibrary/Shaders/ShaderVariables.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Shaders/ShaderVariables.hlsl.meta
-
198Assets/ScriptableRenderLoop/ShaderLibrary/Shaders/UnityStandard.shader
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Shaders/UnityStandard.shader.meta
-
35Assets/ScriptableRenderLoop/ShaderLibrary/Shaders/VertexShader.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Shaders/VertexShader.hlsl.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 534c3b565c7ef4248a10594dbdf4faf1 |
|||
folderAsset: yes |
|||
timeCreated: 1472130065 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6fa64bbd0ffaf8843b041c6e42bb5f82 |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_D3D11_INCLUDED |
|||
#define UNITY_D3D11_INCLUDED |
|||
|
|||
// This file assume SHADER_API_D3D11 is defined |
|||
|
|||
#define UNITY_UV_STARTS_AT_TOP 1 |
|||
|
|||
#endif // UNITY_D3D11_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 9c7140d7b956a4547bb71f8ed0dd9049 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_BSDF_INCLUDED |
|||
#define UNITY_BSDF_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Fresnel term |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float F_Schlick(float f0, float f90, float u) |
|||
{ |
|||
float x = 1.0f - u; |
|||
float x5 = x * x; |
|||
x5 = x5 * x5 * x; |
|||
return (f90 - f0) * x5 + f0; // sub mul mul mul sub mad |
|||
} |
|||
|
|||
float F_Schlick(float f0, float u) |
|||
{ |
|||
return F_Schlick(f0, 1.0f, u); |
|||
} |
|||
|
|||
float3 F_Schlick(float3 f0, float f90, float u) |
|||
{ |
|||
float x = 1.0f - u; |
|||
float x5 = x * x; |
|||
x5 = x5 * x5 * x; |
|||
return (f90 - f0) * x5 + f0; // sub mul mul mul sub mad |
|||
} |
|||
|
|||
float3 F_Schlick(float3 f0, float u) |
|||
{ |
|||
return F_Schlick(f0, float3(1.0f, 1.0f, 1.0f), u); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Specular BRDF |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// With analytical light (not image based light) we clamp the minimun roughness to avoid numerical instability. |
|||
#define UNITY_MIN_ROUGHNESS 0.002 |
|||
|
|||
float D_GGX(float NdotH, float roughness) |
|||
{ |
|||
roughness = max(m, UNITY_MIN_ROUGHNESS); |
|||
float a2 = roughness * roughness; |
|||
float f = (NdotH * a2 - NdotH) * NdotH + 1.0f; |
|||
return INV_PI * a2 / (f * f); |
|||
} |
|||
|
|||
// roughnessT -> roughness in tangent direction |
|||
// roughnessB -> roughness in bitangent direction |
|||
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float roughnessT, float roughnessB) |
|||
{ |
|||
// TODO: Do the clamp on the artists parameter |
|||
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH; |
|||
return INV_PI / (roughnessT * roughnessB * f * f); |
|||
} |
|||
|
|||
// Ref: http://jcgt.org/published/0003/02/03/paper.pdf |
|||
float V_SmithJointGGX(float NdotL, float NdotV, float roughness) |
|||
{ |
|||
#if 1 |
|||
// Original formulation: |
|||
// lambda_v = (-1 + sqrt(a2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f; |
|||
// lambda_l = (-1 + sqrt(a2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f; |
|||
// G = 1 / (1 + lambda_v + lambda_l); |
|||
|
|||
// Reorder code to be more optimal |
|||
half a = roughness; |
|||
half a2 = a * a; |
|||
|
|||
half lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2); |
|||
half lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2); |
|||
|
|||
// Simplify visibility term: (2.0f * NdotL * NdotV) / ((4.0f * NdotL * NdotV) * (lambda_v + lambda_l)); |
|||
return 0.5f / (lambdaV + lambdaL); |
|||
#else |
|||
// Approximation of the above formulation (simplify the sqrt, not mathematically correct but close enough) |
|||
half a = roughness; |
|||
half lambdaV = NdotL * (NdotV * (1 - a) + a); |
|||
half lambdaL = NdotV * (NdotL * (1 - a) + a); |
|||
|
|||
return 0.5f / (lambdaV + lambdaL); |
|||
#endif |
|||
} |
|||
|
|||
// TODO: V_ term for aniso GGX from farcry |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Diffuse BRDF - diffuseColor is expected to be multiply by the caller |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float Lambert() |
|||
{ |
|||
return INV_PI; |
|||
} |
|||
|
|||
float DisneyDiffuse(float NdotV, float NdotL, float LdotH, float perceptualRoughness) |
|||
{ |
|||
float fd90 = 0.5 + 2 * LdotH * LdotH * perceptualRoughness; |
|||
// Two schlick fresnel term |
|||
float lightScatter = F_Schlick(1.0f, fd90, NdotL); |
|||
float viewScatter = F_Schlick(1.0f, fd90, NdotV); |
|||
|
|||
return INV_PI * lightScatter * viewScatter; |
|||
} |
|||
|
|||
#endif // UNITY_BSDF_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 5eb5e8e99ae281342bae5c7b296b3ae3 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_COLOR_INCLUDED |
|||
#define UNITY_COLOR_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Gamma space - Assume positive values |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Gamma20 |
|||
float Gamma20ToLinear(float c) |
|||
{ |
|||
return c * c; |
|||
} |
|||
|
|||
float3 Gamma20ToLinear(float3 c) |
|||
{ |
|||
return c.rgb * c.rgb; |
|||
} |
|||
|
|||
float4 Gamma20ToLinear(float4 c) |
|||
{ |
|||
return float4(Gamma20ToLinear(c.rgb), c.a); |
|||
} |
|||
|
|||
float LinearToGamma20(float c) |
|||
{ |
|||
return sqrt(c); |
|||
} |
|||
|
|||
float3 LinearToGamma20(float3 c) |
|||
{ |
|||
return sqrt(c.rgb); |
|||
} |
|||
|
|||
float4 LinearToGamma20(float4 c) |
|||
{ |
|||
return float4(LinearToGamma20(c.rgb), c.a); |
|||
} |
|||
|
|||
// Gamma22 |
|||
float Gamma22ToLinear(float c) |
|||
{ |
|||
return pow(c, 2.2); |
|||
} |
|||
|
|||
float3 Gamma22ToLinear(float3 c) |
|||
{ |
|||
return pow(c.rgb, float3(2.2, 2.2, 2.2)); |
|||
} |
|||
|
|||
float3 Gamma22ToLinear(float3 c) |
|||
{ |
|||
return float4(Gamma22ToLinear(c.rgb), c.a); |
|||
} |
|||
|
|||
float LinearToGamma22(float c) |
|||
{ |
|||
return pow(c, 0.454545454545455); |
|||
} |
|||
|
|||
float3 LinearToGamma22(float3 c) |
|||
{ |
|||
return pow(c.rgb, float3(0.454545454545455, 0.454545454545455, 0.454545454545455)); |
|||
} |
|||
|
|||
float3 LinearToGamma22(float3 c) |
|||
{ |
|||
return float4(LinearToGamma22(c.rgb), c.a); |
|||
} |
|||
|
|||
// sRGB |
|||
float3 SRGBToLinear(float3 c) |
|||
{ |
|||
float3 linearRGBLo = c / 12.92; |
|||
float3 linearRGBHi = pow((c + 0.055) / 1.055, float3(2.4, 2.4, 2.4)); |
|||
float3 linearRGB = (c <= 0.04045) ? linearRGBLo : linearRGBHi; |
|||
return linearRGB; |
|||
} |
|||
|
|||
float4 SRGBToLinear(float4 c) |
|||
{ |
|||
return float4(SRGBToLinear(c), c.a); |
|||
} |
|||
|
|||
float3 LinearToSRGB(float3 c) |
|||
{ |
|||
float3 sRGBLo = c * 12.92; |
|||
float3 sRGBHi = (pow(c, float3(1.0/2.4, 1.0/2.4, 1.0/2.4)) * 1.055) - 0.055; |
|||
float3 sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi; |
|||
return sRGB; |
|||
} |
|||
|
|||
float4 LinearToSRGB(float4 c) |
|||
{ |
|||
return float4(LinearToSRGB(c), c.a); |
|||
} |
|||
|
|||
// TODO: Seb - To verify and refit! |
|||
// Ref: http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 |
|||
float3 FastSRGBToLinear(float3 c) |
|||
{ |
|||
return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878); |
|||
} |
|||
|
|||
float3 FastSRGBToLinear(float3 c) |
|||
{ |
|||
return float4(FastSRGBToLinear(c.rgb), c.a); |
|||
} |
|||
|
|||
float3 FastLinearToSRGB(float3 c) |
|||
{ |
|||
return max(1.055 * pow(c, 0.416666667) - 0.055, 0.0); |
|||
} |
|||
|
|||
float4 FastLinearToSRGB(float4 c) |
|||
{ |
|||
return float4(FastLinearToSRGB(c), c.a); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Color space |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Convert rgb to luminance |
|||
// with rgb in linear space with sRGB primaries and D65 white point |
|||
half Luminance(half3 linearRgb) |
|||
{ |
|||
return dot(linearRgb, half3(0.2126729f, 0.7151522f, 0.0721750f)); |
|||
} |
|||
|
|||
// Ref: http://realtimecollisiondetection.net/blog/?p=15 |
|||
float4 PackLogLuv(in float3 vRGB) |
|||
{ |
|||
// M matrix, for encoding |
|||
const float3x3 M = float3x3( |
|||
0.2209, 0.3390, 0.4184, |
|||
0.1138, 0.6780, 0.7319, |
|||
0.0102, 0.1130, 0.2969); |
|||
|
|||
float4 vResult; |
|||
float3 Xp_Y_XYZp = mul(vRGB, M); |
|||
Xp_Y_XYZp = max(Xp_Y_XYZp, float3(1e-6, 1e-6, 1e-6)); |
|||
vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z; |
|||
float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0; |
|||
vResult.w = frac(Le); |
|||
vResult.z = (Le - (floor(vResult.w*255.0f))/255.0f)/255.0f; |
|||
return vResult; |
|||
} |
|||
|
|||
float3 UnpackLogLuv(in float4 vLogLuv) |
|||
{ |
|||
// Inverse M matrix, for decoding |
|||
const float3x3 InverseM = float3x3( |
|||
6.0014, -2.7008, -1.7996, |
|||
-1.3320, 3.1029, -5.7721, |
|||
0.3008, -1.0882, 5.6268); |
|||
|
|||
float Le = vLogLuv.z * 255.0 + vLogLuv.w; |
|||
float3 Xp_Y_XYZp; |
|||
Xp_Y_XYZp.y = exp2((Le - 127.0) / 2.0); |
|||
Xp_Y_XYZp.z = Xp_Y_XYZp.y / vLogLuv.y; |
|||
Xp_Y_XYZp.x = vLogLuv.x * Xp_Y_XYZp.z; |
|||
float3 vRGB = mul(Xp_Y_XYZp, InverseM); |
|||
return max(vRGB, float3(0.0, 0.0, 0.0)); |
|||
} |
|||
|
|||
// TODO: check what is really use by the lightmap... should be hardcoded |
|||
// This function must handle various crappy case of lightmap ? |
|||
half4 UnityEncodeRGBM (half3 rgb, float maxRGBM) |
|||
{ |
|||
float kOneOverRGBMMaxRange = 1.0 / maxRGBM; |
|||
const float kMinMultiplier = 2.0 * 1e-2; |
|||
|
|||
float4 rgbm = float4(rgb * kOneOverRGBMMaxRange, 1.0f); |
|||
rgbm.a = max(max(rgbm.r, rgbm.g), max(rgbm.b, kMinMultiplier)); |
|||
rgbm.a = ceil(rgbm.a * 255.0) / 255.0; |
|||
|
|||
// Division-by-zero warning from d3d9, so make compiler happy. |
|||
rgbm.a = max(rgbm.a, kMinMultiplier); |
|||
|
|||
rgbm.rgb /= rgbm.a; |
|||
return rgbm; |
|||
} |
|||
|
|||
// Alternative... |
|||
#define RGBMRANGE (8.0) |
|||
float4 packRGBM(float3 color) |
|||
{ |
|||
float4 rgbm; |
|||
color *= (1.0 / RGBMRANGE); |
|||
rgbm.a = saturate( max( max( color.r, color.g ), max( color.b, 1e-6 ) ) ); |
|||
rgbm.a = ceil( rgbm.a * 255.0 ) / 255.0; |
|||
rgbm.rgb = color / rgbm.a; |
|||
return rgbm; |
|||
} |
|||
|
|||
float3 unpackRGBM(float4 rgbm) |
|||
{ |
|||
return RGBMRANGE * rgbm.rgb * rgbm.a; |
|||
} |
|||
|
|||
#endif // UNITY_COLOR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 23284bbc36146a94995a8a08e61f4e73 |
|||
timeCreated: 1472140529 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_COMMON_INCLUDED |
|||
#define UNITY_COMMON_INCLUDED |
|||
|
|||
// Include platform header |
|||
#if defined(SHADER_API_XBOXONE) |
|||
#include "Platform/XboxOne.hlsl" |
|||
#endif |
|||
|
|||
// Include language header |
|||
#if defined(SHADER_API_D3D11) |
|||
#include "API/D3D11.hlsl" |
|||
#endif |
|||
|
|||
#endif |
|||
|
|||
// ---------------------------------------------------------------------------- |
|||
// Common math definition and fastmath function |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
#define PI 3.14159265359f |
|||
#define TWO_PI 6.28318530718f |
|||
#define FOUR_PI 12.56637061436f |
|||
#define INV_PI 0.31830988618f |
|||
#define INV_TWO_PI 0.15915494309f |
|||
#define INV_FOUR_PI 0.07957747155f |
|||
#define HALF_PI 1.57079632679f |
|||
#define INV_HALF_PI 0.636619772367f |
|||
|
|||
// Ref: https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/ |
|||
float FastACos(float inX) |
|||
{ |
|||
float x = abs(inX); |
|||
float res = -0.156583f * x + HALF_PI; |
|||
res *= sqrt(1.0f - x); |
|||
return (inX >= 0) ? res : PI - res; |
|||
} |
|||
|
|||
// Same cost as Acos + 1 FR |
|||
// Same error |
|||
// input [-1, 1] and output [-PI/2, PI/2] |
|||
float FastASin(float x) |
|||
{ |
|||
return HALF_PI - FastACos(x); |
|||
} |
|||
|
|||
// max absolute error 1.3x10^-3 |
|||
// Eberly's odd polynomial degree 5 - respect bounds |
|||
// 4 VGPR, 14 FR (10 FR, 1 QR), 2 scalar |
|||
// input [0, infinity] and output [0, PI/2] |
|||
float FastATanPos(float inX) |
|||
{ |
|||
float t0 = (x < 1.0f) ? x : 1.0f / x; |
|||
float t1 = t0 * t0; |
|||
float poly = 0.0872929f; |
|||
poly = -0.301895f + poly * t1; |
|||
poly = 1.0f + poly * t1; |
|||
poly = poly * t0; |
|||
return (x < 1.0f) ? poly : HALF_PI - poly; |
|||
} |
|||
|
|||
// 4 VGPR, 16 FR (12 FR, 1 QR), 2 scalar |
|||
// input [-infinity, infinity] and output [-PI/2, PI/2] |
|||
float FastATan(float x) |
|||
{ |
|||
float t0 = FastATanPos(abs(x)); |
|||
return (x < 0.0f) ? -t0: t0; |
|||
} |
|||
|
|||
#endif // UNITY_COMMON_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: a57f9f83ea626ae45b402953fe637268 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_GEOMETRICTOOLS_INCLUDED |
|||
#define UNITY_GEOMETRICTOOLS_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
#endif // UNITY_GEOMETRICTOOLS_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: eebfba22df48acf4b978d98000cb10e6 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b7031a2dbb001ad429fda765366875e3 |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7c29049a5f4f04a4cbce45f056b27640 |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_MATERIAL_INCLUDED |
|||
#define UNITY_MATERIAL_INCLUDED |
|||
|
|||
#include "Packing.hlsl" |
|||
|
|||
#define DisneyGGXSurfaceData SurfaceData |
|||
#define DisneyGGXBSDFData BSDFData |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// SurfaceData and BSDFData |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Main structure that store the data from the standard shader (i.e user input) |
|||
struct DisneyGGXSurfaceData |
|||
{ |
|||
float3 diffuseColor; |
|||
float occlusion; |
|||
|
|||
float3 specularColor; |
|||
float smoothness; |
|||
|
|||
float3 normal; // normal in world space |
|||
}; |
|||
|
|||
struct DisneyGGXBSDFData |
|||
{ |
|||
float3 diffuseColor; |
|||
float occlusion; |
|||
|
|||
float3 fresnel0; |
|||
float roughness; |
|||
|
|||
float3 normalWS; |
|||
}; |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Parametrization function helpers |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float PerceptualRoughnessToRoughness(float perceptualRoughness) |
|||
{ |
|||
return perceptualRoughness * perceptualRoughness; |
|||
} |
|||
|
|||
float RoughnessToPerceptualRoughness(float roughness) |
|||
{ |
|||
return sqrt(roughness); |
|||
} |
|||
|
|||
// Smoothness is the user facing name |
|||
// it should be perceptualSmoothness but we don't want the user to have to deal with this name |
|||
float SmoothnessToRoughness(float smoothness) |
|||
{ |
|||
return (1 - smoothness) * (1 - smoothness); |
|||
} |
|||
|
|||
float SmoothnessToPerceptualRoughness(float smoothness) |
|||
{ |
|||
return (1 - smoothness); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// conversion function for forward and deferred |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DisneyGGXBSDFData ConvertSurfaceDataToBSDFData(DisneyGGXSurfaceData data) |
|||
{ |
|||
DisneyGGXBSDFData output; |
|||
|
|||
output.diffuseColor = data.diffuseColor; |
|||
output.occlusion = data.occlusion; |
|||
|
|||
output.fresnel0 = data.specularColor; |
|||
output.roughness = SmoothnessToRoughness(data.smoothness); |
|||
|
|||
output.normalWS = data.normal; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
// This will encode UnityStandardData into GBuffer |
|||
void EncodeIntoGBuffer(DisneyGGXSurfaceData data, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2) |
|||
{ |
|||
// RT0: diffuse color (rgb), occlusion (a) - sRGB rendertarget |
|||
outGBuffer0 = half4(data.diffuseColor, data.occlusion); |
|||
|
|||
// RT1: spec color (rgb), roughness (a) - sRGB rendertarget |
|||
outGBuffer1 = half4(data.specularColor, SmoothnessToRoughness(data.smoothness)); |
|||
|
|||
// RT2: normal (rgb), --unused, very low precision-- (a) |
|||
outGBuffer2 = half4(PackNormalCartesian(data.normal), 1.0f); |
|||
} |
|||
|
|||
// This decode the Gbuffer in a BSDFData struct |
|||
DisneyGGXBSDFData DecodeFromGBuffer(half4 inGBuffer0, half4 inGBuffer1, half4 inGBuffer2) |
|||
{ |
|||
BSDFData data; |
|||
|
|||
data.diffuseColor = inGBuffer0.rgb; |
|||
data.occlusion = inGBuffer0.a; |
|||
|
|||
data.fresnel0 = inGBuffer1.rgb; |
|||
data.roughness = inGBuffer1.a; |
|||
|
|||
data.normalWS = UnpackNormalCartesian(inGBuffer2.rgb); |
|||
|
|||
return data; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF functions for each light type |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void EvaluateBSDF_Punctual_DisneyGGX( float3 V, float3 positionWS, PunctualLightData light, DisneyGGXBSDFData material, |
|||
out float4 diffuseLighting, |
|||
out float4 specularLighting) |
|||
{ |
|||
float3 unormalizedLightVector = light.pos - positionWS; |
|||
float3 L = normalize(unormalizedLightVector); |
|||
|
|||
// Always done, directional have it neutral |
|||
float attenuation = GetDistanceAttenuation(unormalizedLightVector, light.invSqrAttenuationRadius); |
|||
// Always done, point and dir have it neutral |
|||
attenuation *= GetAngleAttenuation(L, light.forward, light.angleScale, light.angleOffset); |
|||
float illuminance = saturate(dot(material.normalWS, L)) * attenuation; |
|||
|
|||
diffuseLighting = float4(0.0f, 0.0f, 0.0f, 1.0f); |
|||
specularLighting = float4(0.0f, 0.0f, 0.0f, 1.0f); |
|||
|
|||
if (illuminance > 0.0f) |
|||
{ |
|||
float NdotV = abs(dot(material.normalWS, V)) + 1e-5f; // TODO: check Eric idea about doing that when writting into the GBuffer (with our forward decal) |
|||
float3 H = normalize(V + L); |
|||
float LdotH = saturate(dot(L, H)); |
|||
float NdotL = saturate(dot(material.normalWS, L)); |
|||
float3 F = F_Schlick(material.fresnel0, LdotH); |
|||
float Vis = V_SmithGGX(NdotL, NdotV, material.roughness); |
|||
float D = D_GGX(NdotH, material.roughness); |
|||
specularLighting.rgb = F * Vis * D; |
|||
float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotH, material.perceptualRoughness); |
|||
diffuseLighting.rgb = material.diffuseColor * disneyDiffuse; |
|||
|
|||
diffuseLighting.rgb *= light.color * illuminance; |
|||
specularLighting.rgb *= light.color * illuminance; |
|||
} |
|||
} |
|||
|
|||
#endif // UNITY_MATERIAL_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 1dc16e70dd841de4396d41f9ae92c6f9 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_PACKING_INCLUDED |
|||
#define UNITY_PACKING_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Normal packing |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float3 PackNormalCartesian(float3 n) |
|||
{ |
|||
return n * 0.5 + 0.5; |
|||
} |
|||
|
|||
float3 UnpackNormalCartesian(float3 n) |
|||
{ |
|||
return normalize(n * 2.0 - 1.0); |
|||
} |
|||
|
|||
float3 PackNormalMaxComponent(float3 n) |
|||
{ |
|||
// TODO: use max3 |
|||
return (n / max(abs(n.x), max(abs(n.y), abs(n.z)))) * 0.5 + 0.5; |
|||
} |
|||
|
|||
float3 UnpackNormalMaxComponent(float3 n) |
|||
{ |
|||
return normalize(n * 2.0 - 1.0); |
|||
} |
|||
|
|||
// Ref: http://jcgt.org/published/0003/02/01/paper.pdf |
|||
// Encode with Oct, this function work with any size of output |
|||
// return float between [-1, 1] |
|||
float2 PackNormalOctEncode(in float3 v) |
|||
{ |
|||
float l1norm = abs(v.x) + abs(v.y) + abs(v.z); |
|||
float2 res0 = v.xy * (1.0f / l1norm); |
|||
|
|||
float2 val = 1.0f - abs(res0.yx); |
|||
return (v.zz < float2(0.0f, 0.0f) ? (res0 >= 0.0f ? val : -val) : res0); |
|||
} |
|||
|
|||
float3 UnpackNormalOctEncode(in float x, in float y) |
|||
{ |
|||
float3 v = float3(x, y, 1.0f - abs(x) - abs(y)); |
|||
|
|||
float2 val = 1.0f - abs(v.yx); |
|||
v.xy = (v.zz < float2(0.0f, 0.0f) ? (v.xy >= 0.0f ? val : -val) : v.xy); |
|||
|
|||
return normalize(v); |
|||
} |
|||
|
|||
float3 UnpackNormalDXT5nm (float4 packednormal) |
|||
{ |
|||
float3 normal; |
|||
normal.xy = packednormal.wy * 2 - 1; |
|||
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); |
|||
return normal; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Byte packing |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float Pack2Byte(float2 inputs) |
|||
{ |
|||
float2 temp = inputs * float2(255.0, 255.0); |
|||
temp.x *= 256.0; |
|||
temp = round(temp); |
|||
float combined = temp.x + temp.y; |
|||
return combined * (1.0 / 65535.0); |
|||
} |
|||
|
|||
float2 Unpack2Byte(float inputs) |
|||
{ |
|||
float temp = round(inputs * 65535.0); |
|||
float ipart; |
|||
float fpart = modf(temp / 256.0, ipart); |
|||
float2 result = float2(ipart, round(256.0 * fpart)); |
|||
return result * (1.0 / float2(255.0, 255.0)); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#endif // UNITY_PACKING_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: ad629edbad34c1c45afea3021c1553c8 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 89da82daf26da9242b541b3d831288e3 |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c50ac5c0368fe38449d335dad3e23260 |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e71f86976f604d43854b41241260bda |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: d90c5a99d7855ad46b792d749ce7ca6f |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_QUATERNIONMATH_INCLUDED |
|||
#define UNITY_QUATERNIONMATH_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
#endif // UNITY_QUATERNIONMATH_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 28991169f6e68314ab20d6a0e4aeccec |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_SHMATH_INCLUDED |
|||
#define UNITY_SHMATH_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
#endif // UNITY_SHMATH_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 6c7ed7ec061ae2243bb560c39b451a15 |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_SAMPLING_INCLUDED |
|||
#define UNITY_SAMPLING_INCLUDED |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
#endif // UNITY_SAMPLING_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: f4c850bea2c5d45449ba8e228333c82c |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f3f46477a8abfdd4095f74e7f5e052d9 |
|||
folderAsset: yes |
|||
timeCreated: 1472205826 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_SHADER_VARIABLES_INCLUDED |
|||
#define UNITY_SHADER_VARIABLES_INCLUDED |
|||
|
|||
#define UNITY_MATRIX_M unity_ObjectToWorld |
|||
|
|||
// These are updated per eye in VR |
|||
#define UNITY_MATRIX_V unity_MatrixV |
|||
#define UNITY_MATRIX_P glstate_matrix_projection |
|||
#define UNITY_MATRIX_VP unity_MatrixVP |
|||
|
|||
#ifdef UNITY_SINGLE_PASS_STEREO |
|||
#define UNITY_MATRIX_MVP mul(unity_MatrixVP, unity_ObjectToWorld) |
|||
#else |
|||
#define UNITY_MATRIX_MVP glstate_matrix_mvp |
|||
#endif |
|||
|
|||
// These use the camera center position in VR |
|||
#define UNITY_MATRIX_MV glstate_matrix_modelview0 |
|||
#define UNITY_MATRIX_T_MV glstate_matrix_transpose_modelview0 |
|||
#define UNITY_MATRIX_IT_MV glstate_matrix_invtrans_modelview0 |
|||
|
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
|
|||
CBUFFER_START(UnityPerCamera) |
|||
// Time (t = time since current level load) values from Unity |
|||
float4 _Time; // (t/20, t, t*2, t*3) |
|||
float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t) |
|||
float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t) |
|||
float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt |
|||
|
|||
#ifndef UNITY_SINGLE_PASS_STEREO |
|||
float3 _WorldSpaceCameraPos; |
|||
#endif |
|||
|
|||
// x = 1 or -1 (-1 if projection is flipped) |
|||
// y = near plane |
|||
// z = far plane |
|||
// w = 1/far plane |
|||
float4 _ProjectionParams; |
|||
|
|||
// x = width |
|||
// y = height |
|||
// z = 1 + 1.0/width |
|||
// w = 1 + 1.0/height |
|||
float4 _ScreenParams; |
|||
|
|||
// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt) |
|||
// x = 1-far/near |
|||
// y = far/near |
|||
// z = x/far |
|||
// w = y/far |
|||
float4 _ZBufferParams; |
|||
|
|||
// x = orthographic camera's width |
|||
// y = orthographic camera's height |
|||
// z = unused |
|||
// w = 1.0 if camera is ortho, 0.0 if perspective |
|||
float4 unity_OrthoParams; |
|||
CBUFFER_END |
|||
|
|||
|
|||
CBUFFER_START(UnityPerCameraRare) |
|||
float4 unity_CameraWorldClipPlanes[6]; |
|||
|
|||
// Projection matrices of the camera. Note that this might be different from projection matrix |
|||
// that is set right now, e.g. while rendering shadows the matrices below are still the projection |
|||
// of original camera. |
|||
float4x4 unity_CameraProjection; |
|||
float4x4 unity_CameraInvProjection; |
|||
|
|||
#ifndef UNITY_SINGLE_PASS_STEREO |
|||
float4x4 unity_WorldToCamera; |
|||
float4x4 unity_CameraToWorld; |
|||
#endif |
|||
CBUFFER_END |
|||
|
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
CBUFFER_START(UnityPerDraw) |
|||
#ifndef UNITY_SINGLE_PASS_STEREO |
|||
float4x4 glstate_matrix_mvp; |
|||
#endif |
|||
|
|||
// Use center position for stereo rendering |
|||
float4x4 glstate_matrix_modelview0; |
|||
float4x4 glstate_matrix_invtrans_modelview0; |
|||
|
|||
float4x4 unity_ObjectToWorld; |
|||
float4x4 unity_WorldToObject; |
|||
float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels |
|||
float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms |
|||
CBUFFER_END |
|||
|
|||
#ifdef UNITY_SINGLE_PASS_STEREO |
|||
CBUFFER_START(UnityPerEye) |
|||
float3 _WorldSpaceCameraPos; |
|||
float4x4 glstate_matrix_projection; |
|||
|
|||
float4x4 unity_MatrixV; |
|||
float4x4 unity_MatrixVP; |
|||
|
|||
float4x4 unity_WorldToCamera; |
|||
float4x4 unity_CameraToWorld; |
|||
CBUFFER_END |
|||
#endif |
|||
|
|||
CBUFFER_START(UnityPerDrawRare) |
|||
float4x4 glstate_matrix_transpose_modelview0; |
|||
#ifdef UNITY_SINGLE_PASS_STEREO |
|||
float4x4 glstate_matrix_mvp; |
|||
#endif |
|||
CBUFFER_END |
|||
|
|||
|
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
CBUFFER_START(UnityPerFrame) |
|||
|
|||
#ifndef UNITY_SINGLE_PASS_STEREO |
|||
float4x4 glstate_matrix_projection; |
|||
float4x4 unity_MatrixV; |
|||
float4x4 unity_MatrixVP; |
|||
#endif |
|||
|
|||
fixed4 glstate_lightmodel_ambient; |
|||
fixed4 unity_AmbientSky; |
|||
fixed4 unity_AmbientEquator; |
|||
fixed4 unity_AmbientGround; |
|||
fixed4 unity_IndirectSpecColor; |
|||
|
|||
CBUFFER_END |
|||
|
|||
#endif // UNITY_SHADER_VARIABLES_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: d1fb2d5b8f417ce40bac95e4fe4301b9 |
|||
timeCreated: 1472205826 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unity Standard" |
|||
{ |
|||
Properties |
|||
{ |
|||
_DiffuseColor("Diffuse", Color) = (1,1,1,1) |
|||
_DiffuseMap("Diffuse", 2D) = "white" {} |
|||
|
|||
_SpecColor("Specular", Color) = (0.2,0.2,0.2) |
|||
_SpecMap("Specular", 2D) = "white" {} |
|||
|
|||
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5 |
|||
_SmoothnessMap("Smoothness", 2D) = "white" {} |
|||
|
|||
_NormalMap("Normal Map", 2D) = "bump" {} |
|||
_OcclusionMap("Occlusion", 2D) = "white" {} |
|||
|
|||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
// Blending state |
|||
[HideInInspector] _Mode ("__mode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend ("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend ("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite ("__zw", Float) = 1.0 |
|||
} |
|||
|
|||
CGINCLUDE |
|||
|
|||
#include "Lighting.hlsl" |
|||
#include "Material.hlsl" |
|||
|
|||
ENDCG |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Shadow rendering pass |
|||
Pass { |
|||
Name "ShadowCaster" |
|||
Tags { "LightMode" = "ShadowCaster" } |
|||
|
|||
ZWrite On ZTest LEqual |
|||
|
|||
CGPROGRAM |
|||
#pragma target 5.0 |
|||
|
|||
// ------------------------------------- |
|||
|
|||
|
|||
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON |
|||
#pragma shader_feature _SPECGLOSSMAP |
|||
#pragma multi_compile_shadowcaster |
|||
|
|||
#pragma vertex vertShadowCaster |
|||
#pragma fragment fragShadowCaster |
|||
|
|||
#include "UnityStandardShadow.cginc" |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Base forward pass (directional light, emission, lightmaps, ...) |
|||
Pass |
|||
{ |
|||
Name "FORWARD" |
|||
Tags { "LightMode" = "ForwardBase" } |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
ZWrite [_ZWrite] |
|||
|
|||
CGPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
// Include |
|||
#include "Lighting.hlsl" |
|||
#include "Material.hlsl" |
|||
|
|||
VertexOutput MainVs( VertexInput i ) |
|||
{ |
|||
// TODO : here we must support anykind of vertex animation |
|||
VertexOutput o; |
|||
|
|||
//o.vPositionPs.xyzw = mul( UNITY_MATRIX_MVP, i.vPositionOs.xyzw ); |
|||
|
|||
float3 vNormalWs = UnityObjectToWorldNormal( i.vNormalOs.xyz ); |
|||
float3 vPositionWs = mul( unity_ObjectToWorld, i.vPositionOs.xyzw ).xyz; |
|||
float2 vShadowOffsets = GetShadowOffsets( vNormalWs.xyz, g_vLightDirWs.xyz ); |
|||
vPositionWs.xyz -= vShadowOffsets.x * vNormalWs.xyz / 100; |
|||
vPositionWs.xyz += vShadowOffsets.y * g_vLightDirWs.xyz / 1000; |
|||
o.vPositionPs.xyzw = mul( UNITY_MATRIX_MVP, float4( mul( unity_WorldToObject, float4( vPositionWs.xyz, 1.0 ) ).xyz, 1.0 ) ); |
|||
return o; |
|||
} |
|||
|
|||
float4 MainPs( VertexOutput i ) : SV_Target |
|||
{ |
|||
return float4( 0.0, 0.0, 0.0, 0.0 ); |
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Deferred pass |
|||
Pass |
|||
{ |
|||
Name "DEFERRED" |
|||
Tags { "LightMode" = "Deferred" } |
|||
|
|||
CGPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma exclude_renderers nomrt |
|||
|
|||
|
|||
void fragDeferred2 ( |
|||
VertexOutputDeferred i, |
|||
out half4 outDiffuse : SV_Target0, // RT0: diffuse color (rgb), occlusion (a) |
|||
out half4 outSpecSmoothness : SV_Target1, // RT1: spec color (rgb), smoothness (a) |
|||
out half4 outNormal : SV_Target2, // RT2: normal (rgb), --unused, very low precision-- (a) |
|||
out half4 outEmission : SV_Target3 // RT3: emission (rgb), --unused-- (a) |
|||
) |
|||
{ |
|||
#if (SHADER_TARGET < 30) |
|||
outDiffuse = 1; |
|||
outSpecSmoothness = 1; |
|||
outNormal = 0; |
|||
outEmission = 0; |
|||
return; |
|||
#endif |
|||
|
|||
FRAGMENT_SETUP(s) |
|||
#if UNITY_OPTIMIZE_TEXCUBELOD |
|||
s.reflUVW = i.reflUVW; |
|||
#endif |
|||
|
|||
// no analytic lights in this pass |
|||
UnityLight dummyLight = DummyLight (s.normalWorld); |
|||
half atten = 1; |
|||
|
|||
// only GI |
|||
half occlusion = Occlusion(i.tex.xy); |
|||
#if UNITY_ENABLE_REFLECTION_BUFFERS |
|||
bool sampleReflectionsInDeferred = false; |
|||
#else |
|||
bool sampleReflectionsInDeferred = true; |
|||
#endif |
|||
|
|||
UnityGI gi = FragmentGI (s, occlusion, i.ambientOrLightmapUV, atten, dummyLight, sampleReflectionsInDeferred); |
|||
|
|||
half3 color = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.oneMinusRoughness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect).rgb; |
|||
color += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.oneMinusRoughness, s.normalWorld, -s.eyeVec, occlusion, gi); |
|||
|
|||
#ifdef _EMISSION |
|||
color += Emission (i.tex.xy); |
|||
#endif |
|||
|
|||
#ifndef UNITY_HDR_ON |
|||
color.rgb = exp2(-color.rgb); |
|||
#endif |
|||
|
|||
outDiffuse = half4(s.diffColor, occlusion); |
|||
outSpecSmoothness = half4(s.specColor, s.oneMinusRoughness); |
|||
outNormal = half4(s.normalWorld*0.5+0.5,1); |
|||
outEmission = half4(color, 1); |
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Extracts information for lightmapping, GI (emission, albedo, ...) |
|||
// This pass it not used during regular rendering. |
|||
Pass |
|||
{ |
|||
Name "META" |
|||
Tags { "LightMode"="Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
CGPROGRAM |
|||
#pragma vertex vert_meta |
|||
#pragma fragment frag_meta |
|||
|
|||
#pragma shader_feature _EMISSION |
|||
#pragma shader_feature _SPECGLOSSMAP |
|||
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature ___ _DETAIL_MULX2 |
|||
|
|||
#include "UnityStandardMeta.cginc" |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
CustomEditor "StandardShaderGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c846f5368b257ca49aa135748a1700e2 |
|||
timeCreated: 1472205826 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_VERTEX_INCLUDED |
|||
#define UNITY_VERTEX_INCLUDED |
|||
|
|||
#include "../Common.hlsl" |
|||
|
|||
struct VertexOutputDeferred |
|||
{ |
|||
float4 pos : SV_POSITION; |
|||
float4 tex : TEXCOORD0; |
|||
float4 tangentToWorldAndParallax[3] : TEXCOORD1; // [3x3:tangentToWorld | 1x3:viewDirForParallax] |
|||
}; |
|||
|
|||
VertexOutputDeferred vertDeferred (VertexInput v) |
|||
{ |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
VertexOutputDeferred o; |
|||
UNITY_INITIALIZE_OUTPUT(VertexOutputDeferred, o); |
|||
|
|||
float4 posWorld = mul(unity_ObjectToWorld, v.vertex); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.tex = TexCoords(v); |
|||
float3 normalWorld = UnityObjectToWorldNormal(v.normal); |
|||
|
|||
float4 tangentWorld = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); |
|||
|
|||
float3x3 tangentToWorld = CreateTangentToWorldPerVertex(normalWorld, tangentWorld.xyz, tangentWorld.w); |
|||
o.tangentToWorldAndParallax[0].xyz = tangentToWorld[0]; |
|||
o.tangentToWorldAndParallax[1].xyz = tangentToWorld[1]; |
|||
o.tangentToWorldAndParallax[2].xyz = tangentToWorld[2]; |
|||
|
|||
|
|||
return o; |
|||
} |
|||
|
|||
#endif // UNITY_VERTEX_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 3cc412debf748e040aeabf1cb51d2515 |
|||
timeCreated: 1472205826 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue