Get multiline working again and use it in cel-shading
parent
dc2109e6cb
commit
53effc35a6
|
@ -1,5 +1,5 @@
|
||||||
USING: arrays bunny io io.files kernel
|
USING: arrays bunny io io.files kernel
|
||||||
math math.functions math.vectors
|
math math.functions math.vectors multiline
|
||||||
namespaces
|
namespaces
|
||||||
opengl opengl.gl
|
opengl opengl.gl
|
||||||
prettyprint
|
prettyprint
|
||||||
|
@ -47,47 +47,47 @@ M: cel-shading-gadget pref-dim* ( gadget -- dim )
|
||||||
FOV-RATIO NEAR-PLANE FOV / v*n
|
FOV-RATIO NEAR-PLANE FOV / v*n
|
||||||
first2 [ -+ ] 2apply NEAR-PLANE FAR-PLANE ;
|
first2 [ -+ ] 2apply NEAR-PLANE FAR-PLANE ;
|
||||||
|
|
||||||
: cel-shading-vertex-shader-source
|
STRING: cel-shading-vertex-shader-source
|
||||||
{
|
varying vec3 position, normal;
|
||||||
"varying vec3 position, normal;"
|
|
||||||
""
|
|
||||||
"void"
|
|
||||||
"main()"
|
|
||||||
"{"
|
|
||||||
"gl_Position = ftransform();"
|
|
||||||
""
|
|
||||||
"position = gl_Vertex.xyz;"
|
|
||||||
"normal = gl_Normal;"
|
|
||||||
"}"
|
|
||||||
} "\n" join ;
|
|
||||||
|
|
||||||
: cel-shading-fragment-shader-source
|
void
|
||||||
{
|
main()
|
||||||
"varying vec3 position, normal;"
|
{
|
||||||
"uniform vec3 light_direction;"
|
gl_Position = ftransform();
|
||||||
"uniform vec4 color;"
|
|
||||||
"uniform vec4 ambient, diffuse;"
|
position = gl_Vertex.xyz;
|
||||||
""
|
normal = gl_Normal;
|
||||||
"float"
|
}
|
||||||
"smooth_modulate(vec3 direction, vec3 normal)"
|
|
||||||
"{"
|
;
|
||||||
"return clamp(dot(direction, normal), 0.0, 1.0);"
|
|
||||||
"}"
|
STRING: cel-shading-fragment-shader-source
|
||||||
""
|
varying vec3 position, normal;
|
||||||
"float"
|
uniform vec3 light_direction;
|
||||||
"modulate(vec3 direction, vec3 normal)"
|
uniform vec4 color;
|
||||||
"{"
|
uniform vec4 ambient, diffuse;
|
||||||
"float m = smooth_modulate(direction, normal);"
|
|
||||||
"return smoothstep(0.0, 0.01, m) * 0.4 + smoothstep(0.49, 0.5, m) * 0.5;"
|
float
|
||||||
"}"
|
smooth_modulate(vec3 direction, vec3 normal)
|
||||||
""
|
{
|
||||||
"void"
|
return clamp(dot(direction, normal), 0.0, 1.0);
|
||||||
"main()"
|
}
|
||||||
"{"
|
|
||||||
"vec3 direction = normalize(light_direction - position);"
|
float
|
||||||
"gl_FragColor = ambient + diffuse * color * vec4(vec3(modulate(direction, normal)), 1); "
|
modulate(vec3 direction, vec3 normal)
|
||||||
"}"
|
{
|
||||||
} "\n" join ;
|
float m = smooth_modulate(direction, normal);
|
||||||
|
return smoothstep(0.0, 0.01, m) * 0.4 + smoothstep(0.49, 0.5, m) * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
vec3 direction = normalize(light_direction - position);
|
||||||
|
gl_FragColor = ambient + diffuse * color * vec4(vec3(modulate(direction, normal)), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
: cel-shading-program ( -- program )
|
: cel-shading-program ( -- program )
|
||||||
cel-shading-vertex-shader-source <vertex-shader> check-gl-shader
|
cel-shading-vertex-shader-source <vertex-shader> check-gl-shader
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
USING: help.markup help.syntax multiline ;
|
USING: help.markup help.syntax ;
|
||||||
|
IN: multiline
|
||||||
|
|
||||||
HELP: STRING:
|
HELP: STRING:
|
||||||
{ $syntax "STRING: name\nfoo\n;" }
|
{ $syntax "STRING: name\nfoo\n;" }
|
||||||
|
|
|
@ -16,7 +16,7 @@ IN: multiline
|
||||||
|
|
||||||
: STRING:
|
: STRING:
|
||||||
CREATE dup reset-generic
|
CREATE dup reset-generic
|
||||||
parse-here 1quotation define-compound ; parsing
|
[ parse-here 1quotation define ] keep make-inline ; parsing
|
||||||
|
|
||||||
: (parse-multiline-string) ( start-index end-text -- end-index )
|
: (parse-multiline-string) ( start-index end-text -- end-index )
|
||||||
lexer get line-text 2dup start
|
lexer get line-text 2dup start
|
||||||
|
|
Loading…
Reference in New Issue