MCPcopy Create free account
hub / github.com/DFHack/dfhack / plotLineDiffuse

Function plotLineDiffuse

plugins/rendermax/renderer_light.cpp:174–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172 return ;
173}
174void plotLineDiffuse(int x0, int y0, int x1, int y1,rgbf power,int num_diffuse,const std::function<rgbf(rgbf,int,int,int,int)>& setPixel,bool skip_hack=false)
175{
176
177 int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
178 int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
179 int dsq=dx*dx+dy*dy;
180 int err = dx+dy, e2; /* error value e_xy */
181 int rdx=0;
182 int rdy=0;
183 for(;;){ /* loop */
184 if(rdx!=0 || rdy!=0 || skip_hack) //dirty hack to skip occlusion on the first tile.
185 {
186 power=setPixel(power,rdx,rdy,x0,y0);
187 if(power.dot(power)<0.00001f)
188 return ;
189 }
190 if (x0==x1 && y0==y1) break;
191 e2 = 2*err;
192 rdx=rdy=0;
193 if (e2 >= dy) { err += dy; x0 += sx; rdx=sx;} /* e_xy+e_x > 0 */
194 if (e2 <= dx) { err += dx; y0 += sy; rdy=sy;} /* e_xy+e_y < 0 */
195
196 if(num_diffuse>0 && dsq/4<(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))//reached center?
197 {
198 const float betta=0.25;
199 int nx=y1-y0; //right angle
200 int ny=x1-x0;
201 if((nx*nx+ny*ny)*betta*betta>2)
202 {
203 plotLineDiffuse(x0,y0,x0+nx*betta,y0+ny*betta,power,num_diffuse-1,setPixel,true);
204 plotLineDiffuse(x0,y0,x0-nx*betta,y0-ny*betta,power,num_diffuse-1,setPixel,true);
205 }
206 }
207 }
208 return ;
209}
210void plotLineAA(int x0, int y0, int x1, int y1,rgbf power,const std::function<rgbf(rgbf,int,int,int,int)>& setPixelAA)
211{
212 int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;

Callers 1

doRayMethod · 0.85

Calls 1

dotMethod · 0.80

Tested by

no test coverage detected