浏览代码

Merge branch 'LW-StandardParticlesUpgrade'

/main
Felipe Lira 7 年前
当前提交
39035ffa
共有 5 个文件被更改,包括 95 次插入29 次删除
  1. 5
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardParticlesShaderGUI.cs
  2. 10
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightShaderLibrary/Core.hlsl
  3. 31
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightShaderLibrary/Particles.hlsl
  4. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader
  5. 71
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader

5
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardParticlesShaderGUI.cs


EditorGUILayout.Space();
GUILayout.Label(Styles.advancedOptionsText, EditorStyles.boldLabel);
m_MaterialEditor.RenderQueueField();
EditorGUILayout.Space();
GUILayout.Label(Styles.requiredVertexStreamsText, EditorStyles.boldLabel);
DoVertexStreamsArea(material);
}

10
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightShaderLibrary/Core.hlsl


#endif
}
void ApplyFog(inout half3 color, half fogFactor)
void ApplyFogColor(inout half3 color, half3 fogColor, half fogFactor)
color = lerp(unity_FogColor.rgb, color, fogFactor);
color = lerp(fogColor, color, fogFactor);
void ApplyFog(inout half3 color, half fogFactor)
{
ApplyFogColor(color, unity_FogColor.rgb, fogFactor);
}
#endif

31
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightShaderLibrary/Particles.hlsl


#include "InputSurface.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
float4 _SoftParticleFadeParams;
float4 _CameraFadeParams;
#define SOFT_PARTICLE_NEAR_FADE _SoftParticleFadeParams.x
#define SOFT_PARTICLE_INV_FADE_DISTANCE _SoftParticleFadeParams.y
#define CAMERA_NEAR_FADE _CameraFadeParams.x
#define CAMERA_INV_FADE_DISTANCE _CameraFadeParams.y
#if defined (_COLORADDSUBDIFF_ON)
half4 _ColorAddSubDiff;
#endif

// Fading vertex function
#if defined(SOFTPARTICLES_ON) || defined(_FADING_ON)
#define vertFading(o) \
o.projectedPosition = ComputeScreenPos (clipPosition); \
COMPUTE_EYEDEPTH(o.projectedPosition.z);
#define vertFading(o, positionWS, positionCS) \
o.projectedPosition.xy = positionCS.xy * 0.5 + positionCS.w; \
o.projectedPosition.y *= _ProjectionParams.x; \
o.projectedPosition.w = positionCS.w; \
o.projectedPosition.z = -TransformWorldToView(positionWS.xyz).z
#define vertFading(o)
#define vertFading(o, positionWS, positionCS)
#define fragColorMode(albedo, color) \
#define fragColorMode(i) \
half3 aHSL = RGBtoHSV(albedo.rgb); \
half3 bHSL = RGBtoHSV(i.color.rgb); \
half3 aHSL = RgbToHsv(albedo.rgb); \
half3 bHSL = RgbToHsv(i.color.rgb); \
albedo = half4(HSVtoRGB(rHSL), albedo.a * i.color.a);
albedo = half4(HsvToRgb(rHSL), albedo.a * i.color.a);
#elif defined(_COLORADDSUBDIFF_ON)
#define fragColorMode(i) \
albedo.rgb = albedo.rgb + i.color.rgb * _ColorAddSubDiff.x; \

#define fragSoftParticles(i) \
if (SOFT_PARTICLE_NEAR_FADE > 0.0 || SOFT_PARTICLE_INV_FADE_DISTANCE > 0.0) \
{ \
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projectedPosition))); \
float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.projectedPosition.xy / i.projectedPosition.w), _ZBufferParams); \
float fade = saturate (SOFT_PARTICLE_INV_FADE_DISTANCE * ((sceneZ - SOFT_PARTICLE_NEAR_FADE) - i.projectedPosition.z)); \
ALBEDO_MUL *= fade; \
}

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader


VertexOutputLit ParticlesLitVertex(appdata_particles v)
{
VertexOutputLit o;
float4 clipPosition = TransformObjectToHClip(v.vertex.xyz);
#if _NORMALMAP
OutputTangentToWorld(v.tangent, v.normal, o.tangent, o.binormal, o.normal);
#else

o.posWS.xyz = TransformObjectToWorld(v.vertex.xyz).xyz;
o.clipPos = TransformWorldToHClip(o.posWS.xyz);
o.clipPos = TransformWorldToHClip(o.posWS.xyz);
vertFading(o);
o.clipPos = clipPosition;
vertFading(o, o.posWS, o.clipPos);
return o;
}

71
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader


_EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
_DistortionStrength("Strength", Float) = 1.0
_DistortionBlend("Blend", Range(0.0, 1.0)) = 0.5
_SoftParticlesNearFadeDistance("Soft Particles Near Fade", Float) = 0.0
_SoftParticlesFarFadeDistance("Soft Particles Far Fade", Float) = 1.0
_CameraNearFadeDistance("Camera Near Fade", Float) = 1.0

[HideInInspector] _ColorMode("__colormode", Float) = 0.0
[HideInInspector] _FlipbookMode("__flipbookmode", Float) = 0.0
[HideInInspector] _LightingEnabled("__lightingenabled", Float) = 0.0
[HideInInspector] _DistortionEnabled("__distortionenabled", Float) = 0.0
[HideInInspector] _EmissionEnabled("__emissionenabled", Float) = 0.0
[HideInInspector] _BlendOp("__blendop", Float) = 0.0
[HideInInspector] _SrcBlend("__src", Float) = 1.0

[HideInInspector] _SoftParticleFadeParams("__softparticlefadeparams", Vector) = (0,0,0,0)
[HideInInspector] _CameraFadeParams("__camerafadeparams", Vector) = (0,0,0,0)
[HideInInspector] _ColorAddSubDiff("__coloraddsubdiff", Vector) = (0,0,0,0)
[HideInInspector] _DistortionStrengthScaled("__distortionstrengthscaled", Float) = 0.0
}
Category

Pass
{
CGPROGRAM
HLSLPROGRAM
#pragma multi_compile __ SOFTPARTICLES_ON
#pragma multi_compile_fog
#pragma target 2.5

#pragma vertex vertParticleUnlit
#pragma fragment fragParticleUnlit
#include "UnityStandardParticles.cginc"
ENDCG
#include "LightweightShaderLibrary/Particles.hlsl"
#include "LightweightShaderLibrary/Core.hlsl"
VertexOutputLit vertParticleUnlit(appdata_particles v)
{
VertexOutputLit o = (VertexOutputLit)0;
// position ws is used to compute eye depth in vertFading
o.posWS.xyz = TransformObjectToWorld(v.vertex.xyz);
o.posWS.w = ComputeFogFactor(o.clipPos.z);
o.clipPos = TransformWorldToHClip(o.posWS.xyz);
o.color = v.color;
vertColor(o.color);
vertTexcoord(v, o);
vertFading(o, o.posWS, o.clipPos);
return o;
}
half4 fragParticleUnlit(VertexOutputLit IN) : SV_Target
{
half4 albedo = readTexture(_MainTex, sampler_MainTex, IN);
albedo *= _Color;
fragColorMode(IN);
fragSoftParticles(IN);
fragCameraFading(IN);
#if defined(_NORMALMAP)
float3 normal = normalize(UnpackNormalScale(readTexture(_BumpMap, sampler_BumpMap, IN), _BumpScale));
#else
float3 normal = float3(0,0,1);
#endif
#if defined(_EMISSION)
half3 emission = readTexture(_EmissionMap, sampler_EmissionMap, IN).rgb;
#else
half3 emission = 0;
#endif
half4 result = albedo;
#if defined(_ALPHAMODULATE_ON)
result.rgb = lerp(half3(1.0, 1.0, 1.0), albedo.rgb, albedo.a);
#endif
result.rgb += emission * _EmissionColor.rgb;
#if !defined(_ALPHABLEND_ON) && !defined(_ALPHAPREMULTIPLY_ON) && !defined(_ALPHAOVERLAY_ON)
result.a = 1;
#endif
#if defined(_ALPHATEST_ON)
clip(albedo.a - _Cutoff + 0.0001);
#endif
half fogFactor = IN.posWS.w;
ApplyFogColor(result.rgb, half3(0, 0, 0), fogFactor);
return result;
}
ENDHLSL
}
}
}

正在加载...
取消
保存