浏览代码

Added basemap pass shader.

/main
Yao Xiaoling 6 年前
当前提交
f304d36d
共有 6 个文件被更改,包括 382 次插入10 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLit.shader
  2. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLitData.hlsl
  3. 74
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl
  4. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl.meta
  5. 282
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLit_Basemap.shader
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLit_Basemap.shader.meta

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLit.shader


UsePass "Hidden/Nature/Terrain/Picking/TERRAINPICKING"
}
Dependency "BaseMapShader" = "HDRenderPipeline/TerrainLit_Basemap"
CustomEditor "UnityEditor.Experimental.Rendering.HDPipeline.TerrainLitGUI"
}

17
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLitData.hlsl


GetLayerTexCoord(input, layerTexCoord);
float4 blendMasks = GetBlendMask(layerTexCoord, input.color);
float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord, blendMasks);
float alpha0 = GetSurfaceData0(input, layerTexCoord, surfaceData0, normalTS0, bentNormalTS0);
float alpha1 = GetSurfaceData1(input, layerTexCoord, surfaceData1, normalTS1, bentNormalTS1);
float alpha2 = GetSurfaceData2(input, layerTexCoord, surfaceData2, normalTS2, bentNormalTS2);
float alpha3 = GetSurfaceData3(input, layerTexCoord, surfaceData3, normalTS3, bentNormalTS3);
GetSurfaceData0(input, layerTexCoord, surfaceData0, normalTS0, bentNormalTS0);
GetSurfaceData1(input, layerTexCoord, surfaceData1, normalTS1, bentNormalTS1);
GetSurfaceData2(input, layerTexCoord, surfaceData2, normalTS2, bentNormalTS2);
GetSurfaceData3(input, layerTexCoord, surfaceData3, normalTS3, bentNormalTS3);
ComputeLayerWeights(input, layerTexCoord, float4(alpha0, alpha1, alpha2, alpha3), blendMasks, weights);
// For layered shader, alpha of base color is used as either an opacity mask, a composition mask for inheritance parameters or a density mask.
float alpha = PROP_BLEND_SCALAR(alpha, weights);
ComputeLayerWeights(input, layerTexCoord, float4(1, 1, 1, 1), blendMasks, weights);
float3 normalTS;
float3 bentNormalWS;

#endif
#ifndef _DISABLE_DBUFFER
float alpha = 1;
AddDecalContribution(posInput, surfaceData, alpha);
#endif

}
#endif
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData);
GetBuiltinData(input, surfaceData, 1, bentNormalWS, 0, builtinData);
}
#include "TerrainLitDataMeshModification.hlsl"

74
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl


//-------------------------------------------------------------------------------------
// Fill SurfaceData/Builtin data function
//-------------------------------------------------------------------------------------
#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
#include "../Lit/LitBuiltinData.hlsl"
#include "../Decal/DecalUtilities.hlsl"
TEXTURE2D(_MainTex);
TEXTURE2D(_MetallicTex);
SAMPLER(sampler_MainTex);
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{
// terrain lightmap uvs are always taken from uv0
input.texCoord1 = input.texCoord2 = input.texCoord0;
ApplyDoubleSidedFlipOrMirror(input); // Apply double sided flip on the vertex normal
surfaceData.baseColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.texCoord0).rgb;
surfaceData.perceptualSmoothness = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.texCoord0).a;
surfaceData.ambientOcclusion = 1;
surfaceData.metallic = SAMPLE_TEXTURE2D(_MetallicTex, sampler_MainTex, input.texCoord0).r;
surfaceData.tangentWS = normalize(input.worldToTangent[0].xyz); // The tangent is not normalize in worldToTangent for mikkt. Tag: SURFACE_GRADIENT
surfaceData.subsurfaceMask = 0;
surfaceData.thickness = 1;
surfaceData.diffusionProfile = 0;
surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
// Init other parameters
surfaceData.anisotropy = 0.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.coatMask = 0.0;
surfaceData.iridescenceThickness = 0.0;
surfaceData.iridescenceMask = 0.0;
// Transparency parameters
// Use thickness from SSS
surfaceData.ior = 1.0;
surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
surfaceData.atDistance = 1000000.0;
surfaceData.transmittanceMask = 0.0;
#ifdef SURFACE_GRADIENT
float3 normalTS = float3(0.0, 0.0, 0.0); // No gradient
#else
float3 normalTS = float3(0.0, 0.0, 1.0);
#endif
GetNormalWS(input, V, normalTS, surfaceData.normalWS);
float3 bentNormalWS = surfaceData.normalWS;
surfaceData.specularOcclusion = 1.0;
#ifndef _DISABLE_DBUFFER
float alpha = 1;
AddDecalContribution(posInput, surfaceData, alpha);
#endif
#if defined(DEBUG_DISPLAY)
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, layerTexCoord.base0.uv, _BaseColorMap0, _BaseColorMap0_TexelSize, _BaseColorMap0_MipInfo, surfaceData.baseColor);
surfaceData.metallic = 0;
}
#endif
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, 0, builtinData);
}
#include "TerrainLitDataMeshModification.hlsl"

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl.meta


fileFormatVersion: 2
guid: 1d91d53f274c0e147bfbb8b31e35091f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

282
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLit_Basemap.shader


Shader "HDRenderPipeline/TerrainLit_Basemap"
{
Properties
{
// Following are builtin properties
// Stencil state
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting
[HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 7 // StencilMask.Lighting (fixed at compile time)
[HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 128 // StencilLightingUsage.RegularLighting (fixed at compile time)
[HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 128 // StencilMask.ObjectsVelocity (fixed at compile time)
// Blending state
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
[HideInInspector] _CullMode("__cullmode", Float) = 2.0
[HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal
[HideInInspector] _ZTestGBuffer("_ZTestGBuffer", Int) = 4
[ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0
[Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1
[HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0)
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
// value that exist to identify if the GI emission need to be enabled.
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
// TODO: Fix the code in legacy unity so we can customize the behavior for GI
_EmissionColor("Color", Color) = (1, 1, 1)
_MetallicTex("Metallic (R)", 2D) = "white" {}
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
_MainTex("Albedo", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
[ToggleUI] _SupportDBuffer("Support DBuffer", Float) = 1.0
}
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#pragma shader_feature _DOUBLESIDED_ON
#pragma shader_feature _DISABLE_DBUFFER
//enable GPU instancing support
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
//-------------------------------------------------------------------------------------
// Define
//-------------------------------------------------------------------------------------
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
// Use surface gradient normal mapping as it handle correctly triplanar normal mapping and multiple UVSet
#define SURFACE_GRADIENT
// This shader support vertex modification
#define HAVE_VERTEX_MODIFICATION
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../../ShaderPass/FragInputs.hlsl"
#include "../../ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
#define TERRAINLIT_BASEMAP_SHADER
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
#include "../../Material/Lit/LitProperties.hlsl"
// All our shaders use same name for entry point
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
SubShader
{
// This tags allow to use the shader replacement features
Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" }
// Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe meta pass.
Pass
{
Name "GBuffer" // Name is not used
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
Cull [_CullMode]
ZTest[_ZTestGBuffer]
Stencil
{
WriteMask [_StencilWriteMask]
Ref [_StencilRef]
Comp Always
Pass Replace
}
HLSLPROGRAM
#pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ SHADOWS_SHADOWMASK
#define SHADERPASS SHADERPASS_GBUFFER
#include "../../ShaderVariables.hlsl"
#ifdef DEBUG_DISPLAY
#include "../../Debug/DebugDisplay.hlsl"
#endif
#include "../../Material/Material.hlsl"
#include "TerrainLitSharePass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL
}
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.
Pass
{
Name "META"
Tags{ "LightMode" = "Meta" }
Cull Off
HLSLPROGRAM
// Lightmap memo
// 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.
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "TerrainLitSharePass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL
}
Pass
{
Name "Motion Vectors"
Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)
// If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity
Stencil
{
WriteMask [_StencilWriteMaskMV]
Ref [_StencilRefMV]
Comp Always
Pass Replace
}
Cull[_CullMode]
ZWrite On
HLSLPROGRAM
#define SHADERPASS SHADERPASS_VELOCITY
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitVelocityPass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
Cull[_CullMode]
ZClip [_ZClip]
ZWrite On
ZTest LEqual
ColorMask 0
HLSLPROGRAM
#define SHADERPASS SHADERPASS_SHADOWS
#define USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitDepthPass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{ "LightMode" = "DepthOnly" }
Cull[_CullMode]
ZWrite On
ColorMask 0
HLSLPROGRAM
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitDepthPass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}
Pass
{
Name "Forward" // Name is not used
Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
WriteMask [_StencilWriteMask]
Ref [_StencilRef]
Comp Always
Pass Replace
}
// In case of forward we want to have depth equal for opaque mesh
ZTest [_ZTestDepthEqualForOpaque]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ SHADOWS_SHADOWMASK
// #include "../../Lighting/Forward.hlsl"
//#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS
#define LIGHTLOOP_TILE_PASS
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
#define SHADERPASS SHADERPASS_FORWARD
// In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
#ifndef _SURFACE_TYPE_TRANSPARENT
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
#endif
#include "../../ShaderVariables.hlsl"
#ifdef DEBUG_DISPLAY
#include "../../Debug/DebugDisplay.hlsl"
#endif
#include "../../Lighting/Lighting.hlsl"
#include "TerrainLitSharePass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassForward.hlsl"
ENDHLSL
}
UsePass "Hidden/Nature/Terrain/Picking/TERRAINPICKING"
}
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/TerrainLit/TerrainLit_Basemap.shader.meta


fileFormatVersion: 2
guid: 153d8e9d335a52c4e9843423e660a548
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存