Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active January 2, 2022 13:49
Show Gist options
  • Save cecilemuller/47d3cf126c4377df119a221abf1b8b64 to your computer and use it in GitHub Desktop.
Save cecilemuller/47d3cf126c4377df119a221abf1b8b64 to your computer and use it in GitHub Desktop.
Marmoset Toolbag 4: Albedo Transition
#include "../state.frag"
#include "../other/customExtras.sh"
#define MARGIN 0.05
#define RANGE 1.05
uniform float uStartTime; // name "Start time (in seconds)" min 0 max 60 default 0
uniform float uDurationTime; // name "Duration (in seconds)" min 0 max 60 default 10
USE_TEXTURE2D(tTransitionMap); // name "Transition"
USE_TEXTURE2D(tAlbedoMap2); // name "Albedo"
float getLerpFactor(in FragmentState s) {
float blendFraction = textureMaterial(tTransitionMap, s.vertexTexCoord).r;
float timeFraction = max(0, (uCustomAnimationTime - uStartTime)) / uDurationTime;
float minValue = (timeFraction * RANGE) - MARGIN;
return clamp((blendFraction - minValue) / MARGIN, 0.0, 1.0);
}
void CustomAlbedo(inout FragmentState s) {
vec4 color1 = textureMaterial(tAlbedoMap, s.vertexTexCoord);
color1 = uAlbedoMapGrayscale ? color1.rrra : color1;
color1.xyz *= uAlbedoMapColor;
vec4 color2 = textureMaterial(tAlbedoMap2, s.vertexTexCoord);
color2 = uAlbedoMapGrayscale ? color2.rrra : color2;
color2.xyz *= uAlbedoMapColor;
vec4 result = lerp(color2, color1, getLerpFactor(s));
s.albedo = result;
s.baseColor = result.xyz;
}
#ifdef Albedo
#undef Albedo
#endif
#define Albedo CustomAlbedo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment