103 lines
4.1 KiB
Plaintext
103 lines
4.1 KiB
Plaintext
Shader "Kaiju/Bubbles"
|
|
{
|
|
HLSLINCLUDE
|
|
|
|
#pragma vertex Vert
|
|
|
|
#pragma target 4.5
|
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"
|
|
|
|
// The PositionInputs struct allow you to retrieve a lot of useful information for your fullScreenShader:
|
|
// struct PositionInputs
|
|
// {
|
|
// float3 positionWS; // World space position (could be camera-relative)
|
|
// float2 positionNDC; // Normalized screen coordinates within the viewport : [0, 1) (with the half-pixel offset)
|
|
// uint2 positionSS; // Screen space pixel coordinates : [0, NumPixels)
|
|
// uint2 tileCoord; // Screen tile coordinates : [0, NumTiles)
|
|
// float deviceDepth; // Depth from the depth buffer : [0, 1] (typically reversed)
|
|
// float linearDepth; // View space Z coordinate : [Near, Far]
|
|
// };
|
|
|
|
// To sample custom buffers, you have access to these functions:
|
|
// But be careful, on most platforms you can't sample to the bound color buffer. It means that you
|
|
// can't use the SampleCustomColor when the pass color buffer is set to custom (and same for camera the buffer).
|
|
// float4 SampleCustomColor(float2 uv);
|
|
// float4 LoadCustomColor(uint2 pixelCoords);
|
|
// float LoadCustomDepth(uint2 pixelCoords);
|
|
// float SampleCustomDepth(float2 uv);
|
|
|
|
// There are also a lot of utility function you can use inside Common.hlsl and Color.hlsl,
|
|
// you can check them out in the source code of the core SRP package.
|
|
|
|
float4 FullScreenPass(Varyings varyings) : SV_Target
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);
|
|
float depth = LoadCameraDepth(varyings.positionCS.xy);
|
|
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
|
|
float3 viewDirection = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
|
|
float4 color = float4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
// Load the camera color buffer at the mip 0 if we're not at the before rendering injection point
|
|
if (_CustomPassInjectionPoint != CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING)
|
|
color = float4(CustomPassLoadCameraColor(varyings.positionCS.xy, 0), 1);
|
|
|
|
|
|
// get uv
|
|
float2 uv = posInput.positionNDC;
|
|
// fix aspect ratio
|
|
uv.x *= _ScreenParams.x / _ScreenParams.y;
|
|
|
|
// Background
|
|
float4 outColour = float4(0.8+0.2*uv.y,0.8+0.2*uv.y,0.8+0.2*uv.y,1);
|
|
|
|
// [unroll(100)]
|
|
for( int i=0; i<40; i++ ) {
|
|
// bubble seeds
|
|
float pha = sin(float(i)*546.13+1.0)*0.5 + 0.5;
|
|
float siz = pow( sin(float(i)*651.74+5.0)*0.5 + 0.5, 4.0 );
|
|
float pox = sin(float(i)*321.55+4.1) * 1 / 1;
|
|
|
|
// buble size, position and color
|
|
float rad = 0.1 + 0.5*siz;
|
|
float2 pos = float2( pox, -1.0-rad + (2.0+2.0*rad)*fmod(pha+0.1*_Time.y*(0.2+0.8*siz),1.0));
|
|
float dis = length( uv - pos );
|
|
float3 col = lerp( float3(0.94,0.3,0.0), float3(0.1,0.4,0.8), 0.5+0.5*sin(float(i)*1.2+1.9));
|
|
col+= 8.0*smoothstep( rad*0.95, rad, dis );
|
|
|
|
// render
|
|
float f = length(uv-pos)/rad;
|
|
f = sqrt(clamp(1.0-f*f,0.0,1.0));
|
|
outColour -= float4(col.zyx *(1.0-smoothstep( rad*0.95, rad, dis )) * f, 0.0);
|
|
}
|
|
|
|
// Vignetting
|
|
outColour *= sqrt(1.5-0.5*length(uv));
|
|
|
|
return outColour;
|
|
|
|
}
|
|
|
|
ENDHLSL
|
|
|
|
SubShader
|
|
{
|
|
Tags{ "RenderPipeline" = "HDRenderPipeline" }
|
|
Pass
|
|
{
|
|
Name "Custom Pass 0"
|
|
|
|
ZWrite Off
|
|
ZTest Always
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
Cull Off
|
|
|
|
HLSLPROGRAM
|
|
#pragma fragment FullScreenPass
|
|
ENDHLSL
|
|
}
|
|
}
|
|
Fallback Off
|
|
}
|