Get multiline working again and use it in cel-shading

db4
Joe Groff 2008-01-13 19:06:16 -08:00
parent dc2109e6cb
commit 53effc35a6
3 changed files with 44 additions and 43 deletions

View File

@ -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;" gl_Position = ftransform();
"uniform vec3 light_direction;"
"uniform vec4 color;" position = gl_Vertex.xyz;
"uniform vec4 ambient, diffuse;" 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;
"" uniform vec3 light_direction;
"float" uniform vec4 color;
"modulate(vec3 direction, vec3 normal)" uniform vec4 ambient, diffuse;
"{"
"float m = smooth_modulate(direction, normal);" float
"return smoothstep(0.0, 0.01, m) * 0.4 + smoothstep(0.49, 0.5, m) * 0.5;" smooth_modulate(vec3 direction, vec3 normal)
"}" {
"" return clamp(dot(direction, normal), 0.0, 1.0);
"void" }
"main()"
"{" float
"vec3 direction = normalize(light_direction - position);" modulate(vec3 direction, vec3 normal)
"gl_FragColor = ambient + diffuse * color * vec4(vec3(modulate(direction, normal)), 1); " {
"}" float m = smooth_modulate(direction, normal);
} "\n" join ; 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

View File

@ -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;" }

View File

@ -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