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.

Revisions

  1. cecilemuller revised this gist Jun 3, 2024. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion triplanar.frag
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ 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));

    @@ -14,10 +15,14 @@ void TriplanarEmissive( inout FragmentState s )
    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
    #define Emissive TriplanarEmissive
  2. cecilemuller created this gist Jun 3, 2024.
    23 changes: 23 additions & 0 deletions triplanar.frag
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #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;

    s.emissiveLight = color0.xyz;
    }

    #ifdef Emissive
    #undef Emissive
    #endif
    #define Emissive TriplanarEmissive