diff --git a/fps.txt b/fps.txt deleted file mode 100644 index ffb358f..0000000 --- a/fps.txt +++ /dev/null @@ -1,2806 +0,0 @@ -0 -1199040 -259 -228 -229 -88 -1597 -157 -154 -167 -201 -152 -167 -171 -167 -177 -152 -219 -171 -189 -184 -179 -181 -183 -177 -178 -182 -177 -187 -189 -175 -188 -184 -178 -193 -185 -177 -208 -170 -177 -191 -185 -176 -205 -170 -209 -180 -159 -190 -195 -169 -204 -204 -212 -206 -198 -240 -184 -214 -221 -205 -203 -195 -210 -207 -212 -218 -203 -197 -198 -212 -202 -215 -212 -184 -224 -198 -210 -204 -196 -233 -179 -233 -152 -306 -202 -189 -212 -200 -208 -217 -202 -196 -191 -205 -201 -188 -228 -172 -198 -222 -200 -194 -193 -200 -196 -190 -222 -184 -190 -224 -176 -220 -193 -195 -198 -187 -202 -195 -190 -223 -180 -228 -187 -202 -195 -186 -196 -194 -188 -222 -170 -199 -207 -172 -222 -187 -192 -189 -185 -191 -194 -187 -193 -195 -184 -218 -169 -199 -204 -168 -206 -185 -199 -188 -219 -192 -191 -216 -212 -169 -214 -215 -170 -212 -213 -189 -188 -215 -217 -174 -214 -214 -191 -189 -213 -186 -186 -214 -203 -173 -213 -212 -174 -214 -215 -193 -186 -214 -188 -188 -214 -211 -165 -214 -209 -192 -185 -211 -191 -184 -216 -201 -174 -212 -213 -195 -182 -214 -190 -188 -212 -189 -187 -214 -214 -172 -212 -212 -187 -185 -211 -184 -184 -212 -205 -169 -214 -209 -164 -201 -211 -189 -184 -209 -187 -184 -212 -197 -172 -207 -202 -172 -207 -207 -172 -208 -209 -181 -185 -212 -192 -182 -212 -213 -168 -212 -214 -193 -183 -209 -191 -184 -214 -202 -171 -214 -213 -171 -215 -212 -189 -187 -211 -196 -184 -212 -217 -171 -213 -212 -185 -190 -214 -196 -185 -214 -217 -174 -217 -215 -192 -191 -216 -199 -189 -216 -219 -167 -215 -210 -189 -190 -222 -205 -174 -215 -218 -173 -214 -220 -184 -189 -223 -200 -191 -217 -219 -162 -209 -224 -196 -196 -221 -221 -167 -213 -228 -163 -225 -223 -198 -195 -220 -228 -167 -220 -223 -198 -191 -224 -219 -172 -222 -221 -199 -197 -221 -213 -179 -224 -223 -171 -224 -219 -200 -192 -224 -226 -174 -224 -219 -200 -196 -223 -227 -175 -225 -226 -198 -193 -224 -223 -174 -227 -225 -202 -193 -223 -205 -195 -225 -226 -198 -195 -223 -229 -179 -224 -229 -193 -195 -229 -232 -172 -230 -226 -190 -193 -232 -231 -185 -234 -227 -209 -199 -232 -223 -178 -235 -234 -213 -203 -242 -238 -211 -210 -241 -242 -187 -241 -236 -215 -209 -235 -244 -210 -201 -240 -240 -213 -208 -243 -229 -199 -237 -245 -202 -213 -243 -241 -197 -214 -236 -246 -219 -209 -241 -234 -192 -238 -251 -215 -207 -249 -253 -219 -214 -251 -252 -222 -221 -255 -254 -231 -222 -260 -253 -226 -218 -259 -258 -227 -219 -258 -256 -230 -220 -258 -261 -208 -223 -260 -259 -233 -223 -261 -261 -214 -224 -268 -267 -233 -232 -266 -266 -232 -226 -274 -276 -246 -238 -268 -275 -278 -204 -271 -283 -271 -239 -236 -284 -276 -236 -239 -277 -283 -289 -215 -275 -283 -283 -243 -246 -288 -288 -249 -233 -288 -292 -291 -248 -244 -289 -290 -261 -249 -287 -293 -294 -231 -240 -289 -282 -251 -237 -283 -284 -285 -218 -279 -289 -277 -257 -240 -287 -291 -285 -260 -237 -297 -296 -248 -249 -293 -296 -292 -215 -296 -296 -296 -262 -249 -296 -302 -300 -246 -252 -301 -302 -270 -255 -297 -301 -305 -246 -252 -301 -306 -308 -268 -254 -310 -310 -305 -274 -259 -307 -315 -294 -249 -310 -315 -317 -314 -246 -314 -320 -314 -303 -246 -311 -322 -320 -274 -268 -313 -322 -324 -336 -278 -262 -326 -326 -277 -261 -328 -316 -322 -286 -269 -316 -322 -324 -287 -330 -265 -322 -328 -322 -290 -268 -321 -322 -321 -290 -269 -321 -322 -327 -277 -266 -322 -326 -315 -279 -264 -321 -322 -326 -281 -267 -327 -325 -325 -269 -280 -322 -326 -325 -281 -270 -321 -329 -320 -272 -268 -320 -328 -325 -265 -271 -326 -328 -321 -288 -268 -322 -327 -321 -278 -269 -321 -320 -320 -285 -265 -320 -326 -321 -276 -267 -321 -323 -326 -279 -268 -322 -323 -315 -275 -265 -321 -312 -316 -274 -262 -321 -314 -316 -274 -263 -317 -315 -313 -270 -259 -312 -307 -315 -228 -305 -312 -311 -287 -239 -306 -305 -310 -265 -253 -306 -302 -305 -248 -250 -300 -302 -266 -255 -292 -296 -298 -243 -248 -300 -298 -300 -258 -247 -300 -296 -243 -246 -297 -297 -294 -262 -250 -293 -289 -264 -246 -294 -292 -293 -255 -245 -297 -291 -254 -293 -243 -287 -288 -254 -237 -293 -284 -281 -216 -282 -288 -282 -249 -244 -282 -283 -246 -234 -282 -283 -276 -241 -237 -283 -278 -232 -237 -280 -279 -249 -237 -275 -283 -253 -278 -240 -279 -278 -236 -237 -276 -275 -245 -231 -275 -276 -268 -205 -266 -276 -267 -205 -270 -275 -276 -239 -231 -272 -272 -228 -230 -272 -267 -253 -212 -271 -268 -272 -209 -266 -272 -267 -235 -231 -267 -264 -237 -228 -264 -264 -235 -225 -267 -260 -240 -220 -260 -264 -231 -223 -260 -264 -226 -223 -264 -260 -233 -221 -256 -261 -219 -219 -257 -257 -223 -223 -260 -254 -232 -222 -261 -257 -220 -215 -260 -257 -222 -221 -260 -257 -225 -216 -258 -252 -221 -216 -260 -254 -214 -218 -256 -253 -228 -221 -254 -253 -226 -221 -247 -250 -217 -206 -252 -257 -195 -244 -249 -249 -190 -247 -251 -250 -195 -247 -249 -218 -213 -248 -243 -218 -213 -244 -246 -222 -211 -244 -248 -188 -240 -247 -231 -197 -246 -247 -218 -208 -244 -241 -219 -208 -244 -240 -215 -210 -245 -244 -189 -238 -241 -211 -207 -240 -241 -208 -206 -240 -237 -188 -238 -240 -237 -187 -240 -237 -214 -201 -239 -234 -184 -237 -236 -224 -188 -239 -237 -214 -201 -240 -236 -203 -204 -234 -227 -187 -235 -238 -199 -205 -235 -227 -186 -230 -235 -211 -202 -234 -235 -204 -203 -236 -233 -191 -234 -234 -208 -204 -232 -235 -213 -200 -233 -225 -184 -235 -232 -211 -199 -233 -228 -184 -230 -231 -207 -198 -232 -231 -175 -226 -232 -214 -188 -232 -229 -207 -197 -229 -222 -180 -232 -228 -207 -203 -232 -234 -183 -232 -229 -208 -198 -231 -229 -207 -199 -229 -200 -196 -227 -230 -193 -200 -229 -203 -195 -228 -227 -194 -197 -229 -200 -195 -227 -226 -194 -197 -227 -202 -195 -227 -226 -198 -197 -223 -198 -194 -226 -227 -178 -222 -223 -193 -194 -224 -227 -180 -227 -227 -197 -194 -222 -224 -172 -223 -224 -192 -192 -224 -207 -196 -227 -224 -193 -194 -224 -225 -180 -227 -223 -198 -195 -223 -211 -184 -222 -224 -197 -197 -222 -202 -194 -223 -225 -178 -222 -224 -212 -182 -224 -223 -174 -226 -223 -205 -193 -223 -226 -173 -221 -224 -192 -195 -223 -211 -184 -224 -224 -199 -196 -224 -203 -194 -225 -221 -168 -218 -224 -197 -196 -221 -223 -203 -191 -225 -201 -196 -223 -224 -173 -223 -227 -204 -198 -227 -224 -179 -222 -227 -204 -195 -226 -227 -182 -227 -226 -202 -199 -227 -226 -200 -197 -228 -196 -198 -227 -226 -206 -196 -226 -199 -199 -226 -228 -181 -223 -229 -206 -200 -226 -227 -204 -200 -230 -227 -186 -226 -230 -201 -199 -232 -224 -186 -229 -229 -211 -199 -232 -229 -184 -230 -232 -232 -187 -232 -232 -205 -201 -232 -229 -187 -232 -230 -205 -200 -229 -232 -177 -229 -232 -201 -204 -232 -235 -210 -205 -235 -235 -181 -235 -234 -209 -206 -238 -226 -191 -207 -242 -214 -205 -234 -232 -199 -204 -240 -241 -181 -231 -239 -219 -199 -239 -234 -192 -204 -234 -236 -184 -237 -248 -209 -205 -236 -240 -212 -211 -237 -240 -220 -206 -237 -228 -194 -239 -242 -218 -206 -243 -234 -215 -207 -242 -237 -187 -238 -241 -212 -209 -239 -240 -209 -208 -240 -240 -210 -206 -245 -225 -206 -244 -244 -232 -195 -247 -243 -223 -207 -244 -246 -220 -212 -247 -244 -184 -240 -243 -250 -184 -244 -244 -218 -209 -244 -244 -216 -210 -244 -243 -221 -210 -247 -242 -186 -240 -246 -231 -194 -245 -243 -220 -209 -244 -247 -217 -210 -242 -244 -184 -240 -243 -224 -211 -243 -246 -207 -209 -245 -240 -222 -209 -240 -244 -218 -206 -242 -241 -189 -241 -241 -216 -208 -241 -246 -213 -213 -239 -241 -220 -207 -244 -240 -186 -240 -242 -215 -209 -238 -233 -216 -201 -234 -239 -211 -205 -233 -223 -189 -234 -235 -213 -203 -231 -234 -185 -230 -238 -204 -207 -237 -234 -213 -204 -237 -236 -185 -234 -235 -204 -204 -232 -233 -209 -204 -232 -230 -187 -234 -232 -209 -201 -232 -231 -179 -227 -232 -202 -200 -234 -231 -210 -201 -229 -225 -180 -229 -229 -195 -202 -228 -237 -176 -229 -227 -207 -198 -230 -229 -183 -224 -227 -196 -197 -228 -228 -180 -221 -228 -191 -196 -222 -225 -183 -229 -224 -203 -196 -223 -225 -177 -223 -224 -204 -195 -221 -224 -172 -221 -224 -197 -197 -218 -204 -186 -221 -222 -170 -217 -221 -194 -193 -223 -220 -174 -220 -221 -194 -192 -218 -202 -180 -219 -219 -173 -214 -216 -193 -184 -218 -213 -172 -219 -221 -175 -216 -221 -192 -188 -216 -214 -173 -217 -219 -195 -192 -218 -196 -190 -217 -217 -198 -189 -213 -186 -187 -214 -198 -188 -212 -213 -173 -209 -212 -180 -189 -216 -194 -188 -214 -219 -172 -211 -217 -190 -190 -214 -202 -176 -211 -214 -171 -215 -212 -195 -184 -212 -196 -187 -213 -210 -154 -221 -214 -195 -182 -208 -187 -184 -211 -184 -183 -217 -210 -172 -213 -212 -167 -208 -211 -191 -186 -212 -205 -168 -211 -217 -164 -206 -210 -167 -207 -220 -187 -188 -213 -190 -188 -214 -216 -172 -214 -215 -192 -188 -216 -189 -187 -216 -215 -166 -211 -214 -184 -191 -218 -200 -183 -219 -217 -172 -217 -219 -193 -192 -219 -202 -178 -218 -223 -175 -213 -221 -197 -190 -210 -212 -172 -221 -219 -195 -193 -216 -210 -173 -219 -221 -173 -216 -222 -192 -192 -214 -203 -178 -223 -220 -202 -189 -224 -192 -193 -223 -223 -171 -220 -224 -193 -196 -232 -206 -196 -227 -224 -195 -196 -221 -207 -196 -223 -228 -181 -198 -227 -213 -182 -227 -230 -170 -220 -229 -200 -191 -229 -222 -206 -200 -226 -218 -189 -228 -233 -201 -203 -231 -229 -173 -228 -228 -201 -198 -232 -231 -175 -232 -235 -199 -203 -235 -231 -215 -202 -235 -218 -197 -235 -235 -190 -205 -239 -233 -179 -237 -239 -204 -208 -240 -236 -204 -206 -239 -242 -178 -241 -244 -222 -206 -240 -248 -213 -208 -243 -242 -215 -215 -245 -250 -195 -252 -254 -236 -198 -251 -255 -252 -200 -253 -257 -256 -200 -253 -257 -224 -217 -258 -256 -240 -206 -254 -259 -234 -217 -258 -260 -238 -201 -260 -262 -231 -222 -261 -258 -265 -202 -263 -269 -236 -223 -268 -260 -258 -210 -264 -262 -265 -232 -233 -269 -271 -228 -228 -273 -272 -223 -228 -270 -277 -240 -226 -276 -275 -248 -234 -276 -273 -275 -239 -232 -281 -275 -243 -231 -282 -280 -258 -214 -278 -284 -270 -210 -275 -278 -286 -224 -231 -280 -286 -245 -241 -285 -284 -284 -264 -237 -288 -284 -250 -240 -289 -286 -285 -265 -239 -290 -289 -256 -242 -291 -292 -284 -217 -289 -294 -286 -243 -236 -293 -290 -287 -208 -280 -292 -288 -235 -246 -292 -290 -257 -249 -289 -294 -280 -240 -240 -294 -277 -254 -243 -289 -284 -296 -224 -250 -281 -286 -255 -235 -296 -297 -287 -267 -255 -294 -292 -246 -237 -300 -292 -308 -263 -249 -300 -305 -276 -237 -296 -302 -297 -261 -255 -308 -306 -310 -267 -254 -300 -320 -288 -234 -297 -315 -315 -275 -266 -309 -316 -316 -285 -262 -316 -316 -323 -283 -262 -304 -300 -317 -259 -262 -324 -321 -328 -281 -244 -319 -323 -323 -271 -269 -314 -333 -324 -270 -260 -327 -333 -327 -281 -277 -332 -331 -332 -278 -260 -330 -334 -337 -312 -317 -276 -336 -348 -312 -298 -273 -335 -338 -339 -289 -275 -335 -340 -328 -290 -267 -332 -332 -336 -293 -277 -327 -332 -338 -330 -292 -279 -337 -338 -335 -281 -271 -330 -337 -334 -293 -272 -336 -339 -332 -287 -277 -337 -337 -335 -277 -271 -335 -332 -335 -308 -292 -252 -325 -325 -301 -248 -334 -325 -323 -284 -261 -315 -333 -319 -280 -266 -308 -328 -315 -286 -331 -259 -326 -317 -328 -284 -251 -316 -311 -295 -292 -257 -294 -331 -256 -263 -333 -316 -314 -254 -261 -315 -316 -308 -255 -260 -308 -316 -304 -276 -258 -311 -310 -302 -285 -249 -310 -302 -266 -252 -302 -300 -289 -252 -246 -308 -301 -270 -273 -244 -298 -294 -254 -243 -293 -292 -283 -248 -242 -290 -290 -250 -240 -294 -273 -271 -223 -289 -285 -303 -253 -240 -291 -286 -268 -221 -286 -290 -287 -253 -243 -283 -283 -249 -234 -280 -281 -284 -248 -243 -283 -282 -247 -233 -278 -280 -265 -214 -279 -280 -269 -205 -256 -280 -271 -226 -233 -269 -274 -233 -229 -273 -270 -245 -228 -270 -274 -229 -236 -271 -271 -257 -210 -256 -268 -258 -242 -237 -268 -271 -224 -225 -264 -263 -237 -225 -264 -263 -235 -222 -264 -264 -226 -223 -264 -259 -229 -222 -263 -258 -224 -219 -263 -262 -220 -220 -259 -260 -229 -216 -260 -256 -214 -216 -253 -256 -228 -215 -252 -255 -224 -217 -256 -250 -225 -216 -254 -249 -222 -214 -249 -250 -210 -212 -248 -251 -194 -244 -247 -247 -193 -242 -247 -220 -206 -246 -239 -218 -207 -244 -241 -184 -240 -242 -218 -201 -240 -238 -200 -204 -234 -239 -206 -201 -238 -217 -204 -233 -238 -201 -202 -235 -224 -186 -234 -235 -206 -204 -230 -234 -177 -229 -235 -213 -202 -229 -235 -197 -198 -235 -232 -189 -232 -234 -211 -198 -232 -229 -210 -198 -228 -216 -200 -232 -228 -210 -194 -230 -232 -181 -230 -230 -205 -197 -232 -229 -208 -202 -231 -200 -200 -229 -229 -171 -229 -227 -217 -186 -230 -229 -204 -196 -226 -229 -182 -228 -227 -202 -196 -224 -228 -178 -222 -225 -199 -194 -225 -216 -182 -224 -224 -167 -224 -224 -214 -182 -224 -224 -203 -192 -225 -201 -192 -223 -223 -178 -224 -220 -201 -187 -223 -222 -170 -225 -224 -191 -191 -223 -227 -177 -223 -221 -200 -190 -225 -192 -193 -222 -221 -180 -222 -223 -199 -192 -222 -213 -177 -223 -220 -187 -191 -225 -205 -181 -221 -220 -197 -192 -219 -194 -190 -224 -218 -178 -221 -222 -195 -196 -219 -206 -181 -219 -222 -196 -189 -219 -188 -188 -219 -222 -166 -219 -221 -198 -189 -219 -210 -176 -219 -215 -170 -218 -217 -184 -188 -218 -199 -190 -219 -216 -167 -217 -216 -192 -185 -217 -193 -186 -216 -213 -166 -212 -214 -192 -188 -213 -191 -186 -213 -204 -173 -215 -216 -193 -186 -216 -205 -173 -217 -198 -186 -212 -215 -163 -208 -217 -192 -184 -216 -188 -185 -214 -213 -163 -216 -214 -195 -187 -216 -199 -185 -216 -214 -165 -213 -214 -196 -186 -215 -198 -188 -215 -214 -171 -217 -216 -196 -186 -217 -191 -188 -219 -212 -176 -212 -219 -182 -194 -218 -203 -178 -218 -218 -173 -218 -216 -187 -189 -216 -200 -190 -217 -218 -198 -186 -217 -199 -189 -220 -206 -176 -219 -218 -197 -192 -218 -200 -190 -218 -217 -173 -216 -219 -198 -192 -219 -220 -172 -222 -222 -192 -192 -222 -200 -194 -223 -221 -193 -191 -224 -198 -194 -221 -222 -173 -220 -224 -201 -195 -223 -213 -183 -223 -224 -201 -196 -224 -207 -196 -226 -226 -202 -196 -226 -215 -186 -224 -224 -204 -199 -223 -231 -180 -226 -227 -208 -199 -227 -230 -181 -224 -230 -199 -202 -228 -230 -184 -222 -227 -200 -198 -227 -229 -182 -225 -230 -217 -189 -228 -232 -205 -197 -229 -227 -187 -230 -232 -209 -195 -229 -232 -178 -230 -231 -207 -202 -232 -229 -186 -224 -233 -213 -192 -231 -229 -206 -201 -229 -230 -189 -227 -232 -210 -200 -235 -231 -178 -224 -235 -202 -204 -237 -234 -214 -202 -238 -234 -189 -235 -233 -205 -211 -235 -238 -213 -205 -241 -238 -186 -234 -237 -207 -205 -240 -237 -212 -202 -241 -238 -217 -202 -241 -224 -193 -238 -239 -207 -208 -238 diff --git a/imgui.ini b/imgui.ini index cbaa00b..3353b93 100644 --- a/imgui.ini +++ b/imgui.ini @@ -11,10 +11,14 @@ Pos=1648,207 Size=266,285 [Window][Fog settings] -Pos=1654,501 +Pos=1640,500 Size=247,157 [Window][Debug] -Pos=1642,667 +Pos=1642,668 Size=260,143 +[Window][Debug BVH] +Pos=60,60 +Size=159,127 + diff --git a/includes/RT/BVH.hpp b/includes/RT/BVH.hpp index c796431..1e2f5e0 100644 --- a/includes/RT/BVH.hpp +++ b/includes/RT/BVH.hpp @@ -27,6 +27,11 @@ struct AABB AABB(glm::vec3 min, glm::vec3 max) : min(min), max(max) {} }; +struct BVHStats { + int min_triangles; + int max_triangles; + float average_triangles; +}; class BVH { @@ -39,7 +44,9 @@ class BVH void updateBounds(std::vector &primitives); void subdivide(std::vector &primitives); - int size(); + int getSize(); + int getLeaves(); + BVHStats analyzeBVHLeaves(BVH* root); void flatten(std::vector &bvhs, int ¤tIndex); GPUBvh toGPUBvh(); diff --git a/scenes/dragon.rt b/scenes/dragon.rt index 1ba5a34..7c36d57 100644 --- a/scenes/dragon.rt +++ b/scenes/dragon.rt @@ -23,7 +23,7 @@ pl 0 -2 0 0 1 0 2 // floor qu -1 1.999 -1 2 0 0 0 0 2 6 -# sp 1 1 0 0.5 6 +# sp 1 1 0 0.1 6 OBJ obj/Dragon_80K.obj diff --git a/scenes/test.rt b/scenes/test.rt index ce820a6..02fe112 100644 --- a/scenes/test.rt +++ b/scenes/test.rt @@ -22,4 +22,4 @@ pl 0 -10 0 0 1 0 2 // floor qu -20 59 -20 40 0 0 0 0 40 6 -OBJ obj/audi.obj +OBJ obj/Model.obj diff --git a/shaders/debug.glsl b/shaders/debug.glsl index 7072d66..ff7ccc6 100644 --- a/shaders/debug.glsl +++ b/shaders/debug.glsl @@ -140,24 +140,23 @@ hitInfo traceBVH(Ray ray, inout Stats stats) hit.t = 1e30; hit.obj_index = -1; - int stack[64]; + int stack[32]; int stack_ptr = 0; stack[0] = 0; while (stack_ptr >= 0) { int current_index = stack[stack_ptr--]; - GPUBvh node = bvh[current_index]; if (node.is_leaf != 0) { for (int i = 0; i < node.primitive_count; i++) - { + { GPUTriangle obj = triangles[node.first_primitive + i]; hitInfo temp_hit; - if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t > 0.0f && temp_hit.t < hit.t + 0.0001) + if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t < hit.t) { hit.t = temp_hit.t; hit.normal = temp_hit.normal; diff --git a/shaders/trace.glsl b/shaders/trace.glsl index de1a0e8..b407cfd 100644 --- a/shaders/trace.glsl +++ b/shaders/trace.glsl @@ -66,7 +66,7 @@ hitInfo traceBVH(Ray ray) hit.t = 1e30; hit.obj_index = -1; - int stack[64]; + int stack[32]; int stack_ptr = 0; stack[0] = 0; @@ -84,7 +84,7 @@ hitInfo traceBVH(Ray ray) GPUTriangle obj = triangles[node.first_primitive + i]; hitInfo temp_hit; - if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t > 0.0f && temp_hit.t < hit.t + 0.0001) + if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t < hit.t) { hit.t = temp_hit.t; hit.last_t = temp_hit.last_t; diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 6eff0f1..3d4f7b9 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -20,8 +20,8 @@ int main(int argc, char **argv) return (1); Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0); - // Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl"); - Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl"); + Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl"); + // Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl"); GLint max_gpu_size; glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size); @@ -128,7 +128,7 @@ int main(int argc, char **argv) recorded_fps.push_back((int)window.getFps()); - float y_offset = 0.; + float y_offset = 0; float dist_to_obj = 2; float speed = 0.5; diff --git a/srcs/class/BVH.cpp b/srcs/class/BVH.cpp index 3745cc6..e5befc4 100644 --- a/srcs/class/BVH.cpp +++ b/srcs/class/BVH.cpp @@ -145,26 +145,74 @@ void BVH::flatten(std::vector &bvhs, int ¤tIndex) bvhs[self_index] = self_bvh; } -int BVH::size() -{ - int count = 0; - - if (_is_leaf) - return (0); - - count += 1 + _left->size(); - count += 1 + _right->size(); - - return (count); -} - std::vector BVH::getGPUBvhs() { - std::vector bvhs(size() + 1); + std::vector bvhs(getSize() + 1); int currentIndex = 0; flatten(bvhs, currentIndex); return (bvhs); +} + +int BVH::getSize() +{ + int count = 0; + + if (_is_leaf) + return (0); + + count += 1 + _left->getSize(); + count += 1 + _right->getSize(); + + return (count); +} + +int BVH::getLeaves() +{ + int count = 0; + + if (_is_leaf) + return (1); + + count += _left->getLeaves(); + count += _right->getLeaves(); + + return (count); +} + +//get tri per leaf min max and average +BVHStats BVH::analyzeBVHLeaves(BVH *root) +{ + if (!root) + return {0, 0, 0.0f}; + // If this is a leaf node, return its stats + + if (root->_is_leaf) + return { + root->_primitive_count, // min + root->_primitive_count, // max + (float)root->_primitive_count // average + }; + + // Get stats from left and right subtrees + BVHStats left = analyzeBVHLeaves(root->_left); + BVHStats right = analyzeBVHLeaves(root->_right); + + // Combine the results + int min_count = std::min(left.min_triangles, right.min_triangles); + int max_count = std::max(left.max_triangles, right.max_triangles); + + // Calculate weighted average based on number of leaves in each subtree + float left_leaf_count = (left.average_triangles > 0) ? 1.0f : 0.0f; + float right_leaf_count = (right.average_triangles > 0) ? 1.0f : 0.0f; + float total_leaf_count = left_leaf_count + right_leaf_count; + + float avg_count = 0.0f; + if (total_leaf_count > 0) + avg_count = (left.average_triangles * left_leaf_count + + right.average_triangles * right_leaf_count) / total_leaf_count; + + return {min_count, max_count, avg_count}; } \ No newline at end of file diff --git a/srcs/class/Scene.cpp b/srcs/class/Scene.cpp index 8080243..febad85 100644 --- a/srcs/class/Scene.cpp +++ b/srcs/class/Scene.cpp @@ -64,8 +64,15 @@ bool Scene::parseScene(char *name) BVH *bvh = new BVH(_gpu_triangles, 0, _gpu_triangles.size()); _gpu_bvh = bvh->getGPUBvhs(); - std::cout << "BVH Done: " << bvh->size() << std::endl; + std::cout << "BVH Done: " << std::endl; + std::cout << "\tBVH size: " << bvh->getSize() << std::endl; + std::cout << "\tBVH leaves: " << bvh->getLeaves() << std::endl << std::endl; + + BVHStats stats = bvh->analyzeBVHLeaves(bvh); + std::cout << "\tMin triangles per leaf: " << stats.min_triangles << std::endl; + std::cout << "\tMax triangles per leaf: " << stats.max_triangles << std::endl; + std::cout << "\tAverage triangles per leaf: " << stats.average_triangles << std::endl << std::endl; return (true); } diff --git a/srcs/class/Window.cpp b/srcs/class/Window.cpp index 2b0ea7a..5acc4cc 100644 --- a/srcs/class/Window.cpp +++ b/srcs/class/Window.cpp @@ -248,7 +248,7 @@ void Window::imGuiRender() ImGui::End(); - ImGui::Begin("Debug"); + ImGui::Begin("Debug BVH"); has_changed |= ImGui::Checkbox("Enable", (bool *)(&_scene->getDebug().enabled)); ImGui::Separator();