Andre McGrail
7 年前
当前提交
3e297a4c
共有 14 个文件被更改,包括 547 次插入 和 353 次删除
-
2Assets/LightweightAsset.asset
-
10Assets/Objects/environment/Trees/Materials/Softvegetation.mat
-
11Assets/Objects/environment/Trees/Materials/Trees.mat
-
2Assets/Objects/props/props/Matr_Props.mat
-
3Assets/Shaders/CustomTerrain.ShaderGraph
-
33Assets/Shaders/LWSoftVegetationShader.shader
-
318Assets/Shaders/LWVegetationShader.shader
-
131Assets/Shaders/NewUnlitShader.shader
-
2Assets/Shaders/NewUnlitShader.shader.meta
-
3Assets/Shaders/PackedPBR.ShaderGraph
-
275Assets/scenes/Island.unity
-
2ProjectSettings/ProjectSettings.asset
-
99Assets/Shaders/Vegetation.hlsl
-
9Assets/Shaders/Vegetation.hlsl.meta
3
Assets/Shaders/CustomTerrain.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
3
Assets/Shaders/PackedPBR.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
#include "LWRP/ShaderLibrary/Lighting.hlsl" |
|||
|
|||
struct VegetationVertexInput |
|||
{ |
|||
float4 position : POSITION; |
|||
float3 normal : NORMAL; |
|||
float4 tangent : TANGENT; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 lightmapUV : TEXCOORD1; |
|||
float4 color : COLOR; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct VegetationVertexOutput |
|||
{ |
|||
float3 uv : TEXCOORD0;//z holds vert AO |
|||
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1); |
|||
float3 posWS : TEXCOORD2; |
|||
|
|||
#ifdef _NORMALMAP |
|||
half4 normal : TEXCOORD3; // xyz: normal, w: viewDir.x |
|||
half4 tangent : TEXCOORD4; // xyz: tangent, w: viewDir.y |
|||
half4 binormal : TEXCOORD5; // xyz: binormal, w: viewDir.z |
|||
#else |
|||
half3 normal : TEXCOORD3; |
|||
half3 viewDir : TEXCOORD4; |
|||
#endif |
|||
|
|||
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light |
|||
|
|||
#ifdef _SHADOWS_ENABLED |
|||
float4 shadowCoord : TEXCOORD7; |
|||
#endif |
|||
|
|||
float4 clipPos : SV_POSITION; |
|||
half occlusion : TEXCOORD8; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
UNITY_INSTANCING_BUFFER_START(Props) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, _Position) |
|||
UNITY_INSTANCING_BUFFER_END(Props) |
|||
|
|||
/////////////////////////////////////vegetation stuff////////////////////////////////////////////////// |
|||
float4 SmoothCurve( float4 x ) { |
|||
return x * x *( 3.0 - 2.0 * x ); |
|||
} |
|||
|
|||
float4 TriangleWave( float4 x ) { |
|||
return abs( frac( x + 0.5 ) * 2.0 - 1.0 ); |
|||
} |
|||
|
|||
float4 SmoothTriangleWave( float4 x ) { |
|||
return SmoothCurve( TriangleWave( x ) ); |
|||
} |
|||
|
|||
float3 VegetationDeformation(float3 position, float3 origin, float3 normal, half leafStiffness, half branchStiffness, half phaseOffset) |
|||
{ |
|||
///////Main Bending |
|||
float fBendScale = 0.05;//main bend opacity |
|||
float fLength = length(position);//distance to origin |
|||
float2 vWind = float2(sin(_Time.y + origin.x) * 0.1, sin(_Time.y + origin.z) * 0.1);//wind direction |
|||
|
|||
// Bend factor - Wind variation is done on the CPU. |
|||
float fBF = position.y * fBendScale; |
|||
// Smooth bending factor and increase its nearby height limit. |
|||
fBF += 1.0; |
|||
fBF *= fBF; |
|||
fBF = fBF * fBF - fBF; |
|||
// Displace position |
|||
float3 vNewPos = position; |
|||
vNewPos.xz += vWind.xy * fBF; |
|||
// Rescale |
|||
position = normalize(vNewPos.xyz) * fLength; |
|||
|
|||
////////Detail blending |
|||
float fSpeed = 0.25;//leaf occil |
|||
float fDetailFreq = 0.3;//detail leaf occil |
|||
float fEdgeAtten = leafStiffness;//leaf stiffness(red) |
|||
float fDetailAmp = 0.1;//leaf edge amplitude of movement |
|||
float fBranchAtten = 1 - branchStiffness;//branch stiffness(blue) |
|||
float fBranchAmp = 1.5;//branch amplitude of movement |
|||
float fBranchPhase = phaseOffset * 3.3;//leaf phase(green) |
|||
|
|||
// Phases (object, vertex, branch) |
|||
float fObjPhase = dot(origin, 1); |
|||
fBranchPhase += fObjPhase; |
|||
float fVtxPhase = dot(position, phaseOffset + fBranchPhase); |
|||
// x is used for edges; y is used for branches |
|||
float2 vWavesIn = _Time.y + float2(fVtxPhase, fBranchPhase ); |
|||
// 1.975, 0.793, 0.375, 0.193 are good frequencies |
|||
float4 vWaves = (frac( vWavesIn.xxyy * float4(1.975, 0.793, 0.375, 0.193) ) * 2.0 - 1.0 ) * fSpeed * fDetailFreq; |
|||
vWaves = SmoothTriangleWave( vWaves ); |
|||
float2 vWavesSum = vWaves.xz + vWaves.yw; |
|||
// Edge (xy) and branch bending (z) |
|||
return position + vWavesSum.xyx * float3(fEdgeAtten * fDetailAmp * normal.x, fBranchAtten * fBranchAmp, fEdgeAtten * fDetailAmp * normal.z); |
|||
} |
|||
////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|||
fileFormatVersion: 2 |
|||
guid: 372bb067f678c44e6ba03e6852450096 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue