Skip to content

Instantly share code, notes, and snippets.

@lcrs
Created January 8, 2014 22:29
Show Gist options
  • Save lcrs/8325671 to your computer and use it in GitHub Desktop.
Save lcrs/8325671 to your computer and use it in GitHub Desktop.
folding noise matchbox shader with loop duration control
uniform float adsk_time;
uniform float adsk_result_w, adsk_result_h;
uniform float pRight;
uniform float pLeft;
uniform float Offset;
uniform float Speed;
uniform float Zoom;
uniform float Detail;
uniform float Steps;
uniform float Aspect;
uniform vec3 Color;
uniform bool useduration;
uniform int duration;
vec2 resolution = vec2(adsk_result_w, adsk_result_h);
void main( void ) {
float time;
if(useduration) {
// The only time-dependent function below is sin(time), which
// repeats every 2*pi
time = 2.0 * 3.14159265358979 * (adsk_time/float(duration));
time += Offset/float(duration);
} else {
time = adsk_time*.01*Speed+Offset;
}
vec2 position = ( gl_FragCoord.xy / resolution.xy ) * 1.0*Zoom;
position.x *= resolution.x / resolution.y*Aspect;
float color = 0.0;
for(float i = 0.0; i < Steps; i++)
{
position.x += sin(Detail * sin(length(position.y)));
color += sin(0.6 * sin(length(position) + position.x + i * position.y*0.5 + sin(i + position.x + time )) + sin(Detail * cos(sin(position.y * 2. + position.x) * 0.5)));
color = sin(color*1.5);
position.y += color*1.5;
position.x -= sin(position.y - cos(dot(position, vec2(color, sin(color*2.)))));
}
color = abs(color);
color *= 0.8;
gl_FragColor = vec4(pow(vec3(1.0 - color), vec3(1.-Color.r, 1.-Color.g, 1.-Color.b)), color );
}
<ShaderNodePreset SupportsAdaptiveDegradation="0" Description="
This Matchbox shader creates a folding texture, which you can use as a reflection map.
Setup:
-Speed : speed of the texture changes
-Offset : offset the texture pattern
-Zoom : zoom in/out of the texture
-Detail : level of detail
-Steps : texture generations steps
-Aspect : aspect ratio of the generated texture
Demo clip: http://vimeo.com/83624633
[email protected]" Name="crok folding">
<Shader OutputBitDepth="Output" Index="1">
<Uniform Inc="0.01" Tooltip="" Row="0" Col="2" Page="0" DisplayName="Color" ValueType="Colour" Type="vec3" Name="Color">
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.0">
</SubUniform>
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.1">
</SubUniform>
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.16">
</SubUniform>
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="5.0" Inc="0.01" Tooltip="" Row="0" Col="0" Page="0" DisplayName="Speed" Type="float" Name="Speed">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.0" Inc="0.01" Tooltip="" Row="1" Col="0" Page="0" DisplayName="Offset" Type="float" Name="Offset">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="2.0" Inc="0.01" Tooltip="" Row="2" Col="0" Page="0" DisplayName="Zoom" Type="float" Name="Zoom">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="4.0" Inc="0.01" Tooltip="" Row="3" Col="0" Page="0" DisplayName="Detail" Type="float" Name="Detail">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="3.0" Inc="1.0" Tooltip="" Row="4" Col="0" Page="0" DisplayName="Steps" Type="float" Name="Steps">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="1.0" Inc="0.01" Tooltip="" Row="0" Col="1" Page="0" DisplayName="Aspect" Type="float" Name="Aspect">
</Uniform>
<Uniform Row="0" Col="3" Page="0" Default="False" Tooltip="" DisplayName="Choose speed to create loop" Type="bool" Name="useduration">
</Uniform>
<Uniform ResDependent="None" Max="1000000" Min="1" Default="100" Inc="1" Tooltip="" Row="1" Col="3" Page="0" DisplayName="Duration" Type="int" Name="duration">
</Uniform>
</Shader>
<Page Name="Folding" Page="0">
<Col Name="Texture" Col="0" Page="0">
</Col>
<Col Name="Colour" Col="2" Page="0">
</Col>
<Col Name="Loop" Col="3" Page="0">
</Col>
</Page>
</ShaderNodePreset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment