Skip to content

Commit

Permalink
add gradient map module
Browse files Browse the repository at this point in the history
  • Loading branch information
lackofbindings committed Jul 23, 2024
1 parent 5b18300 commit d42d7c0
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 4 deletions.
93 changes: 93 additions & 0 deletions Assets/Examples/ExampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,99 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &182411961
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 182411965}
- component: {fileID: 182411964}
- component: {fileID: 182411963}
- component: {fileID: 182411962}
m_Layer: 0
m_Name: ORL Standard GradientMap
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!135 &182411962
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 182411961}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &182411963
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 182411961}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 7266852b7b67dc3498823563fcf1076f, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &182411964
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 182411961}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &182411965
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 182411961}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 3.707}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &195397332
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
%Properties()
{
UI_GradientMapHeader("# Gradient Map (Grab Pass)", Float) = 0
_GradientMap ("Gradient (RGB) %Gradient()", 2D) = "white" {}
_DistortMagnitude("Distortion Magnitude", Range(0,1)) = 0.05
_DistortThreshold("Distortion Threshold", Range(0,1)) = 0.01
}

%ShaderDefines()
{
#define EXTRA_V2F_0
}

%PrePasses()
{
GrabPass { "_GrabTexture1" }

Pass
{
ZWrite On Lighting Off Cull Off Fog{ Mode Off } Blend One Zero
LOD 200
}
}

%Variables()
{
half _DistortThreshold;
half _DistortMagnitude;
}

%Textures()
{
TEXTURE2D(_GradientMap);
SAMPLER(sampler_GradientMap);
SAMPLER(_GrabTexture1);
}

%Vertex("GrabPassVertex")
{
void GrabPassVertex(VertexData v, inout FragmentData o)
{
half4 vertex = UnityObjectToClipPos(v.vertex);
o.extraV2F0 = ComputeGrabScreenPos(vertex); // GrabPass UV
}
}

%Fragment("GrabPassFragment")
{
float linearToGamma(fixed4 c)
{
return pow(sqrt(c.rgb) + 0.25, 2.0);
}

void GrabPassFragment(FragmentData i, inout SurfaceData o)
{
// Distortion: offset the UV data of the grab texture based on the normal map
i.extraV2F0.xy += (saturate(o.Normal.rg - _DistortThreshold)) * _DistortMagnitude;

// Sample grab texture and map Luminance to value on input gradient
fixed4 color_GrabTex = tex2Dproj(_GrabTexture1, UNITY_PROJ_COORD(i.extraV2F0)); // apply the screen texture in the correct position
float2 gradientUV = float2(linearToGamma(Luminance(color_GrabTex.rgb)), 0.0); // convert luminance to UV X coordinate on gradient
fixed4 color_Result = SAMPLE_TEXTURE2D(_GradientMap, sampler_GradientMap, gradientUV);
o.Albedo *= sqrt(color_Result.rgb); //sqrt makes sRGB gradient textures have the right color values.
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%ShaderName("orels1/Standard Gradient Map")
%CustomEditor("ORL.ShaderInspector.InspectorGUI")

%Includes()
{
"@/Shaders/ORL Standard",
"/Packages/com.lackofbindings.orlmodules/Runtime/Modules/GrabGradientMap",
"self"
}

%ShaderTags()
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Opaque"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This VPM provides custom modules for the [ORL shader suite](https://shaders.orel

## Included Modules:

#### Stencil Options
### Stencil Options

This Module provides the standard stencil masking options (stencil mask value, pass/fail/comparison, etc.)

#### AudioLink Pathing
### AudioLink Pathing

This module ports the AudioLink code from [Silent's Cell Shading Shader](https://gitlab.com/s-ilent/SCSS) to ORL Standard. This provides Furality/Poiyomi-Pathing style AudioLink.

Expand All @@ -17,12 +17,16 @@ This module ports the AudioLink code from [Silent's Cell Shading Shader](https:/
2. Furality-style with a separate channel (AL band) map and sweep (direction) map.
3. A simplified Furality-style mode that loses the 4th AL band in favor of packing in the sweep (direction) map into the alpha channel, thus only requiring one texture.

This module also features a toggle to flip the direction of the sweep, since some shaders (Poiyomi, Furality, SCSS) interpret the sweep map differently.
This module also features a toggle to flip the direction of the sweep, since some shaders (Poiyomi) interpret the sweep map differently.

#### 2nd Emission
### 2nd Emission

This module adds a secondary emission texture slot. It provides its own tint color, UV channel, and RGB channel options. It shares the same tiling, offsets, sampler, and keyword with the base emission slot.

### Gradient Map (Grab Pass)

This module multiplies the albedo by a grab pass, where the grab pass has been mapped to a color gradient based on its luminance value (think "Color Ramp" in Blender or "Gradient Map" in Photoshop). This is mostly a novelty, but could be used to make a glass surface that stylizes other objects viewed through it.

## How to Install

### Dependencies
Expand Down Expand Up @@ -51,6 +55,7 @@ Ready-to-use variants of ORL Standard can be found when making a new material:
- `orels1/Standard Stencil`
- `orels1/Standard Audiolink Pathing`
- `orels1/Standard 2nd Emission`
- `orels1/Standard Gradient Map`

#### As a module

Expand Down

0 comments on commit d42d7c0

Please sign in to comment.