On this page
Power
pow(x, y)raisesxto the power ofy.
This is useful for remapping gradients, shaping data like falloff masks, lighting ramps, or animation curves.
float result = pow(x, y);
float2 result = pow(float2(x1, x2), y);
float3 result = pow(float3(x, y, z), 2.0);
Visual demo¶
This shader visualizes the pow() function by remapping a horizontal UV gradient. The power exponent reshapes the curve: values below 1 bend it upward (fast rise), values above 1 bend it downward (slow rise), which is useful for biasing interpolation or nonlinear fading.
Node logic (engine-agnostic)¶
Try it live¶
The same power reshape, live: drag the exponent.
Shader "DecompiledArt/CommonFunctions/Power/Power"
{
Properties
{
_Tint01("Tint01", Color) = (1,1,1,1)
_Tint02("Tint02", Color) = (1,1,1,1)
_Power("Power", Range(0.01, 10)) = 1.0
[Toggle(SHOW_GRAPH)] _ShowGraph("showGraph", Int) = 0
_GraphLineWidth("Graph_LineWidth", Range(0.005, 0.025)) = 0.02
}
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#pragma shader_feature_local SHOW_GRAPH
struct Attributes
{
float4 positionOS : POSITION;
half2 uvs: TEXCOORD0;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
half2 uvs: TEXCOORD0;
};
CBUFFER_START(UnityPerMaterial)
half3 _Tint01;
half3 _Tint02;
half _Power;
half _GraphLineWidth;
CBUFFER_END
Varyings vert (Attributes IN)
{
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uvs = IN.uvs;
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
half value_for_viz = pow(abs(IN.uvs.x), _Power);
half3 col_output = lerp(_Tint01, _Tint02, value_for_viz);
#ifdef SHOW_GRAPH
half graph_line = saturate(1 - smoothstep(0.0, _GraphLineWidth, abs(IN.uvs.y - value_for_viz)));
col_output += graph_line;
#endif
return half4(col_output, 1.0);
}
ENDHLSL
}
}
}
🔗 Related Functions¶
Abs • Step • Remap • Smoothstep
❤️ Support Shader Story¶
If this article helped you, consider supporting the project on Patreon: you’ll get access to the related source files and reference cheat-sheets.
Your support helps keep this library open and free for everyone.