71 lines
1.9 KiB
Plaintext
71 lines
1.9 KiB
Plaintext
// Crest Water System
|
|
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
|
|
|
// Adds flow from a provided texture. Used by Painted and Texture input modes.
|
|
|
|
#pragma kernel CrestExecute
|
|
|
|
#include "HLSLSupport.cginc"
|
|
|
|
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
|
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
|
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
|
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
|
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
|
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
|
|
|
Texture2D _Crest_Texture;
|
|
RWTexture2DArray<float2> _Crest_Target;
|
|
|
|
CBUFFER_START(CrestPerMaterial)
|
|
int _Crest_Blend;
|
|
float _Crest_Weight;
|
|
float2 _Crest_Multiplier;
|
|
float2 _Crest_TextureSize;
|
|
float2 _Crest_TexturePosition;
|
|
float2 _Crest_TextureRotation;
|
|
float _Crest_FeatherWidth;
|
|
bool _Crest_NegativeValues;
|
|
CBUFFER_END
|
|
|
|
m_CrestNameSpace
|
|
|
|
void Execute(uint3 id)
|
|
{
|
|
const Cascade cascade = Cascade::MakeFlow(id.z);
|
|
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
|
|
|
half weight = _Crest_Weight;
|
|
|
|
// Feather boundaries.
|
|
weight *= FeatherWeightFromUV(uv, _Crest_FeatherWidth);
|
|
|
|
// Check we are within bounds.
|
|
if (weight <= 0.0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
float2 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).xy;
|
|
|
|
if (!_Crest_NegativeValues)
|
|
{
|
|
// From 0..1 to -1..1.
|
|
source = source * 2.0 - 1.0;
|
|
}
|
|
|
|
source *= _Crest_Multiplier;
|
|
|
|
if (_Crest_Blend == m_CrestBlendAlpha)
|
|
{
|
|
weight *= saturate(length(source));
|
|
}
|
|
|
|
const float2 target = _Crest_Target[id];
|
|
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source, target);
|
|
}
|
|
|
|
m_CrestNameSpaceEnd
|
|
|
|
m_CrestInputKernelDefault(Execute)
|