/* draw_rgb.c * * Jiwon Hahn * * This program reads a material file, calculate XYZ and rgb values for each pixel, * and create corresponding r,g,b image files. * * Calling convention: prog materal_file * Output files are out.b out.g out.r */ #include #include #include #include //choose the parameters #define M 0.5 #define Lx 0.578 #define Ly 0.578 #define Lz 0.578 #define Z0 0 #define R 100 #define C 1 #define I_SIZE 250 //Calculation of Fresnel Reflectance float fresnel(float n,float k, int th) { float a, b, Rn, Rp; a=sqrt(0.5)*sqrt(sqrt((n*n-k*k-sin(th)*sin(th))*(n*n-k*k-sin(th)*sin(th))+4*n*n*k*k)+(n*n-k*k-sin(th)*sin(th))); b=sqrt(0.5)*sqrt(sqrt((n*n-k*k-sin(th)*sin(th))*(n*n-k*k-sin(th)*sin(th))+4*n*n*k*k)-(n*n-k*k-sin(th)*sin(th))); Rn=(a*a+b*b-2*a*cos(th)+cos(th)*cos(th))/(a*a+b*b+2*a*cos(th)+cos(th)*cos(th)); Rp=Rn*(a*a+b*b-2*a*sin(th)*tan(th)+sin(th)*sin(th)*tan(th)*tan(th)) / (a*a+b*b+2*a*sin(th)*tan(th)+sin(th)*sin(th)*tan(th)*tan(th)); return 0.5*(Rn+Rp); } //Interpolation - makes a continuous function and returns the value corresponding to given lambda float getvalue(float l, float *x, float *f, int N) { int i; for(i=0; i=1 && Gc>=1) G=1; else if(Gb