Commit 14038f39 authored by Eldritch Conundrum's avatar Eldritch Conundrum
Browse files

misc cleanup

parent 775132d7
......@@ -5,6 +5,7 @@ open System.IO
// Values to export in the C code (uniform and attribute values)
let exportedValues = ref ([] : (string * string * string) list)
// 'ty' is a prefix for the type of shader param. Nothing (VAR) for vars, "F" for hlsl functions
let export ty name (newName:string) =
if newName.[0] <> '0' then
exportedValues := !exportedValues |> List.map (fun (ty2, name2, newName2 as arg) ->
......
......@@ -3,7 +3,6 @@
open Ast
let mutable identTable = [||]
let mutable output = stdout
let out a = sprintf a
// how to print variable names
......
......@@ -55,6 +55,8 @@ let stripSpaces str =
if macro then result.Append("\n") |> ignore
result.ToString()
let hasInlinePrefix (s:string) = s.StartsWith("i_")
let declsNotToInline d = d |> List.filter (fun x -> not (hasInlinePrefix x.name))
let bool = function
| true -> Var "true" // Int (1, "")
......@@ -113,6 +115,7 @@ let rec expr env = function
if (Printer.exprToS e).Length <= (Printer.exprToS div).Length then e
else div
// iq's smoothstep trick: http://www.pouet.net/topic.php?which=6751&page=1#c295695
| FunCall(Var "smoothstep", [Float (0.,_); Float (1.,_); _]) as e -> e
| FunCall(Var "smoothstep", [a; b; x]) when Ast.smoothstepTrick ->
let sub1 = FunCall(Var "-", [x; a])
......@@ -122,7 +125,7 @@ let rec expr env = function
| Dot(e, field) when fieldNames <> "" -> Dot(e, renameField field)
| Var s as e when s.StartsWith("i_") ->
| Var s as e when hasInlinePrefix s ->
match Map.tryFind s env.vars with
| Some (ty, size, Some init) -> init
| _ -> e
......@@ -174,10 +177,8 @@ let instr = function
Keyword("return", Some expr)
else
Block (squeezeDeclarations b)
| Decl (ty, li) -> Decl (rwType ty, li |> List.filter (fun x -> not (x.name.StartsWith("i_"))))
| ForD((ty, d), cond, inc, body) ->
let d = d |> List.filter (fun x -> not (x.name.StartsWith("i_")))
ForD((rwType ty, d), cond, inc, body)
| Decl (ty, li) -> Decl (rwType ty, declsNotToInline li)
| ForD((ty, d), cond, inc, body) -> ForD((rwType ty, declsNotToInline d), cond, inc, body)
// FIXME: properly handle booleans
| If(Var "true", e1, e2) -> e1
| If(Var "false", e1, Some e2) -> e2
......@@ -197,8 +198,7 @@ let apply li =
|> reorderTopLevel
|> mapTopLevel (mapEnv expr instr)
|> List.map (function
| TLDecl (ty, li) ->
TLDecl (rwType ty, li |> List.filter (fun x -> not (x.name.StartsWith("i_"))))
| TLDecl (ty, li) -> TLDecl (rwType ty, declsNotToInline li)
| TLVerbatim s -> TLVerbatim (stripSpaces s)
| e -> e
)
......
void main()
{
var x = 0.5;
var i_y = 0.6*x;
var a = x * i_y;
}
\ No newline at end of file
void main()
{
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
float s = sqrt( dot(p,p) );
s = smoothstep(0.0,1.0,s);
ao = smoothstep(0.0,0.4,s) - smoothstep(0.4,0.7,s);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment