Andre McGrail
7 年前
当前提交
35e631d7
共有 27 个文件被更改,包括 1155 次插入 和 247 次删除
-
8ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain.meta
-
8ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain.meta
-
108ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/InputSurfaceGrass.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/InputSurfaceGrass.hlsl.meta
-
31ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/InputSurfaceTerrain.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/InputSurfaceTerrain.hlsl.meta
-
41ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/InputSurfaceTerrainBase.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/InputSurfaceTerrainBase.hlsl.meta
-
40ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassDepthOnlyGrass.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassDepthOnlyGrass.hlsl.meta
-
158ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitGrass.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitGrass.hlsl.meta
-
165ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl.meta
-
114ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrain.shader
-
69ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainAddPass.shader
-
10ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainAddPass.shader.meta
-
143ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainBase.shader
-
10ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainBase.shader.meta
-
89ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrass.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrass.shader.meta
-
89ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrassBillboard.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrassBillboard.shader.meta
-
247ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardTerrain.shader
-
0/ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrain.shader.meta
|
|||
fileFormatVersion: 2 |
|||
guid: efa36c22af7d342ad888a01f6eecabb4 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cf2defa266cfe43e59a7230ff55c6107 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_GRASS_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_GRASS_INCLUDED |
|||
|
|||
#include "../Core.hlsl" |
|||
#include "../InputSurfaceCommon.hlsl" |
|||
|
|||
// Terrain engine shader helpers |
|||
CBUFFER_START(TerrainGrass) |
|||
half4 _WavingTint; |
|||
float4 _WaveAndDistance; // wind speed, wave size, wind amount, max sqr distance |
|||
float4 _CameraPosition; // .xyz = camera position, .w = 1 / (max sqr distance) |
|||
float3 _CameraRight, _CameraUp; |
|||
CBUFFER_END |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half4 _SpecColor; |
|||
half4 _EmissionColor; |
|||
half _Cutoff; |
|||
half _Shininess; |
|||
CBUFFER_END |
|||
|
|||
// ---- Grass helpers |
|||
|
|||
// Calculate a 4 fast sine-cosine pairs |
|||
// val: the 4 input values - each must be in the range (0 to 1) |
|||
// s: The sine of each of the 4 values |
|||
// c: The cosine of each of the 4 values |
|||
void FastSinCos (float4 val, out float4 s, out float4 c) { |
|||
val = val * 6.408849 - 3.1415927; |
|||
// powers for taylor series |
|||
float4 r5 = val * val; // wavevec ^ 2 |
|||
float4 r6 = r5 * r5; // wavevec ^ 4; |
|||
float4 r7 = r6 * r5; // wavevec ^ 6; |
|||
float4 r8 = r6 * r5; // wavevec ^ 8; |
|||
|
|||
float4 r1 = r5 * val; // wavevec ^ 3 |
|||
float4 r2 = r1 * r5; // wavevec ^ 5; |
|||
float4 r3 = r2 * r5; // wavevec ^ 7; |
|||
|
|||
|
|||
//Vectors for taylor's series expansion of sin and cos |
|||
float4 sin7 = {1, -0.16161616, 0.0083333, -0.00019841}; |
|||
float4 cos8 = {-0.5, 0.041666666, -0.0013888889, 0.000024801587}; |
|||
|
|||
// sin |
|||
s = val + r1 * sin7.y + r2 * sin7.z + r3 * sin7.w; |
|||
|
|||
// cos |
|||
c = 1 + r5 * cos8.x + r6 * cos8.y + r7 * cos8.z + r8 * cos8.w; |
|||
} |
|||
|
|||
half4 TerrainWaveGrass (inout float4 vertex, float waveAmount, half4 color) |
|||
{ |
|||
half4 _waveXSize = half4(0.012, 0.02, 0.06, 0.024) * _WaveAndDistance.y; |
|||
half4 _waveZSize = half4 (0.006, .02, 0.02, 0.05) * _WaveAndDistance.y; |
|||
half4 waveSpeed = half4 (1.2, 2, 1.6, 4.8); |
|||
|
|||
half4 _waveXmove = half4(0.024, 0.04, -0.12, 0.096); |
|||
half4 _waveZmove = half4 (0.006, .02, -0.02, 0.1); |
|||
|
|||
float4 waves; |
|||
waves = vertex.x * _waveXSize; |
|||
waves += vertex.z * _waveZSize; |
|||
|
|||
// Add in time to model them over time |
|||
waves += _WaveAndDistance.x * waveSpeed; |
|||
|
|||
float4 s, c; |
|||
waves = frac (waves); |
|||
FastSinCos (waves, s,c); |
|||
|
|||
s = s * s; |
|||
|
|||
s = s * s; |
|||
|
|||
half lighting = dot (s, normalize (half4 (1,1,.4,.2))) * 0.7; |
|||
|
|||
s = s * waveAmount; |
|||
|
|||
half3 waveMove = 0; |
|||
waveMove.x = dot (s, _waveXmove); |
|||
waveMove.z = dot (s, _waveZmove); |
|||
|
|||
vertex.xz -= waveMove.xz * _WaveAndDistance.z; |
|||
|
|||
// apply color animation |
|||
half3 waveColor = lerp (0.5, _WavingTint.rgb, lighting); |
|||
|
|||
// Fade the grass out before detail distance. |
|||
// Saturate because Radeon HD drivers on OS X 10.4.10 don't saturate vertex colors properly. |
|||
half3 offset = vertex.xyz - _CameraPosition.xyz; |
|||
color.a = saturate (2 * (_WaveAndDistance.w - dot (offset, offset)) * _CameraPosition.w); |
|||
|
|||
return half4(2 * waveColor * color.rgb, color.a); |
|||
} |
|||
|
|||
void TerrainBillboardGrass( inout float4 pos, float2 offset ) |
|||
{ |
|||
float3 grasspos = pos.xyz - _CameraPosition.xyz; |
|||
if (dot(grasspos, grasspos) > _WaveAndDistance.w) |
|||
offset = 0.0; |
|||
pos.xyz += offset.x * _CameraRight.xyz; |
|||
pos.y += offset.y; |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_GRASS_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: ca55f7593a02f4c1ab1bdbc03282d7af |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|||
|
|||
#include "LWRP/ShaderLibrary/Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
#include "LWRP/ShaderLibrary/InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(_Terrain) |
|||
half _Metallic0, _Metallic1, _Metallic2, _Metallic3; |
|||
half _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3; |
|||
|
|||
float4 _Control_ST; |
|||
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_Control); SAMPLER(sampler_Control); |
|||
TEXTURE2D(_Splat0); SAMPLER(sampler_Splat0); |
|||
TEXTURE2D(_Splat1); |
|||
TEXTURE2D(_Splat2); |
|||
TEXTURE2D(_Splat3); |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
TEXTURE2D(_Normal0); SAMPLER(sampler_Normal0); |
|||
TEXTURE2D(_Normal1); |
|||
TEXTURE2D(_Normal2); |
|||
TEXTURE2D(_Normal3); |
|||
#endif |
|||
|
|||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap); |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: a817cb90496894b368593402e13b040c |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_TERRAIN_BASE_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_TERRAIN_BASE_INCLUDED |
|||
|
|||
#include "LWRP/ShaderLibrary/Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
#include "LWRP/ShaderLibrary/InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half _Cutoff; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_MetallicTex); SAMPLER(sampler_MetallicTex); |
|||
|
|||
half4 SampleMetallicSpecGloss(float2 uv, half albedoAlpha) |
|||
{ |
|||
half4 specGloss; |
|||
specGloss = SAMPLE_TEXTURE2D(_MetallicTex, sampler_MetallicTex, uv); |
|||
specGloss.a = albedoAlpha; |
|||
return specGloss; |
|||
} |
|||
|
|||
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) |
|||
{ |
|||
half4 albedoSmoothness= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv); |
|||
outSurfaceData.alpha = 1; |
|||
|
|||
half4 specGloss = SampleMetallicSpecGloss(uv, albedoSmoothness.a); |
|||
outSurfaceData.albedo = albedoSmoothness.rgb; |
|||
|
|||
outSurfaceData.metallic = specGloss.r; |
|||
outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h); |
|||
|
|||
outSurfaceData.smoothness = specGloss.a; |
|||
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap)); |
|||
outSurfaceData.occlusion = 1; |
|||
outSurfaceData.emission = 0; |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_TERRAIN_BASE_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: fbd614929e4f04b8584f224142f1259d |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_DEPTH_ONLY_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_DEPTH_ONLY_INCLUDED |
|||
|
|||
#include "LWRP/ShaderLibrary/Core.hlsl" |
|||
|
|||
struct VertexInput |
|||
{ |
|||
float4 position : POSITION; |
|||
half4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct VertexOutput |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
half4 color : TEXCOORD1; |
|||
float4 clipPos : SV_POSITION; |
|||
}; |
|||
|
|||
VertexOutput DepthOnlyVertex(VertexInput v) |
|||
{ |
|||
VertexOutput o = (VertexOutput)0; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
|
|||
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
// MeshGrass v.color.a: 1 on top vertices, 0 on bottom vertices |
|||
// _WaveAndDistance.z == 0 for MeshLit |
|||
float waveAmount = v.color.a * _WaveAndDistance.z; |
|||
o.color = TerrainWaveGrass (v.position, waveAmount, v.color); |
|||
o.clipPos = TransformObjectToHClip(v.position.xyz); |
|||
return o; |
|||
} |
|||
|
|||
half4 DepthOnlyFragment(VertexOutput IN) : SV_TARGET |
|||
{ |
|||
Alpha(SampleAlbedoAlpha(IN.uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)).a, IN.color, _Cutoff); |
|||
return 0; |
|||
} |
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 4f907bbd39d214935a038247d3b26b9b |
|||
timeCreated: 1488965025 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_LIT_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_LIT_INCLUDED |
|||
|
|||
#include "LWRP/ShaderLibrary/Lighting.hlsl" |
|||
|
|||
struct GrassVertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
float4 tangent : TANGENT; |
|||
half4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 lightmapUV : TEXCOORD1; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct GrassVertexOutput |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1); |
|||
|
|||
float4 posWSShininess : TEXCOORD2; // xyz: posWS, w: Shininess * 128 |
|||
|
|||
half3 normal : TEXCOORD3; |
|||
half3 viewDir : TEXCOORD4; |
|||
|
|||
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light |
|||
|
|||
#ifdef _SHADOWS_ENABLED |
|||
float4 shadowCoord : TEXCOORD6; |
|||
#endif |
|||
half4 color : TEXCOORD7; |
|||
|
|||
float4 clipPos : SV_POSITION; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
void InitializeInputData(GrassVertexOutput IN, out InputData inputData) |
|||
{ |
|||
inputData.positionWS = IN.posWSShininess.xyz; |
|||
|
|||
half3 viewDir = IN.viewDir; |
|||
inputData.normalWS = FragmentNormalWS(IN.normal); |
|||
|
|||
inputData.viewDirectionWS = FragmentViewDirWS(viewDir); |
|||
#ifdef _SHADOWS_ENABLED |
|||
inputData.shadowCoord = IN.shadowCoord; |
|||
#else |
|||
inputData.shadowCoord = float4(0, 0, 0, 0); |
|||
#endif |
|||
inputData.fogCoord = IN.fogFactorAndVertexLight.x; |
|||
inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; |
|||
inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.vertexSH, inputData.normalWS); |
|||
} |
|||
|
|||
void InitializeVertData(GrassVertexInput IN, inout GrassVertexOutput vertData) |
|||
{ |
|||
vertData.uv = IN.texcoord; |
|||
|
|||
vertData.posWSShininess.xyz = TransformObjectToWorld(IN.vertex.xyz); |
|||
vertData.posWSShininess.w = 32; |
|||
vertData.clipPos = TransformWorldToHClip(vertData.posWSShininess.xyz); |
|||
|
|||
half3 viewDir = VertexViewDirWS(GetCameraPositionWS() - vertData.posWSShininess.xyz); |
|||
vertData.viewDir = viewDir; |
|||
// initializes o.normal and if _NORMALMAP also o.tangent and o.binormal |
|||
OUTPUT_NORMAL(IN, vertData); |
|||
|
|||
// We either sample GI from lightmap or SH. |
|||
// Lightmap UV and vertex SH coefficients use the same interpolator ("float2 lightmapUV" for lightmap or "half3 vertexSH" for SH) |
|||
// see DECLARE_LIGHTMAP_OR_SH macro. |
|||
// The following funcions initialize the correct variable with correct data |
|||
OUTPUT_LIGHTMAP_UV(IN.lightmapUV, unity_LightmapST, vertData.lightmapUV); |
|||
OUTPUT_SH(vertData.normal.xyz, vertData.vertexSH); |
|||
|
|||
half3 vertexLight = VertexLighting(vertData.posWSShininess.xyz, vertData.normal.xyz); |
|||
half fogFactor = ComputeFogFactor(vertData.clipPos.z); |
|||
vertData.fogFactorAndVertexLight = half4(fogFactor, vertexLight); |
|||
|
|||
#ifdef _SHADOWS_ENABLED |
|||
#if SHADOWS_SCREEN |
|||
vertData.shadowCoord = ComputeShadowCoord(vertData.clipPos); |
|||
#else |
|||
vertData.shadowCoord = TransformWorldToShadowCoord(vertData.posWSShininess.xyz); |
|||
#endif |
|||
#endif |
|||
} |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
// Vertex and Fragment functions // |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
|
|||
// Grass: appdata_full usage |
|||
// color - .xyz = color, .w = wave scale |
|||
// normal - normal |
|||
// tangent.xy - billboard extrusion |
|||
// texcoord - UV coords |
|||
// texcoord1 - 2nd UV coords |
|||
|
|||
GrassVertexOutput WavingGrassVert(GrassVertexInput v) |
|||
{ |
|||
GrassVertexOutput o = (GrassVertexOutput)0; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_TRANSFER_INSTANCE_ID(v, o); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
|
|||
// MeshGrass v.color.a: 1 on top vertices, 0 on bottom vertices |
|||
// _WaveAndDistance.z == 0 for MeshLit |
|||
float waveAmount = v.color.a * _WaveAndDistance.z; |
|||
o.color = TerrainWaveGrass (v.vertex, waveAmount, v.color); |
|||
|
|||
InitializeVertData(v, o); |
|||
|
|||
return o; |
|||
} |
|||
|
|||
GrassVertexOutput WavingGrassBillboardVert(GrassVertexInput v) |
|||
{ |
|||
GrassVertexOutput o = (GrassVertexOutput)0; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_TRANSFER_INSTANCE_ID(v, o); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
|
|||
TerrainBillboardGrass (v.vertex, v.tangent.xy); |
|||
// wave amount defined by the grass height |
|||
float waveAmount = v.tangent.y; |
|||
o.color = TerrainWaveGrass (v.vertex, waveAmount, v.color); |
|||
|
|||
InitializeVertData(v, o); |
|||
|
|||
return o; |
|||
} |
|||
|
|||
// Used for StandardSimpleLighting shader |
|||
half4 LitPassFragmentGrass(GrassVertexOutput IN) : SV_Target |
|||
{ |
|||
UNITY_SETUP_INSTANCE_ID(IN); |
|||
|
|||
float2 uv = IN.uv; |
|||
half4 diffuseAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)); |
|||
half3 diffuse = diffuseAlpha.rgb * IN.color.rgb; |
|||
|
|||
half alpha = diffuseAlpha.a; |
|||
AlphaDiscard(alpha, _Cutoff); |
|||
alpha *= IN.color.a; |
|||
|
|||
half3 emission = 0; |
|||
half4 specularGloss = 0.1;// SampleSpecularGloss(uv, diffuseAlpha.a, _SpecColor, TEXTURE2D_PARAM(_SpecGlossMap, sampler_SpecGlossMap)); |
|||
half shininess = IN.posWSShininess.w; |
|||
|
|||
InputData inputData; |
|||
InitializeInputData(IN, inputData); |
|||
|
|||
return LightweightFragmentBlinnPhong(inputData, diffuse, specularGloss, shininess, emission, alpha); |
|||
}; |
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: b4bc78a1364154f15b718a412e9710b6 |
|||
timeCreated: 1488965025 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_LIT_TERRAIN_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_LIT_TERRAIN_INCLUDED |
|||
|
|||
#include "LWRP/ShaderLibrary/Lighting.hlsl" |
|||
|
|||
struct VertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float4 tangent : TANGENT; |
|||
float3 normal : NORMAL; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 texcoord1 : TEXCOORD1; |
|||
}; |
|||
|
|||
struct VertexOutput |
|||
{ |
|||
float4 uvSplat01 : TEXCOORD0; // xy: splat0, zw: splat1 |
|||
float4 uvSplat23 : TEXCOORD1; // xy: splat2, zw: splat3 |
|||
float4 uvControlAndLM : TEXCOORD2; // xy: control, zw: lightmap |
|||
half3 normal : TEXCOORD3; |
|||
#if _TERRAIN_NORMAL_MAP |
|||
half3 tangent : TEXCOORD4; |
|||
half3 binormal : TEXCOORD5; |
|||
#endif |
|||
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light |
|||
float3 positionWS : TEXCOORD7; |
|||
float4 shadowCoord : TEXCOORD8; |
|||
float4 clipPos : SV_POSITION; |
|||
}; |
|||
|
|||
void InitializeInputData(VertexOutput IN, half3 normalTS, out InputData input) |
|||
{ |
|||
input = (InputData)0; |
|||
|
|||
input.positionWS = IN.positionWS; |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
input.normalWS = TangentToWorldNormal(normalTS, IN.tangent, IN.binormal, IN.normal); |
|||
#else |
|||
input.normalWS = normalize(IN.normal); |
|||
#endif |
|||
|
|||
input.viewDirectionWS = SafeNormalize(GetCameraPositionWS() - IN.positionWS); |
|||
#ifdef _SHADOWS_ENABLED |
|||
input.shadowCoord = IN.shadowCoord; |
|||
#else |
|||
input.shadowCoord = float4(0, 0, 0, 0); |
|||
#endif |
|||
input.fogCoord = IN.fogFactorAndVertexLight.x; |
|||
input.vertexLighting = IN.fogFactorAndVertexLight.yzw; |
|||
|
|||
#ifdef LIGHTMAP_ON |
|||
input.bakedGI = SampleLightmap(IN.uvControlAndLM.zw, input.normalWS); |
|||
#endif |
|||
} |
|||
|
|||
void SplatmapMix(VertexOutput IN, half4 defaultAlpha, out half4 splat_control, out half weight, out half4 mixedDiffuse, inout half3 mixedNormal) |
|||
{ |
|||
splat_control = SAMPLE_TEXTURE2D(_Control, sampler_Control, IN.uvControlAndLM.xy); |
|||
weight = dot(splat_control, 1); |
|||
|
|||
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS) |
|||
clip(weight == 0.0f ? -1 : 1); |
|||
#endif |
|||
|
|||
// Normalize weights before lighting and restore weights in final modifier functions so that the overal |
|||
// lighting result can be correctly weighted. |
|||
splat_control /= (weight + 1e-3f); |
|||
|
|||
mixedDiffuse = 0.0f; |
|||
mixedDiffuse += splat_control.r * SAMPLE_TEXTURE2D(_Splat0, sampler_Splat0, IN.uvSplat01.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.r); |
|||
mixedDiffuse += splat_control.g * SAMPLE_TEXTURE2D(_Splat1, sampler_Splat0, IN.uvSplat01.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.g); |
|||
mixedDiffuse += splat_control.b * SAMPLE_TEXTURE2D(_Splat2, sampler_Splat0, IN.uvSplat23.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.b); |
|||
mixedDiffuse += splat_control.a * SAMPLE_TEXTURE2D(_Splat3, sampler_Splat0, IN.uvSplat23.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.a); |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
half4 nrm = 0.0f; |
|||
nrm += splat_control.r * SAMPLE_TEXTURE2D(_Normal0, sampler_Normal0, IN.uvSplat01.xy); |
|||
nrm += splat_control.g * SAMPLE_TEXTURE2D(_Normal1, sampler_Normal0, IN.uvSplat01.zw); |
|||
nrm += splat_control.b * SAMPLE_TEXTURE2D(_Normal2, sampler_Normal0, IN.uvSplat23.xy); |
|||
nrm += splat_control.a * SAMPLE_TEXTURE2D(_Normal3, sampler_Normal0, IN.uvSplat23.zw); |
|||
mixedNormal = UnpackNormal(nrm); |
|||
#else |
|||
mixedNormal = half3(0, 0, 1); |
|||
#endif |
|||
} |
|||
|
|||
void SplatmapFinalColor(inout half4 color, half fogCoord) |
|||
{ |
|||
color.rgb *= color.a; |
|||
#ifdef TERRAIN_SPLAT_ADDPASS |
|||
ApplyFogColor(color.rgb, half3(0,0,0), fogCoord); |
|||
#else |
|||
ApplyFog(color.rgb, fogCoord); |
|||
#endif |
|||
} |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
// Vertex and Fragment functions // |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
|
|||
// Used in Standard Terrain shader |
|||
VertexOutput SplatmapVert(VertexInput v) |
|||
{ |
|||
VertexOutput o = (VertexOutput)0; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(v.vertex.xyz); |
|||
float4 clipPos = TransformWorldToHClip(positionWS); |
|||
|
|||
o.uvSplat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0); |
|||
o.uvSplat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1); |
|||
o.uvSplat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2); |
|||
o.uvSplat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3); |
|||
o.uvControlAndLM.xy = TRANSFORM_TEX(v.texcoord, _Control); |
|||
o.uvControlAndLM.zw = v.texcoord1 * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
float4 vertexTangent = float4(cross(v.normal, float3(0, 0, 1)), -1.0); |
|||
OutputTangentToWorld(vertexTangent, v.normal, o.tangent, o.binormal, o.normal); |
|||
#else |
|||
o.normal = TransformObjectToWorldNormal(v.normal); |
|||
#endif |
|||
o.fogFactorAndVertexLight.x = ComputeFogFactor(clipPos.z); |
|||
o.fogFactorAndVertexLight.yzw = VertexLighting(positionWS, o.normal); |
|||
o.positionWS = positionWS; |
|||
o.clipPos = clipPos; |
|||
|
|||
#ifdef _SHADOWS_ENABLED |
|||
#if SHADOWS_SCREEN |
|||
o.shadowCoord = ComputeShadowCoord(o.clipPos); |
|||
#else |
|||
o.shadowCoord = TransformWorldToShadowCoord(positionWS); |
|||
#endif |
|||
#endif |
|||
|
|||
return o; |
|||
} |
|||
|
|||
// Used in Standard Terrain shader |
|||
half4 SpatmapFragment(VertexOutput IN) : SV_TARGET |
|||
{ |
|||
half4 splat_control; |
|||
half weight; |
|||
half4 mixedDiffuse; |
|||
half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3); |
|||
half3 normalTS; |
|||
SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, normalTS); |
|||
|
|||
half3 albedo = mixedDiffuse.rgb; |
|||
half smoothness = mixedDiffuse.a; |
|||
half metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3)); |
|||
half3 specular = half3(0, 0, 0); |
|||
half alpha = weight; |
|||
|
|||
InputData inputData; |
|||
InitializeInputData(IN, normalTS, inputData); |
|||
half4 color = LightweightFragmentPBR(inputData, albedo, metallic, specular, smoothness, /* occlusion */ 1.0, /* emission */ half3(0, 0, 0), alpha); |
|||
|
|||
SplatmapFinalColor(color, inputData.fogCoord); |
|||
|
|||
return half4(color.rgb, 1); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_PASS_LIT_TERRAIN_INCLUDED |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: ad25529ea2516421ab5f1a2440bee139 |
|||
timeCreated: 1488965025 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "LightweightPipeline/Terrain/Standard Terrain" |
|||
{ |
|||
Properties |
|||
{ |
|||
// set by terrain engine |
|||
[HideInInspector] _Control("Control (RGBA)", 2D) = "red" {} |
|||
[HideInInspector] _Splat3("Layer 3 (A)", 2D) = "white" {} |
|||
[HideInInspector] _Splat2("Layer 2 (B)", 2D) = "white" {} |
|||
[HideInInspector] _Splat1("Layer 1 (G)", 2D) = "white" {} |
|||
[HideInInspector] _Splat0("Layer 0 (R)", 2D) = "white" {} |
|||
[HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {} |
|||
[HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0 |
|||
|
|||
// used in fallback on old cards & base map |
|||
[HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "white" {} |
|||
[HideInInspector] _Color("Main Color", Color) = (1,1,1,1) |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "Queue" = "Geometry-100" "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"} |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "LightMode" = "LightweightForward" } |
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 3.0 |
|||
|
|||
#pragma vertex SplatmapVert |
|||
#pragma fragment SpatmapFragment |
|||
|
|||
#define _METALLICSPECGLOSSMAP 1 |
|||
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1 |
|||
|
|||
// ------------------------------------- |
|||
// Lightweight Pipeline keywords |
|||
#pragma multi_compile _ _ADDITIONAL_LIGHTS |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE |
|||
#pragma multi_compile _ _SHADOWS_ENABLED |
|||
|
|||
// ------------------------------------- |
|||
// Unity defined keywords |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile_fog |
|||
|
|||
#pragma multi_compile __ _TERRAIN_NORMAL_MAP |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrain.hlsl" |
|||
#include "LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "ShadowCaster"} |
|||
|
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
#pragma vertex ShadowPassVertex |
|||
#pragma fragment ShadowPassFragment |
|||
|
|||
#include "LWRP/ShaderLibrary/InputSurfacePBR.hlsl" |
|||
#include "LWRP/ShaderLibrary/LightweightPassShadow.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "DepthOnly"} |
|||
|
|||
ZWrite On |
|||
ColorMask 0 |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
#pragma vertex DepthOnlyVertex |
|||
#pragma fragment DepthOnlyFragment |
|||
|
|||
#include "LWRP/ShaderLibrary/InputSurfacePBR.hlsl" |
|||
#include "LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl" |
|||
ENDHLSL |
|||
} |
|||
} |
|||
Dependency "AddPassShader" = "Hidden/LightweightPipeline/Terrain/Standard Terrain Add Pass" |
|||
Dependency "BaseMapShader" = "Hidden/LightweightPipeline/Terrain/Standard Terrain Base" |
|||
|
|||
Fallback "Hidden/InternalErrorShader" |
|||
} |
|
|||
Shader "Hidden/LightweightPipeline/Terrain/Standard Terrain Add Pass" |
|||
{ |
|||
Properties |
|||
{ |
|||
// set by terrain engine |
|||
[HideInInspector] _Control("Control (RGBA)", 2D) = "red" {} |
|||
[HideInInspector] _Splat3("Layer 3 (A)", 2D) = "white" {} |
|||
[HideInInspector] _Splat2("Layer 2 (B)", 2D) = "white" {} |
|||
[HideInInspector] _Splat1("Layer 1 (G)", 2D) = "white" {} |
|||
[HideInInspector] _Splat0("Layer 0 (R)", 2D) = "white" {} |
|||
[HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {} |
|||
[HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0 |
|||
|
|||
// used in fallback on old cards & base map |
|||
[HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "white" {} |
|||
[HideInInspector] _Color("Main Color", Color) = (1,1,1,1) |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "Queue" = "Geometry-99" "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"} |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "LightMode" = "LightweightForward" } |
|||
Blend One One |
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 3.0 |
|||
|
|||
#pragma vertex SplatmapVert |
|||
#pragma fragment SpatmapFragment |
|||
|
|||
// ------------------------------------- |
|||
// Lightweight Pipeline keywords |
|||
#pragma multi_compile _ _ADDITIONAL_LIGHTS |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE |
|||
#pragma multi_compile _ _SHADOWS_ENABLED |
|||
|
|||
// ------------------------------------- |
|||
// Unity defined keywords |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile_fog |
|||
|
|||
#pragma multi_compile __ _TERRAIN_NORMAL_MAP |
|||
#define TERRAIN_SPLAT_ADDPASS 1 |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrain.hlsl" |
|||
#include "LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
Fallback "Hidden/InternalErrorShader" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0a7e590f3cf1d4ee8a8fab5b6eff09ef |
|||
timeCreated: 1508929790 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/LightweightPipeline/Terrain/Standard Terrain Base" |
|||
{ |
|||
Properties |
|||
{ |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_MainTex("Albedo(RGB), Smoothness(A)", 2D) = "white" {} |
|||
_MetallicTex ("Metallic (R)", 2D) = "black" {} |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "Queue" = "Geometry-100" "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"} |
|||
LOD 200 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Forward pass. Shades all light in a single pass. GI + emission + Fog |
|||
Pass |
|||
{ |
|||
// Lightmode matches the ShaderPassName set in LightweightPipeline.cs. SRPDefaultUnlit and passes with |
|||
// no LightMode tag are also rendered by Lightweight Pipeline |
|||
Tags{"LightMode" = "LightweightForward"} |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard SRP library |
|||
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
// ------------------------------------- |
|||
// Material Keywords |
|||
#define _METALLICSPECGLOSSMAP 1 |
|||
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1 |
|||
|
|||
// ------------------------------------- |
|||
// Lightweight Pipeline keywords |
|||
#pragma multi_compile _ _ADDITIONAL_LIGHTS |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE |
|||
#pragma multi_compile _ _SHADOWS_ENABLED |
|||
|
|||
// TODO: Enabled this when we have C# keyword stripping |
|||
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED |
|||
|
|||
// ------------------------------------- |
|||
// Unity defined keywords |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile_fog |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
|
|||
#pragma vertex LitPassVertex |
|||
#pragma fragment LitPassFragment |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrainBase.hlsl" |
|||
#include "LWRP/ShaderLibrary/LightweightPassLit.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "ShadowCaster"} |
|||
|
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1 |
|||
|
|||
#pragma vertex ShadowPassVertex |
|||
#pragma fragment ShadowPassFragment |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrainBase.hlsl" |
|||
#include "LWRP/ShaderLibrary/LightweightPassShadow.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "DepthOnly"} |
|||
|
|||
ZWrite On |
|||
ColorMask 0 |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
#pragma vertex DepthOnlyVertex |
|||
#pragma fragment DepthOnlyFragment |
|||
|
|||
#define _METALLICSPECGLOSSMAP 1 |
|||
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1 |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrainBase.hlsl" |
|||
#include "LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
// This pass it not used during regular rendering, only for lightmap baking. |
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "Meta"} |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
#pragma vertex LightweightVertexMeta |
|||
#pragma fragment LightweightFragmentMeta |
|||
|
|||
#define _METALLICSPECGLOSSMAP 1 |
|||
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1 |
|||
#pragma shader_feature EDITOR_VISUALIZATION |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrainBase.hlsl" |
|||
#include "LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
} |
|||
FallBack "Hidden/InternalErrorShader" |
|||
CustomEditor "LightweightStandardGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dd20536f4428f4376af4032e17f6add0 |
|||
timeCreated: 1503472755 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) |
|||
Shader "Hidden/TerrainEngine/Details/WavingDoublePass" // Has to override the internal shaders so named like this |
|||
{ |
|||
Properties |
|||
{ |
|||
_WavingTint ("Fade Color", Color) = (.7,.6,.5, 0) |
|||
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {} |
|||
_WaveAndDistance ("Wave and distance", Vector) = (12, 3.6, 1, 1) |
|||
_Cutoff ("Cutoff", float) = 0.5 |
|||
} |
|||
SubShader |
|||
{ |
|||
Tags {"Queue" = "Geometry+200" "RenderType" = "Grass" "IgnoreProjectors" = "True" "RenderPipeline" = "LightweightPipeline" }//"DisableBatching"="True" |
|||
Cull Off |
|||
LOD 200 |
|||
AlphaTest Greater [_Cutoff] |
|||
ColorMask RGB |
|||
|
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
// ------------------------------------- |
|||
// Lightweight Pipeline keywords |
|||
#pragma multi_compile _ _ADDITIONAL_LIGHTS |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE |
|||
#pragma multi_compile _ _SHADOWS_ENABLED |
|||
|
|||
// TODO: Enabled this when we have C# keyword stripping |
|||
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED |
|||
|
|||
// ------------------------------------- |
|||
// Unity defined keywords |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile_fog |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
|
|||
#pragma vertex WavingGrassVert |
|||
#pragma fragment LitPassFragmentGrass |
|||
#define _ALPHATEST_ON |
|||
|
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceGrass.hlsl" |
|||
#include "LWRP/ShaderLibrary/Terrain/LightweightPassLitGrass.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "DepthOnly"} |
|||
|
|||
ZWrite On |
|||
ColorMask 0 |
|||
Cull Off |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
#pragma vertex DepthOnlyVertex |
|||
#pragma fragment DepthOnlyFragment |
|||
|
|||
// ------------------------------------- |
|||
// Material Keywords |
|||
#define _ALPHATEST_ON |
|||
#pragma shader_feature _GLOSSINESS_FROM_BASE_ALPHA |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceGrass.hlsl" |
|||
#include "LWRP/ShaderLibrary/Terrain/LightweightPassDepthOnlyGrass.hlsl" |
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e507fdfead5ca47e8b9a768b51c291a1 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) |
|||
Shader "Hidden/TerrainEngine/Details/BillboardWavingDoublePass" // Has to override the internal shaders so named like this |
|||
{ |
|||
Properties |
|||
{ |
|||
_WavingTint ("Fade Color", Color) = (.7,.6,.5, 0) |
|||
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {} |
|||
_WaveAndDistance ("Wave and distance", Vector) = (12, 3.6, 1, 1) |
|||
_Cutoff ("Cutoff", float) = 0.5 |
|||
} |
|||
SubShader |
|||
{ |
|||
Tags {"Queue" = "Geometry+200" "RenderType" = "GrassBillBoard" "IgnoreProjectors" = "True" "RenderPipeline" = "LightweightPipeline" }//"DisableBatching"="True" |
|||
Cull Off |
|||
LOD 200 |
|||
AlphaTest Greater [_Cutoff] |
|||
ColorMask RGB |
|||
|
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
// ------------------------------------- |
|||
// Lightweight Pipeline keywords |
|||
#pragma multi_compile _ _ADDITIONAL_LIGHTS |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE |
|||
#pragma multi_compile _ _SHADOWS_ENABLED |
|||
|
|||
// TODO: Enabled this when we have C# keyword stripping |
|||
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED |
|||
|
|||
// ------------------------------------- |
|||
// Unity defined keywords |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile_fog |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
|
|||
#pragma vertex WavingGrassBillboardVert |
|||
#pragma fragment LitPassFragmentGrass |
|||
#define _ALPHATEST_ON |
|||
|
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceGrass.hlsl" |
|||
#include "LWRP/ShaderLibrary/Terrain/LightweightPassLitGrass.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "DepthOnly"} |
|||
|
|||
ZWrite On |
|||
ColorMask 0 |
|||
Cull Off |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
|
|||
#pragma vertex DepthOnlyVertex |
|||
#pragma fragment DepthOnlyFragment |
|||
|
|||
// ------------------------------------- |
|||
// Material Keywords |
|||
#define _ALPHATEST_ON |
|||
#pragma shader_feature _GLOSSINESS_FROM_BASE_ALPHA |
|||
|
|||
//-------------------------------------- |
|||
// GPU Instancing |
|||
#pragma multi_compile_instancing |
|||
|
|||
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceGrass.hlsl" |
|||
#include "LWRP/ShaderLibrary/Terrain/LightweightPassDepthOnlyGrass.hlsl" |
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 29868e73b638e48ca99a19ea58c48d90 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "LightweightPipeline/Standard Terrain" |
|||
{ |
|||
Properties |
|||
{ |
|||
// set by terrain engine |
|||
[HideInInspector] _Control("Control (RGBA)", 2D) = "red" {} |
|||
[HideInInspector] _Splat3("Layer 3 (A)", 2D) = "white" {} |
|||
[HideInInspector] _Splat2("Layer 2 (B)", 2D) = "white" {} |
|||
[HideInInspector] _Splat1("Layer 1 (G)", 2D) = "white" {} |
|||
[HideInInspector] _Splat0("Layer 0 (R)", 2D) = "white" {} |
|||
[HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {} |
|||
[HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {} |
|||
[HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0 |
|||
[HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0 |
|||
[HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0 |
|||
|
|||
// used in fallback on old cards & base map |
|||
[HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "white" {} |
|||
[HideInInspector] _Color("Main Color", Color) = (1,1,1,1) |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "Queue" = "Geometry-100" "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"} |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "LightMode" = "LightweightForward" } |
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 3.0 |
|||
|
|||
#pragma vertex SplatmapVert |
|||
#pragma fragment SpatmapFragment |
|||
|
|||
// ------------------------------------- |
|||
// Lightweight Pipeline keywords |
|||
#pragma multi_compile _ _ADDITIONAL_LIGHTS |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE |
|||
#pragma multi_compile _ _SHADOWS_ENABLED |
|||
|
|||
// ------------------------------------- |
|||
// Unity defined keywords |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile_fog |
|||
|
|||
#pragma multi_compile __ _TERRAIN_NORMAL_MAP |
|||
|
|||
#include "LWRP/ShaderLibrary/Lighting.hlsl" |
|||
|
|||
CBUFFER_START(_Terrain) |
|||
half _Metallic0; |
|||
half _Metallic1; |
|||
half _Metallic2; |
|||
half _Metallic3; |
|||
|
|||
half _Smoothness0; |
|||
half _Smoothness1; |
|||
half _Smoothness2; |
|||
half _Smoothness3; |
|||
|
|||
float4 _Control_ST; |
|||
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST; |
|||
CBUFFER_END |
|||
|
|||
sampler2D _Control; |
|||
sampler2D _Splat0, _Splat1, _Splat2, _Splat3; |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
sampler2D _Normal0, _Normal1, _Normal2, _Normal3; |
|||
#endif |
|||
|
|||
struct VertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float4 tangent : TANGENT; |
|||
float3 normal : NORMAL; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 texcoord1 : TEXCOORD1; |
|||
}; |
|||
|
|||
struct VertexOutput |
|||
{ |
|||
float4 uvSplat01 : TEXCOORD0; // xy: splat0, zw: splat1 |
|||
float4 uvSplat23 : TEXCOORD1; // xy: splat2, zw: splat3 |
|||
float4 uvControlAndLM : TEXCOORD2; // xy: control, zw: lightmap |
|||
half3 normal : TEXCOORD3; |
|||
|
|||
#if _TERRAIN_NORMAL_MAP |
|||
half3 tangent : TEXCOORD4; |
|||
half3 binormal : TEXCOORD5; |
|||
#endif |
|||
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light |
|||
float3 positionWS : TEXCOORD7; |
|||
float4 shadowCoord : TEXCOORD8; |
|||
float4 clipPos : SV_POSITION; |
|||
}; |
|||
|
|||
void InitializeInputData(VertexOutput IN, half3 normalTS, out InputData input) |
|||
{ |
|||
input = (InputData)0; |
|||
input.positionWS = IN.positionWS; |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
input.normalWS = TangentToWorldNormal(normalTS, IN.tangent, IN.binormal, IN.normal); |
|||
#else |
|||
input.normalWS = normalize(IN.normal); |
|||
#endif |
|||
|
|||
input.viewDirectionWS = SafeNormalize(GetCameraPositionWS() - IN.positionWS); |
|||
input.shadowCoord = IN.shadowCoord; |
|||
|
|||
input.fogCoord = IN.fogFactorAndVertexLight.x; |
|||
|
|||
#ifdef LIGHTMAP_ON |
|||
input.bakedGI = SampleLightmap(IN.uvControlAndLM.zw, input.normalWS); |
|||
#endif |
|||
} |
|||
|
|||
void SplatmapMix(VertexOutput IN, half4 defaultAlpha, out half4 splat_control, out half weight, out half4 mixedDiffuse, inout half3 mixedNormal) |
|||
{ |
|||
splat_control = tex2D(_Control, IN.uvControlAndLM.xy); |
|||
weight = dot(splat_control, half4(1, 1, 1, 1)); |
|||
|
|||
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS) |
|||
clip(weight == 0.0f ? -1 : 1); |
|||
#endif |
|||
|
|||
// Normalize weights before lighting and restore weights in final modifier functions so that the overal |
|||
// lighting result can be correctly weighted. |
|||
splat_control /= (weight + 1e-3f); |
|||
|
|||
mixedDiffuse = 0.0f; |
|||
mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.uvSplat01.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.r); |
|||
mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.uvSplat01.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.g); |
|||
mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.uvSplat23.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.b); |
|||
mixedDiffuse += splat_control.a * tex2D(_Splat3, IN.uvSplat23.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.a); |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
half4 nrm = 0.0f; |
|||
nrm += splat_control.r * tex2D(_Normal0, IN.uvSplat01.xy); |
|||
nrm += splat_control.g * tex2D(_Normal1, IN.uvSplat01.zw); |
|||
nrm += splat_control.b * tex2D(_Normal2, IN.uvSplat23.xy); |
|||
nrm += splat_control.a * tex2D(_Normal3, IN.uvSplat23.zw); |
|||
mixedNormal = UnpackNormal(nrm); |
|||
#else |
|||
mixedNormal = half3(0, 0, 1); |
|||
#endif |
|||
} |
|||
|
|||
VertexOutput SplatmapVert(VertexInput v) |
|||
{ |
|||
VertexOutput o = (VertexOutput)0; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(v.vertex.xyz); |
|||
float4 clipPos = TransformWorldToHClip(positionWS); |
|||
|
|||
o.uvSplat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0); |
|||
o.uvSplat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1); |
|||
o.uvSplat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2); |
|||
o.uvSplat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3); |
|||
o.uvControlAndLM.xy = TRANSFORM_TEX(v.texcoord, _Control); |
|||
o.uvControlAndLM.zw = v.texcoord1 * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
|
|||
#ifdef _TERRAIN_NORMAL_MAP |
|||
float4 vertexTangent = float4(cross(v.normal, float3(0, 0, 1)), -1.0); |
|||
OutputTangentToWorld(vertexTangent, v.normal, o.tangent, o.binormal, o.normal); |
|||
#else |
|||
o.normal = TransformObjectToWorldNormal(v.normal); |
|||
#endif |
|||
o.fogFactorAndVertexLight.x = ComputeFogFactor(clipPos.z); |
|||
o.fogFactorAndVertexLight.yzw = VertexLighting(positionWS, o.normal); |
|||
o.positionWS = positionWS; |
|||
o.clipPos = clipPos; |
|||
o.shadowCoord = ComputeScreenPos(o.clipPos); |
|||
|
|||
return o; |
|||
} |
|||
|
|||
half4 SpatmapFragment(VertexOutput IN) : SV_TARGET |
|||
{ |
|||
half4 splat_control; |
|||
half weight; |
|||
half4 mixedDiffuse; |
|||
half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3); |
|||
half3 normalTS; |
|||
SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, normalTS); |
|||
|
|||
half3 albedo = mixedDiffuse.rgb; |
|||
half smoothness = mixedDiffuse.a; |
|||
half metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3)); |
|||
half3 specular = half3(0, 0, 0); |
|||
half alpha = weight; |
|||
|
|||
InputData inputData; |
|||
InitializeInputData(IN, normalTS, inputData); |
|||
half4 color = LightweightFragmentPBR(inputData, albedo, metallic, specular, smoothness, /* occlusion */ 1.0, /* emission */ half3(0, 0, 0), alpha); |
|||
|
|||
ApplyFog(color.rgb, inputData.fogCoord); |
|||
return color; |
|||
} |
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"Lightmode" = "DepthOnly"} |
|||
|
|||
ZWrite On |
|||
ColorMask 0 |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma target 2.0 |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "LWRP/ShaderLibrary/Core.hlsl" |
|||
|
|||
float4 vert(float4 pos : POSITION) : SV_POSITION |
|||
{ |
|||
return TransformObjectToHClip(pos.xyz); |
|||
} |
|||
|
|||
half4 frag() : SV_TARGET |
|||
{ |
|||
return 0; |
|||
} |
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
Fallback "Hidden/InternalErrorShader" |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue