Skip to content

Conversation

@Kwarf
Copy link
Contributor

@Kwarf Kwarf commented Jan 21, 2023

Hi,

I want to use this project from Rust, so I went ahead and added output support for it.

I decided to generate a byte string literal ([u8]) with an added \0 at the end instead of the usual Rust str because that makes it easier to pass on to the OpenGL functions, since str is unicode and not null-terminated either.

heart.frag generates the following output:

// Generated with Shader Minifier 1.3.2 (https://github.com/laurentlb/Shader_Minifier/)
pub const VAR_MOUSE: &'static [u8] = b"f\0";
pub const VAR_RESOLUTION: &'static [u8] = b"y\0";
pub const VAR_TIME: &'static [u8] = b"v\0";

pub const HEART_FRAG: &'static [u8] = b"\
 uniform float v;\
 uniform vec2 y;\
 uniform vec4 f;\
 void main()\
 {\
   vec2 f=(2.*gl_FragCoord.xy-y)/y.y;\
   float r=mod(v,2.)/2.,a=pow(r,.2)*.5+.5;\
   a-=a*.2*sin(r*6.2831*5.)*exp(-r*6.);\
   f*=vec2(.5,1.5)+a*vec2(.5,-.5);\
   float m=atan(f.x,f.y)/3.141593,x=length(f),e=abs(m),o=(13.*e-22.*e*e+10.*e*e*e)/(6.-5.*e),n=step(x,o)*pow(1.-x/o,.25);\
   gl_FragColor=vec4(n,0,0,1);\
 }\0";

Leading whitespaces are ignored, so no special handling of the indentation is required, as can be seen here on the Rust Playground.

Copy link
Owner

@laurentlb laurentlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot!

@laurentlb laurentlb enabled auto-merge (squash) January 21, 2023 15:27
@laurentlb laurentlb merged commit c479bc4 into laurentlb:master Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants