matlab练习程序(渲染三原色)

这里我用的空间是x向右为正,y向下为正,z向屏幕里面为正。至关于标准右手系绕x轴旋转了180度。html

将三个点光源放在微信

r = [0.3,0,0.5];
g = [0.3,-0.5*cos(pi/6),-0.5*sin(pi/6)];
b = [0.3,0.5*cos(pi/6),-0.5*sin(pi/6)];post

这三个位置上,向四周发射光线,取光线到y-z平面的模的倒数做为光的强度。学习

图像以下:设计

程序以下:code

 
clear all;
close all;
clc;

r = [0.3,0,0.5];
g = [0.3,-0.5*cos(pi/6),-0.5*sin(pi/6)];
b = [0.3,0.5*cos(pi/6),-0.5*sin(pi/6)];
imgr1=[];imgr2=[];
imgg1=[];imgg2=[];
imgb1=[];imgb2=[];
for y=-1:0.004:1
   imgr1=[];imgg1=[];imgb1=[];
   for z=-1:0.004:1       
       pm=[0,y,z];         
       lightr=pm-r;
       lightg=pm-g;
       lightb=pm-b;
       imgr=1/norm(lightr);
       imgg=1/norm(lightg);
       imgb=1/norm(lightb);
       
       imgr1=[imgr1 imgr];
       imgg1=[imgg1 imgg];      
       imgb1=[imgb1 imgb];           
   end
   imgr2=[imgr2;imgr1];
   imgg2=[imgg2;imgg1];  
   imgb2=[imgb2;imgb1]; 
end

[h w]=size(imgr2);

img=zeros(h,w,3);
img(:,:,1) = mat2gray(imgr2);
img(:,:,2) = mat2gray(imgg2);
img(:,:,3) = mat2gray(imgb2);
imshow(img)
imwrite(img,'img.png')

关注公众号: MATLAB基于模型的设计 (ID:xaxymaker) ,天天推送MATLAB学习最多见的问题,天天进步一点点,业精于勤荒于嬉orm

 打开微信扫一扫哦!htm

转载于:https://www.cnblogs.com/52geek/p/10116690.htmlblog