// TODO: This is the max value allowed for emissive (bad name - but keep for now to retrieve it) (It is 8^2.2 (gamma) and 8 is the limit of punctual light slider...), comme from UnityCg.cginc. Fix it!
// Ask Jesper if this can be change for HDRenderPipeline
#define EMISSIVE_RGBM_SCALE 97.0
// RGBM stuff is temporary. For now baked lightmap are in RGBM and the RGBM range for lightmaps is specific so we can't use the generic method.
// In the end baked lightmaps are going to be BC6H so the code will be the same as dynamic lightmaps.
// Same goes for emissive packed as an input for Enlighten with another hard coded multiplier.
// TODO: This function is used with the LightTransport pass to encode lightmap or emissive
// CAUTION: remap from Morten may work only with offline convolution, see impact with runtime convolution!
float m = PerceptualRoughnessToRoughness(perceptualRoughness);
// For now disabled
#if 0
float m = PerceptualRoughnessToRoughness(perceptualRoughness); // m is the real roughness parameter
float n = (2.0 / max(FLT_EPSILON, m*m)) - 2.0; // remap to spec power. See eq. 21 in --> https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf
// Remap to spec power. See eq. 21 in --> https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf
float n = (2.0 / max(FLT_EPSILON, m * m)) - 2.0;
n /= 4.0; // remap from n_dot_h formulatino to n_dot_r. See section "Pre-convolved Cube Maps vs Path Tracers" --> https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html
// Remap from n_dot_h formulation to n_dot_r. See section "Pre-convolved Cube Maps vs Path Tracers" --> https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html
n /= (4.0 * max(NdotR, FLT_EPSILON));
perceptualRoughness = pow(2.0 / (n + 2.0), 0.25); // remap back to square root of real roughness (0.25 include both the sqrt root of the conversion and sqrt for going from roughness to perceptualRoughness)
#else
// MM: came up with a surprisingly close approximation to what the #if 0'ed out code above does.
// remap back to square root of real roughness (0.25 include both the sqrt root of the conversion and sqrt for going from roughness to perceptualRoughness)
#pragma kernel ShadeDeferred_Clustered SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=0 //TODO: disabled clustered permutations so far as it leads to the error "All kernels must use same constant buffer layouts"
#pragma kernel ShadeDeferred_Clustered SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=0 //TODO: disabled clustered permutations so far as it leads to the error "All kernels must use same constant buffer layouts"
[branch]if(idxCoarse<(uint) g_iNrVisibLights && g_vLightData[idxCoarse].lightType!=SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
if(canEnter) canEnter = g_vLightData[idxCoarse].lightType!=SPHERE_LIGHT; // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
**NOTE**: this is a testbed for a Unity feature that has not shipped yet! The project will not work with any public
**NOTE**: this is a testbed for a Unity feature that has not shipped yet! The project does not work with any public
Unity version, and things in it might and will be broken.
"Scriptable Render Loops" is a potential future Unity feature, think "Command Buffers, take two". We plan to ship the feature, and a
There's a more detailed overview document here: [ScriptableRenderLoop google doc](https://docs.google.com/document/d/1e2jkr_-v5iaZRuHdnMrSv978LuJKYZhsIYnrDkNAuvQ/edit?usp=sharing)
Did we mention it's a very WIP, no promises, may or might not ship feature, anything and everything in it can change? It totally is.
## For Unity 5.6 beta users
* Unity 5.6 **beta 1, 2 and 3** should use an older revision of this project, [tagged unity-5.6.0b1](../../releases/tag/unity-5.6.0b1) (commit `acc230b` on 2016 Nov 23). "BasicRenderLoopScene" scene is the basic example, with the scriptable render loop defaulting to off; enable it by enabling the component on the camera. All the other scenes may or might not work. Use of Windows/DX11 is preferred.
SetKeyword(material,"_NORMALMAP",material.GetTexture(kNormalMap)||material.GetTexture(kDetailMap));// With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for ir
SetKeyword(material,"_NORMALMAP",material.GetTexture(kNormalMap)||material.GetTexture(kDetailMap));// With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for ir
publicstaticGUIContentemissiveWarning=newGUIContent("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
publicstaticGUIContentemissiveColorWarning=newGUIContent("Ensure emissive color is non-black for emission to have effect.");
publicstaticGUIContenttessellationFactorText=newGUIContent("Tessellation factor","This value is the tessellation factor use for tessellation, higher mean more tessellated");
publicstaticGUIContenttessellationFactorMinDistanceText=newGUIContent("Start fade distance","Distance (in unity unit) at which the tessellation start to fade out. Must be inferior at Max distance");
publicstaticGUIContenttessellationFactorMaxDistanceText=newGUIContent("End fade distance","Maximum distance (in unity unit) to the camera where triangle are tessellated");
publicstaticGUIContenttessellationFactorTriangleSizeText=newGUIContent("Triangle size","Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle.");
publicstaticGUIContenttessellationShapeFactorText=newGUIContent("Shape factor","Strength of Phong tessellation shape (lerp factor)");
publicstaticGUIContenttessellationBackFaceCullEpsilonText=newGUIContent("Triangle culling Epsilon","If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
publicstaticGUIContenttessellationObjectScaleText=newGUIContent("Enable object scale","Tesselation displacement will take into account the object scale - Only work with uniform positive scale");
FindOptionProperties(props);// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindInputProperties(props);
FindCommonOptionProperties(props);// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
// If we have a lit shader, only the UV0 is available for opacity or heightmap
// If we have a layered shader, any UV can be use for this. To reduce the number of variant we groupt UV0/UV1 and UV2/UV3 instead of having variant for UV0/UV1/UV2/UV3
// When UVX is present, we assume that UVX - 1 ... UV0 is present
output.unPositionSS = input.positionCS; // as input we have the vpos
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
// // The idea here is to lerp toward vertex normal. This way when we don't want to inherit, we will combine layer 1/2/3 normal with a vertex normal which is neutral.
// // Blend layer 1/2/3 normals before combining to the base layer. Again we need to have a neutral value for base layer (vertex normal) in case all weights are zero.
// Compute how much we want to inherit from base layer normal base on the mask. Base layer always fully inherit from "itself" if it's the visible layer.
// Based on this inheritance parameters, fetch a lower level of the base layer normal map so that the less we inherit the more this tends to be "vertex normal"
float maxMipBias = 12.0f; // We arbitrarly choose the max bias for a 2048 texture. Smaller texture will bias toward vertex normal faster.
// Blend all layers but the base one. This will then be added to the "inherited" normal of base layer (that's why base layer here is tangent space vertex normal so that if it's the visible layer we add nothing in term of normal map).
#if defined(_LAYER_MASK_VERTEX_COLOR_MUL) // Used when no layer mask is set
inputMaskValues *= input.color.rgb;
#elif defined(_LAYER_MASK_VERTEX_COLOR_ADD) || defined(_HEIGHT_BASED_BLEND_V2) // When layer mask is set, color is additive to enable user to override it.
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalTS = reflect(normalTS, float3(0.0, 0.0, 1.0)); // Reflect around vertex normal (in tangent space this is z)
#endif
// TODO : Test if GetOddNegativeScale() is necessary here in case of normal map, as GetOddNegativeScale is take into account in CreateTangentToWorld();
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
FindOptionProperties(props);// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindInputProperties(props);
FindCommonOptionProperties(props);// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindMaterialProperties(props);
m_MaterialEditor=materialEditor;
Materialmaterial=materialEditor.targetasMaterial;
if(EditorGUI.EndChangeCheck())
{
foreach(varobjinm_MaterialEditor.targets)
SetupMaterial((Material)obj);
SetupMaterialKeywords((Material)obj);
}
}
EditorGUI.showMixedValue=false;
}
protectedvoidSetupMaterial(Materialmaterial)
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation