85 lines
2.5 KiB
Plaintext
85 lines
2.5 KiB
Plaintext
Shader "Unlit/BrushPainter"
|
|
{
|
|
Properties
|
|
{
|
|
_DrawPosition("Draw Position", Vector) = (0.5, 0.5, 0, 0)
|
|
_DrawRadius("Draw Radius", Float) = 0.05
|
|
_DrawAngleX("Draw Angle (Rad) X", Float) = 0.0
|
|
_DrawAngleY("Draw Angle (Rad) Y", Float) = 0.0
|
|
_ToolDirtiness("Tool Dirtiness", Range(0, 1)) = 0
|
|
[MainTexture] _BrushTex("Brush Texture", 2D) = "white" {}
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"Queue" = "Transparent"
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
ZWrite Off
|
|
ZTest Always
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionHCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
float4 _DrawPosition;
|
|
float _DrawRadius;
|
|
float _DrawAngleX;
|
|
float _DrawAngleY;
|
|
float _ToolDirtiness;
|
|
|
|
TEXTURE2D(_BrushTex);
|
|
SAMPLER(sampler_BrushTex);
|
|
|
|
Varyings vert(Attributes IN)
|
|
{
|
|
Varyings OUT;
|
|
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
|
|
OUT.uv = IN.uv;
|
|
return OUT;
|
|
}
|
|
|
|
half4 frag(Varyings IN) : SV_Target
|
|
{
|
|
float2 centeredUV = (IN.uv - _DrawPosition.xy) / (_DrawRadius * 2.0);
|
|
|
|
float2 rotatedUV;
|
|
rotatedUV.x = centeredUV.x * _DrawAngleX - centeredUV.y * _DrawAngleY;
|
|
rotatedUV.y = centeredUV.x * _DrawAngleY + centeredUV.y * _DrawAngleX;
|
|
|
|
float2 brushUV = rotatedUV + 0.5;
|
|
|
|
float inBounds = step(0.0, brushUV.x) * step(brushUV.x, 1.0) *
|
|
step(0.0, brushUV.y) * step(brushUV.y, 1.0);
|
|
|
|
half4 brushColor = SAMPLE_TEXTURE2D(_BrushTex, sampler_BrushTex, brushUV);
|
|
|
|
float brushMask = brushColor.a * inBounds;
|
|
float fillValue = _ToolDirtiness * brushMask;
|
|
|
|
return half4(fillValue, fillValue, fillValue, brushMask);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
} |