143 lines
5.2 KiB
Plaintext
143 lines
5.2 KiB
Plaintext
Shader "Cielonos/MeshEffects/Weak"
|
|
{
|
|
Properties
|
|
{
|
|
[Header(Base Settings)]
|
|
[MainColor] _BaseColor("Base Color", Color) = (0.8, 0.8, 0.9, 0.1)
|
|
[MainTexture] _BaseMap("Pattern Texture (RGB)", 2D) = "white" {}
|
|
|
|
[Header(Pulsing and Flow)]
|
|
_PulseSpeed("Pulse Frequency", Range(0, 10)) = 2.0
|
|
_PulseMin("Pulse Min Alpha", Range(0, 1)) = 0.3
|
|
_PulseMax("Pulse Max Alpha", Range(0, 1)) = 0.8
|
|
_FlowSpeed("Pattern Scroll Speed (X, Y)", Vector) = (0, 0.2, 0, 0)
|
|
|
|
[Header(Fresnel Effect)]
|
|
[HDR] _FresnelColor("Fresnel Color (Rim)", Color) = (1, 1, 1, 1)
|
|
_FresnelPower("Fresnel Power", Range(0.1, 10)) = 3.0
|
|
_FresnelScale("Fresnel Strength", Range(0, 5)) = 1.5
|
|
|
|
[Header(Transparency)]
|
|
_AlphaScale("Alpha Scale", Range(0, 2)) = 1.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"Queue" = "Transparent"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
"IgnoreProjector" = "True"
|
|
}
|
|
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
ZWrite Off
|
|
Cull Back
|
|
|
|
Pass
|
|
{
|
|
Name "ForwardLit"
|
|
Tags { "LightMode" = "UniversalForward" }
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma prefer_hlslcc gles
|
|
#pragma exclude_renderers d3d11_9x
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float3 positionWS : TEXCOORD1;
|
|
float3 normalWS : TEXCOORD2;
|
|
float3 viewDirWS : TEXCOORD3;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _BaseColor;
|
|
float4 _BaseMap_ST;
|
|
float4 _FresnelColor;
|
|
float4 _FlowSpeed;
|
|
float _PulseSpeed;
|
|
float _PulseMin;
|
|
float _PulseMax;
|
|
float _FresnelPower;
|
|
float _FresnelScale;
|
|
float _AlphaScale;
|
|
CBUFFER_END
|
|
|
|
TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap);
|
|
|
|
Varyings vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
|
|
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
|
output.positionCS = vertexInput.positionCS;
|
|
output.positionWS = vertexInput.positionWS;
|
|
|
|
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS);
|
|
output.normalWS = normalInput.normalWS;
|
|
|
|
output.viewDirWS = GetWorldSpaceNormalizeViewDir(output.positionWS);
|
|
|
|
// Base UV
|
|
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
|
|
|
|
return output;
|
|
}
|
|
|
|
half4 frag(Varyings input) : SV_Target
|
|
{
|
|
float3 viewDirWS = SafeNormalize(input.viewDirWS);
|
|
float3 normalWS = SafeNormalize(input.normalWS);
|
|
|
|
// 1. Calculate Pulse (Breathing Effect)
|
|
// Use Sine wave to oscillate between Min and Max
|
|
float pulse = (sin(_Time.y * _PulseSpeed) * 0.5 + 0.5); // 0 to 1
|
|
float currentPulseAlpha = lerp(_PulseMin, _PulseMax, pulse);
|
|
|
|
// 2. Sample Pattern with Scrolling
|
|
float2 flowOffset = _Time.y * _FlowSpeed.xy;
|
|
float2 finalUV = input.uv + flowOffset;
|
|
half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, finalUV);
|
|
|
|
// 3. Fresnel Calculation (Rim Light)
|
|
float NdotV = saturate(dot(normalWS, viewDirWS));
|
|
float fresnelTerm = pow(1.0 - NdotV, _FresnelPower);
|
|
float3 fresnel = _FresnelColor.rgb * fresnelTerm * _FresnelScale;
|
|
|
|
// 4. Combine
|
|
// Base Color * Pattern, blended with Fresnel
|
|
// Ideally, Weakness effect is additive or semi-transparent overlay
|
|
float3 albedo = _BaseColor.rgb * texColor.rgb;
|
|
|
|
// Brighten the albedo based on pulse?
|
|
// Let's make the whole thing pulse.
|
|
float3 finalColor = (albedo + fresnel) * currentPulseAlpha;
|
|
|
|
// 5. Alpha Logic
|
|
// Base alpha * Texture Alpha + Fresnel Alpha
|
|
// We multiply by currentPulseAlpha to make the whole effect fade in and out slightly
|
|
float baseAlpha = (_BaseColor.a * texColor.a) + (fresnelTerm * _FresnelColor.a);
|
|
float finalAlpha = saturate(baseAlpha * currentPulseAlpha * _AlphaScale);
|
|
|
|
return half4(finalColor, finalAlpha);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|