Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active June 3, 2024 23:44
Show Gist options
  • Save cecilemuller/8e8b093b1a85f2bcdbc361622e420b9f to your computer and use it in GitHub Desktop.
Save cecilemuller/8e8b093b1a85f2bcdbc361622e420b9f to your computer and use it in GitHub Desktop.
Triplanar Mapping shader for Marmoset Toolbag 4
#include "data/shader/mat/state.frag"
uniform float uScale; //name "Scale" default 1.0 min 0.0 max 5.0
USE_TEXTURE2D(tTexture0);
void TriplanarEmissive( inout FragmentState s )
{
vec3 uvw = fract(s.vertexPosition / 100.0 * uScale);
vec3 blend = abs(s.normal);
blend /= dot(blend, vec3(1.0, 1.0, 1.0));
vec4 cx0 = texture2D(tTexture0, uvw.yz);
vec4 cy0 = texture2D(tTexture0, uvw.xz);
vec4 cz0 = texture2D(tTexture0, uvw.xy);
float4 color0 = cx0 * blend.x + cy0 * blend.y + cz0 * blend.z;
// Display the UV coordinates
//s.emissiveLight = uvw;
// Display the texture
s.emissiveLight = color0.xyz;
}
#ifdef Emissive
#undef Emissive
#endif
#define Emissive TriplanarEmissive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment