erebus
changeset 22:11cdaa510201
added -brdf arguments in scene construction commands
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 29 May 2014 03:35:04 +0300 |
parents | e49f4d7ad04c |
children | 56d504cc555a |
files | liberebus/src/scene.cc test/scene |
diffstat | 2 files changed, 71 insertions(+), 2 deletions(-) [+] |
line diff
1.1 --- a/liberebus/src/scene.cc Wed May 28 07:06:29 2014 +0300 1.2 +++ b/liberebus/src/scene.cc Thu May 29 03:35:04 2014 +0300 1.3 @@ -130,7 +130,7 @@ 1.4 1.5 bool Scene::load(FILE *fp) 1.6 { 1.7 - char buf[256]; 1.8 + static char buf[256]; 1.9 1.10 while(fgets(buf, sizeof buf, fp)) { 1.11 char *line = strip_wspace(buf); 1.12 @@ -172,6 +172,67 @@ 1.13 return nelem; 1.14 } 1.15 1.16 +static int parse_brdf(char **argv, Reflectance **brdf_ptr) 1.17 +{ 1.18 + CompositeRefl *composite = 0; 1.19 + Reflectance *brdf = 0; 1.20 + float weight = 1.0; 1.21 + int i; 1.22 + 1.23 + for(i=0; argv[i]; i++) { 1.24 + if(strcmp(argv[i], "-brdf") == 0) { 1.25 + if(strcmp(argv[++i], "lambert") == 0) { 1.26 + if(composite && brdf) { 1.27 + composite->add_brdf(brdf, weight); 1.28 + } 1.29 + brdf = new LambertRefl; 1.30 + if(!composite) break; 1.31 + 1.32 + } else if(strcmp(argv[i], "mirror") == 0) { 1.33 + if(composite && brdf) { 1.34 + composite->add_brdf(brdf, weight); 1.35 + } 1.36 + brdf = new MirrorRefl; 1.37 + if(!composite) break; 1.38 + 1.39 + } else if(strcmp(argv[i], "composite") == 0) { 1.40 + if(composite) { 1.41 + fprintf(stderr, "can't have nested composite BRDFs\n"); 1.42 + return -1; 1.43 + } 1.44 + composite = new CompositeRefl; 1.45 + 1.46 + } else { 1.47 + --i; 1.48 + break; 1.49 + } 1.50 + 1.51 + } else if(strcmp(argv[i], "-brdf-weight") == 0) { 1.52 + if(!composite) { 1.53 + fprintf(stderr, "-brdf-weight is invalid without a composite brdf\n"); 1.54 + return -1; 1.55 + } 1.56 + char *endp; 1.57 + weight = strtod(argv[++i], &endp); 1.58 + if(endp == argv[i]) { 1.59 + fprintf(stderr, "-brdf-weight must be followed by a number\n"); 1.60 + return -1; 1.61 + } 1.62 + } else { 1.63 + --i; 1.64 + break; 1.65 + } 1.66 + } 1.67 + 1.68 + if(composite && brdf) { 1.69 + composite->add_brdf(brdf, weight); 1.70 + *brdf_ptr = composite; 1.71 + } else { 1.72 + *brdf_ptr = brdf; 1.73 + } 1.74 + return i; 1.75 +} 1.76 + 1.77 static SceneNode *proc_object(Object *obj, int argc, char **argv) 1.78 { 1.79 float vec[4]; 1.80 @@ -243,6 +304,13 @@ 1.81 i += nelem; 1.82 gobj->mtl.set_attrib("emissive", emissive); 1.83 1.84 + } else if(strcmp(argv[i], "-brdf") == 0) { 1.85 + int nelem = parse_brdf(argv + i, &gobj->brdf); 1.86 + if(nelem == -1) { 1.87 + goto err; 1.88 + } 1.89 + i += nelem; 1.90 + 1.91 } else { 1.92 fprintf(stderr, "unrecognized %s option: %s\n", argv[0], argv[i]); 1.93 goto err;
2.1 --- a/test/scene Wed May 28 07:06:29 2014 +0300 2.2 +++ b/test/scene Thu May 29 03:35:04 2014 +0300 2.3 @@ -1,7 +1,8 @@ 2.4 # test scene 2.5 2.6 sphere -position 0 0 0 -scaling 1 1 1 -diffuse 1 0.5 0.4 2.7 -box -position 0 -1.25 0 -scaling 4 0.5 4 -diffuse 0.3 0.4 1.0 2.8 + 2.9 +box -position 0 -1.25 0 -scaling 4 0.5 4 -diffuse 0.3 0.4 1.0 -brdf composite -brdf lambert -brdf-weight 0.5 -brdf mirror -brdf-weight 0.5 2.10 2.11 box -position 0 5 0 -scaling 3 0.1 3 -emissive 5 5 5 2.12