450 if(bgfx::isValid(tex_color_))
456 tex_color_ = bgfx::createUniform(
"s_texColor", bgfx::UniformType::Sampler);
457 shadow_map_[0] = bgfx::createUniform(
"s_shadowMap0", bgfx::UniformType::Sampler);
458 shadow_map_[1] = bgfx::createUniform(
"s_shadowMap1", bgfx::UniformType::Sampler);
459 shadow_map_[2] = bgfx::createUniform(
"s_shadowMap2", bgfx::UniformType::Sampler);
460 shadow_map_[3] = bgfx::createUniform(
"s_shadowMap3", bgfx::UniformType::Sampler);
464 rt_shadow_map_[i] = {bgfx::kInvalidHandle};
474 { { 0.0f, 0.0f, 0.0f, 1.0f } },
475 { { 0.0f,-0.4f,-0.6f, 0.0f } },
480 { { 0.5f,-1.0f, 0.1f, 0.0f } },
481 { { 0.0f, 0.0f, 0.0f, 1.0f } },
487 color_[0] = color_[1] = color_[2] = color_[3] = 1.0f;
488 uniforms_.
setPtrs(&point_light_,
506 10.0f, 7.0f, 12.0f, 1.0f
507 , 10.0f, 1.0f, 20.0f, 1.0f
508 , 1.0f, 1.0f, 10.0f, 1.0f
509 , 250.0f, 100.0f, 2000.0f, 50.0f
510 , 0.0035f, 0.0f, 0.01f, 0.00001f
511 , 0.0012f, 0.0f, 0.05f, 0.00001f
512 , 0.7f, 0.0f, 1.0f, 0.01f
513 , 500.0f, 1.0f, 1000.0f, 1.0f
514 , 2.0f, 0.0f, 4.0f, 1.0f
515 , 2.0f, 0.0f, 4.0f, 1.0f
516 , 1.0f, 0.0f, 3.0f, 0.01f
517 , 1.0f, 0.0f, 3.0f, 0.01f
524 10.0f, 7.0f, 12.0f, 1.0f
525 , 10.0f, 1.0f, 20.0f, 1.0f
526 , 1.0f, 1.0f, 99.0f, 1.0f
527 , 250.0f, 100.0f, 2000.0f, 50.0f
528 , 0.007f, 0.0f, 0.01f, 0.00001f
529 , 0.001f, 0.0f, 0.05f, 0.00001f
530 , 0.7f, 0.0f, 1.0f, 0.01f
531 , 500.0f, 1.0f, 1000.0f, 1.0f
532 , 2.0f, 0.0f, 8.0f, 1.0f
533 , 2.0f, 0.0f, 8.0f, 1.0f
534 , 1.0f, 0.0f, 3.0f, 0.01f
535 , 1.0f, 0.0f, 3.0f, 0.01f
542 10.0f, 7.0f, 12.0f, 1.0f
543 , 10.0f, 1.0f, 20.0f, 1.0f
544 , 1.0f, 1.0f, 99.0f, 1.0f
545 , 250.0f, 100.0f, 2000.0f, 50.0f
546 , 0.007f, 0.0f, 0.01f, 0.00001f
547 , 0.001f, 0.0f, 0.05f, 0.00001f
548 , 0.7f, 0.0f, 1.0f, 0.01f
549 , 500.0f, 1.0f, 1000.0f, 1.0f
550 , 2.0f, 0.0f, 8.0f, 1.0f
551 , 2.0f, 0.0f, 8.0f, 1.0f
552 , 1.0f, 0.0f, 3.0f, 0.01f
553 , 1.0f, 0.0f, 3.0f, 0.01f
560 10.0f, 7.0f, 12.0f, 1.0f
561 , 10.0f, 1.0f, 20.0f, 1.0f
562 , 8.0f, 1.0f, 10.0f, 1.0f
563 , 250.0f, 100.0f, 2000.0f, 50.0f
564 , 0.045f, 0.0f, 0.1f, 0.00001f
565 , 0.001f, 0.0f, 0.05f, 0.00001f
566 , 0.02f, 0.0f, 0.04f, 0.00001f
567 , 450.0f, 1.0f, 1000.0f, 1.0f
568 , 2.0f, 0.0f, 4.0f, 1.0f
569 , 2.0f, 0.0f, 4.0f, 1.0f
570 , 1.0f, 0.0f, 3.0f, 0.01f
571 , 1.0f, 0.0f, 3.0f, 0.01f
578 10.0f, 7.0f, 12.0f, 1.0f
579 , 10.0f, 1.0f, 20.0f, 1.0f
580 , 3.0f, 1.0f, 10.0f, 0.01f
581 , 250.0f, 100.0f, 2000.0f, 50.0f
582 , 0.02f, 0.0f, 0.3f, 0.00001f
583 , 0.001f, 0.0f, 0.05f, 0.00001f
584 , 0.7f, 0.0f, 1.0f, 0.01f
585 , 9000.0f, 1.0f, 15000.0f, 1.0f
586 , 2.0f, 0.0f, 4.0f, 1.0f
587 , 2.0f, 0.0f, 4.0f, 1.0f
588 , 1.0f, 0.0f, 3.0f, 0.01f
589 , 1.0f, 0.0f, 3.0f, 0.01f
600 10.0f, 7.0f, 12.0f, 1.0f
601 , 1.0f, 1.0f, 20.0f, 1.0f
602 , 1.0f, 1.0f, 10.0f, 1.0f
603 , 250.0f, 100.0f, 2000.0f, 50.0f
604 , 0.0025f, 0.0f, 0.01f, 0.00001f
605 , 0.0012f, 0.0f, 0.05f, 0.00001f
606 , 0.7f, 0.0f, 1.0f, 0.01f
607 , 500.0f, 1.0f, 1000.0f, 1.0f
608 , 2.0f, 0.0f, 4.0f, 1.0f
609 , 2.0f, 0.0f, 4.0f, 1.0f
610 , 1.0f, 0.0f, 3.0f, 0.01f
611 , 1.0f, 0.0f, 3.0f, 0.01f
618 10.0f, 7.0f, 12.0f, 1.0f
619 , 1.0f, 1.0f, 20.0f, 1.0f
620 , 1.0f, 1.0f, 99.0f, 1.0f
621 , 250.0f, 100.0f, 2000.0f, 50.0f
622 , 0.0025f, 0.0f, 0.01f, 0.00001f
623 , 0.001f, 0.0f, 0.05f, 0.00001f
624 , 0.7f, 0.0f, 1.0f, 0.01f
625 , 2000.0f, 1.0f, 2000.0f, 1.0f
626 , 2.0f, 0.0f, 8.0f, 1.0f
627 , 2.0f, 0.0f, 8.0f, 1.0f
628 , 1.0f, 0.0f, 3.0f, 0.01f
629 , 1.0f, 0.0f, 3.0f, 0.01f
636 10.0f, 7.0f, 12.0f, 1.0f
637 , 1.0f, 1.0f, 20.0f, 1.0f
638 , 1.0f, 1.0f, 99.0f, 1.0f
639 , 250.0f, 100.0f, 2000.0f, 50.0f
640 , 0.0025f, 0.0f, 0.01f, 0.00001f
641 , 0.001f, 0.0f, 0.05f, 0.00001f
642 , 0.7f, 0.0f, 1.0f, 0.01f
643 , 2000.0f, 1.0f, 2000.0f, 1.0f
644 , 2.0f, 0.0f, 8.0f, 1.0f
645 , 2.0f, 0.0f, 8.0f, 1.0f
646 , 1.0f, 0.0f, 3.0f, 0.01f
647 , 1.0f, 0.0f, 3.0f, 0.01f
654 10.0f, 7.0f, 12.0f, 1.0f
655 , 1.0f, 1.0f, 20.0f, 1.0f
656 , 1.0f, 1.0f, 10.0f, 1.0f
657 , 250.0f, 100.0f, 2000.0f, 50.0f
658 , 0.006f, 0.0f, 0.01f, 0.00001f
659 , 0.001f, 0.0f, 0.05f, 0.00001f
660 , 0.02f, 0.0f, 0.1f, 0.00001f
661 , 300.0f, 1.0f, 1500.0f, 1.0f
662 , 2.0f, 0.0f, 4.0f, 1.0f
663 , 2.0f, 0.0f, 4.0f, 1.0f
664 , 1.0f, 0.0f, 3.0f, 0.01f
665 , 1.0f, 0.0f, 3.0f, 0.01f
672 10.0f, 7.0f, 12.0f, 1.0f
673 , 1.0f, 1.0f, 20.0f, 1.0f
674 , 1.0f, 1.0f, 10.0f, 0.01f
675 , 250.0f, 100.0f, 2000.0f, 50.0f
676 , 0.0055f, 0.0f, 0.01f, 0.00001f
677 , 0.001f, 0.0f, 0.05f, 0.00001f
678 , 0.7f, 0.0f, 1.0f, 0.01f
679 , 2500.0f, 1.0f, 5000.0f, 1.0f
680 , 2.0f, 0.0f, 4.0f, 1.0f
681 , 2.0f, 0.0f, 4.0f, 1.0f
682 , 1.0f, 0.0f, 3.0f, 0.01f
683 , 1.0f, 0.0f, 3.0f, 0.01f
698 12.0f, 9.0f, 12.0f, 1.0f
699 , 10.0f, 1.0f, 20.0f, 1.0f
700 , 1.0f, 1.0f, 10.0f, 1.0f
701 , 250.0f, 100.0f, 2000.0f, 50.0f
702 , 0.006f, 0.0f, 0.01f, 0.00001f
703 , 0.001f, 0.0f, 0.05f, 0.00001f
704 , 0.7f, 0.0f, 1.0f, 0.01f
705 , 50.0f, 1.0f, 300.0f, 1.0f
706 , 2.0f, 0.0f, 4.0f, 1.0f
707 , 2.0f, 0.0f, 4.0f, 1.0f
708 , 0.25f, 0.0f, 2.0f, 0.001f
709 , 0.25f, 0.0f, 2.0f, 0.001f
716 12.0f, 9.0f, 12.0f, 1.0f
717 , 10.0f, 1.0f, 20.0f, 1.0f
718 , 1.0f, 1.0f, 99.0f, 1.0f
719 , 250.0f, 100.0f, 2000.0f, 50.0f
720 , 0.004f, 0.0f, 0.01f, 0.00001f
721 , 0.001f, 0.0f, 0.05f, 0.00001f
722 , 0.7f, 0.0f, 1.0f, 0.01f
723 , 50.0f, 1.0f, 300.0f, 1.0f
724 , 2.0f, 0.0f, 8.0f, 1.0f
725 , 2.0f, 0.0f, 8.0f, 1.0f
726 , 1.0f, 0.0f, 3.0f, 0.001f
727 , 1.0f, 0.0f, 3.0f, 0.001f
734 12.0f, 9.0f, 12.0f, 1.0f
735 , 10.0f, 1.0f, 20.0f, 1.0f
736 , 1.0f, 1.0f, 99.0f, 1.0f
737 , 250.0f, 100.0f, 2000.0f, 50.0f
738 , 0.004f, 0.0f, 0.01f, 0.00001f
739 , 0.001f, 0.0f, 0.05f, 0.00001f
740 , 0.7f, 0.0f, 1.0f, 0.01f
741 , 50.0f, 1.0f, 300.0f, 1.0f
742 , 2.0f, 0.0f, 8.0f, 1.0f
743 , 2.0f, 0.0f, 8.0f, 1.0f
744 , 1.0f, 0.0f, 3.0f, 0.001f
745 , 1.0f, 0.0f, 3.0f, 0.001f
752 12.0f, 9.0f, 12.0f, 1.0f
753 , 10.0f, 1.0f, 20.0f, 1.0f
754 , 8.0f, 1.0f, 10.0f, 1.0f
755 , 250.0f, 100.0f, 2000.0f, 50.0f
756 , 0.055f, 0.0f, 0.1f, 0.00001f
757 , 0.001f, 0.0f, 0.05f, 0.00001f
758 , 0.02f, 0.0f, 0.04f, 0.00001f
759 , 450.0f, 1.0f, 900.0f, 1.0f
760 , 2.0f, 0.0f, 4.0f, 1.0f
761 , 2.0f, 0.0f, 4.0f, 1.0f
762 , 0.25f, 0.0f, 2.0f, 0.001f
763 , 0.25f, 0.0f, 2.0f, 0.001f
770 12.0f, 9.0f, 12.0f, 1.0f
771 , 10.0f, 1.0f, 20.0f, 1.0f
772 , 3.0f, 1.0f, 10.0f, 0.01f
773 , 250.0f, 100.0f, 2000.0f, 50.0f
774 , 0.035f, 0.0f, 0.1f, 0.00001f
775 , 0.001f, 0.0f, 0.05f, 0.00001f
776 , 0.7f, 0.0f, 1.0f, 0.01f
777 , 9000.0f, 1.0f, 15000.0f, 1.0f
778 , 2.0f, 0.0f, 4.0f, 1.0f
779 , 2.0f, 0.0f, 4.0f, 1.0f
780 , 0.25f, 0.0f, 2.0f, 0.001f
781 , 0.25f, 0.0f, 2.0f, 0.001f
792 12.0f, 9.0f, 12.0f, 1.0f
793 , 1.0f, 1.0f, 20.0f, 1.0f
794 , 1.0f, 1.0f, 10.0f, 1.0f
795 , 250.0f, 100.0f, 2000.0f, 50.0f
796 , 0.003f, 0.0f, 0.01f, 0.00001f
797 , 0.001f, 0.0f, 0.05f, 0.00001f
798 , 0.7f, 0.0f, 1.0f, 0.01f
799 , 120.0f, 1.0f, 300.0f, 1.0f
800 , 2.0f, 0.0f, 4.0f, 1.0f
801 , 2.0f, 0.0f, 4.0f, 1.0f
802 , 0.25f, 0.0f, 2.0f, 0.001f
803 , 0.25f, 0.0f, 2.0f, 0.001f
810 12.0f, 9.0f, 12.0f, 1.0f
811 , 1.0f, 1.0f, 20.0f, 1.0f
812 , 1.0f, 1.0f, 99.0f, 1.0f
813 , 250.0f, 100.0f, 2000.0f, 50.0f
814 , 0.0035f, 0.0f, 0.01f, 0.00001f
815 , 0.001f, 0.0f, 0.05f, 0.00001f
816 , 0.7f, 0.0f, 1.0f, 0.01f
817 , 120.0f, 1.0f, 300.0f, 1.0f
818 , 2.0f, 0.0f, 8.0f, 1.0f
819 , 2.0f, 0.0f, 8.0f, 1.0f
820 , 1.0f, 0.0f, 3.0f, 0.001f
821 , 1.0f, 0.0f, 3.0f, 0.001f
828 12.0f, 9.0f, 12.0f, 1.0f
829 , 1.0f, 1.0f, 20.0f, 1.0f
830 , 1.0f, 1.0f, 99.0f, 1.0f
831 , 250.0f, 100.0f, 2000.0f, 50.0f
832 , 0.0035f, 0.0f, 0.01f, 0.00001f
833 , 0.001f, 0.0f, 0.05f, 0.00001f
834 , 0.7f, 0.0f, 1.0f, 0.01f
835 , 120.0f, 1.0f, 300.0f, 1.0f
836 , 2.0f, 0.0f, 8.0f, 1.0f
837 , 2.0f, 0.0f, 8.0f, 1.0f
838 , 1.0f, 0.0f, 3.0f, 0.001f
839 , 1.0f, 0.0f, 3.0f, 0.001f
846 12.0f, 9.0f, 12.0f, 1.0f
847 , 1.0f, 1.0f, 20.0f, 1.0f
848 , 1.0f, 1.0f, 10.0f, 1.0f
849 , 250.0f, 100.0f, 2000.0f, 50.0f
850 , 0.006f, 0.0f, 0.1f, 0.00001f
851 , 0.001f, 0.0f, 0.05f, 0.00001f
852 , 0.02f, 0.0f, 0.1f, 0.00001f
853 , 400.0f, 1.0f, 900.0f, 1.0f
854 , 2.0f, 0.0f, 4.0f, 1.0f
855 , 2.0f, 0.0f, 4.0f, 1.0f
856 , 0.25f, 0.0f, 2.0f, 0.001f
857 , 0.25f, 0.0f, 2.0f, 0.001f
864 12.0f, 9.0f, 12.0f, 1.0f
865 , 1.0f, 1.0f, 20.0f, 1.0f
866 , 1.0f, 1.0f, 10.0f, 0.01f
867 , 250.0f, 100.0f, 2000.0f, 50.0f
868 , 0.007f, 0.0f, 0.01f, 0.00001f
869 , 0.001f, 0.0f, 0.05f, 0.00001f
870 , 0.7f, 0.0f, 1.0f, 0.01f
871 , 8000.0f, 1.0f, 15000.0f, 1.0f
872 , 2.0f, 0.0f, 4.0f, 1.0f
873 , 2.0f, 0.0f, 4.0f, 1.0f
874 , 0.25f, 0.0f, 2.0f, 0.001f
875 , 0.25f, 0.0f, 2.0f, 0.001f
890 11.0f, 7.0f, 12.0f, 1.0f
891 , 1.0f, 1.0f, 20.0f, 1.0f
892 , 1.0f, 1.0f, 10.0f, 1.0f
893 , 550.0f, 100.0f, 2000.0f, 50.0f
894 , 0.0012f, 0.0f, 0.01f, 0.00001f
895 , 0.001f, 0.0f, 0.04f, 0.00001f
896 , 0.7f, 0.0f, 1.0f, 0.01f
897 , 200.0f, 1.0f, 400.0f, 1.0f
898 , 2.0f, 0.0f, 4.0f, 1.0f
899 , 2.0f, 0.0f, 4.0f, 1.0f
900 , 0.2f, 0.0f, 1.0f, 0.01f
901 , 0.2f, 0.0f, 1.0f, 0.01f
908 11.0f, 7.0f, 12.0f, 1.0f
909 , 1.0f, 1.0f, 20.0f, 1.0f
910 , 1.0f, 1.0f, 99.0f, 1.0f
911 , 550.0f, 100.0f, 2000.0f, 50.0f
912 , 0.0012f, 0.0f, 0.01f, 0.00001f
913 , 0.001f, 0.0f, 0.04f, 0.00001f
914 , 0.7f, 0.0f, 1.0f, 0.01f
915 , 200.0f, 1.0f, 400.0f, 1.0f
916 , 2.0f, 0.0f, 8.0f, 1.0f
917 , 2.0f, 0.0f, 8.0f, 1.0f
918 , 1.0f, 0.0f, 3.0f, 0.01f
919 , 1.0f, 0.0f, 3.0f, 0.01f
926 11.0f, 7.0f, 12.0f, 1.0f
927 , 1.0f, 1.0f, 20.0f, 1.0f
928 , 1.0f, 1.0f, 99.0f, 1.0f
929 , 550.0f, 100.0f, 2000.0f, 50.0f
930 , 0.0012f, 0.0f, 0.01f, 0.00001f
931 , 0.001f, 0.0f, 0.04f, 0.00001f
932 , 0.7f, 0.0f, 1.0f, 0.01f
933 , 200.0f, 1.0f, 400.0f, 1.0f
934 , 2.0f, 0.0f, 8.0f, 1.0f
935 , 2.0f, 0.0f, 8.0f, 1.0f
936 , 1.0f, 0.0f, 3.0f, 0.01f
937 , 1.0f, 0.0f, 3.0f, 0.01f
944 11.0f, 7.0f, 12.0f, 1.0f
945 , 1.0f, 1.0f, 20.0f, 1.0f
946 , 1.0f, 1.0f, 10.0f, 1.0f
947 , 550.0f, 100.0f, 2000.0f, 50.0f
948 , 0.004f, 0.0f, 0.01f, 0.00001f
949 , 0.001f, 0.0f, 0.04f, 0.00001f
950 , 0.02f, 0.0f, 0.04f, 0.00001f
951 , 2500.0f, 1.0f, 5000.0f, 1.0f
952 , 2.0f, 0.0f, 4.0f, 1.0f
953 , 2.0f, 0.0f, 4.0f, 1.0f
954 , 0.2f, 0.0f, 1.0f, 0.01f
955 , 0.2f, 0.0f, 1.0f, 0.01f
962 11.0f, 7.0f, 12.0f, 1.0f
963 , 1.0f, 1.0f, 20.0f, 1.0f
964 , 1.0f, 1.0f, 10.0f, 0.01f
965 , 550.0f, 100.0f, 2000.0f, 50.0f
966 , 0.004f, 0.0f, 0.01f, 0.00001f
967 , 0.001f, 0.0f, 0.04f, 0.00001f
968 , 0.7f, 0.0f, 1.0f, 0.01f
969 , 9500.0f, 1.0f, 15000.0f, 1.0f
970 , 2.0f, 0.0f, 4.0f, 1.0f
971 , 2.0f, 0.0f, 4.0f, 1.0f
972 , 0.2f, 0.0f, 1.0f, 0.01f
973 , 0.2f, 0.0f, 1.0f, 0.01f
984 11.0f, 7.0f, 12.0f, 1.0f
985 , 1.0f, 1.0f, 20.0f, 1.0f
986 , 1.0f, 1.0f, 10.0f, 1.0f
987 , 550.0f, 100.0f, 2000.0f, 50.0f
988 , 0.0012f, 0.0f, 0.01f, 0.00001f
989 , 0.001f, 0.0f, 0.04f, 0.00001f
990 , 0.7f, 0.0f, 1.0f, 0.01f
991 , 500.0f, 1.0f, 1000.0f, 1.0f
992 , 2.0f, 0.0f, 4.0f, 1.0f
993 , 2.0f, 0.0f, 4.0f, 1.0f
994 , 0.2f, 0.0f, 1.0f, 0.01f
995 , 0.2f, 0.0f, 1.0f, 0.01f
1002 11.0f, 7.0f, 12.0f, 1.0f
1003 , 1.0f, 1.0f, 20.0f, 1.0f
1004 , 1.0f, 1.0f, 99.0f, 1.0f
1005 , 550.0f, 100.0f, 2000.0f, 50.0f
1006 , 0.0012f, 0.0f, 0.01f, 0.00001f
1007 , 0.001f, 0.0f, 0.04f, 0.00001f
1008 , 0.7f, 0.0f, 1.0f, 0.01f
1009 , 200.0f, 1.0f, 400.0f, 1.0f
1010 , 2.0f, 0.0f, 8.0f, 1.0f
1011 , 2.0f, 0.0f, 8.0f, 1.0f
1012 , 1.0f, 0.0f, 3.0f, 0.01f
1013 , 1.0f, 0.0f, 3.0f, 0.01f
1020 11.0f, 7.0f, 12.0f, 1.0f
1021 , 1.0f, 1.0f, 20.0f, 1.0f
1022 , 1.0f, 1.0f, 99.0f, 1.0f
1023 , 550.0f, 100.0f, 2000.0f, 50.0f
1024 , 0.0012f, 0.0f, 0.01f, 0.00001f
1025 , 0.001f, 0.0f, 0.04f, 0.00001f
1026 , 0.7f, 0.0f, 1.0f, 0.01f
1027 , 200.0f, 1.0f, 400.0f, 1.0f
1028 , 2.0f, 0.0f, 8.0f, 1.0f
1029 , 2.0f, 0.0f, 8.0f, 1.0f
1030 , 1.0f, 0.0f, 3.0f, 0.01f
1031 , 1.0f, 0.0f, 3.0f, 0.01f
1038 11.0f, 7.0f, 12.0f, 1.0f
1039 , 1.0f, 1.0f, 20.0f, 1.0f
1040 , 1.0f, 1.0f, 10.0f, 1.0f
1041 , 550.0f, 100.0f, 2000.0f, 50.0f
1042 , 0.004f, 0.0f, 0.01f, 0.00001f
1043 , 0.001f, 0.0f, 0.04f, 0.00001f
1044 , 0.02f, 0.0f, 0.04f, 0.00001f
1045 , 2500.0f, 1.0f, 5000.0f, 1.0f
1046 , 2.0f, 0.0f, 4.0f, 1.0f
1047 , 2.0f, 0.0f, 4.0f, 1.0f
1048 , 0.2f, 0.0f, 1.0f, 0.01f
1049 , 0.2f, 0.0f, 1.0f, 0.01f
1056 11.0f, 7.0f, 12.0f, 1.0f
1057 , 1.0f, 1.0f, 20.0f, 1.0f
1058 , 1.0f, 1.0f, 10.0f, 0.01f
1059 , 550.0f, 100.0f, 2000.0f, 50.0f
1060 , 0.004f, 0.0f, 0.01f, 0.00001f
1061 , 0.001f, 0.0f, 0.04f, 0.00001f
1062 , 0.7f, 0.0f, 1.0f, 0.01f
1063 , 9500.0f, 1.0f, 15000.0f, 1.0f
1064 , 2.0f, 0.0f, 4.0f, 1.0f
1065 , 2.0f, 0.0f, 4.0f, 1.0f
1066 , 0.2f, 0.0f, 1.0f, 0.01f
1067 , 0.2f, 0.0f, 1.0f, 0.01f
1078 bx::memCopy(sm_settings_, smSettings,
sizeof(smSettings));
1149 if(!l.casts_shadows)
1155 bool recreateTextures =
false;
1156 recreateTextures |= !valid_;
1174 auto last_settings = settings_;
1177 settings_.
m_smImpl = convert(l.shadow_params.type);
1178 settings_.
m_depthImpl = convert(l.shadow_params.depth);
1190 settings_.
m_stencilPack = l.point_shadow_params.stencil_pack;
1191 settings_.
m_fovXAdjust = l.point_shadow_params.fov_x_adjust;
1192 settings_.
m_fovYAdjust = l.point_shadow_params.fov_y_adjust;
1197 settings_.
m_numSplits = l.directional_shadow_params.num_splits;
1198 settings_.
m_stabilize = l.directional_shadow_params.stabilize;
1203#define SET_CLAMPED_VAL(x, val) x = val
1208 SET_CLAMPED_VAL(currentSmSettings->m_sizePwrTwo, convert(l.shadow_params.resolution));
1209 SET_CLAMPED_VAL(currentSmSettings->m_near, l.shadow_params.near_plane);
1211 SET_CLAMPED_VAL(currentSmSettings->m_normalOffset, l.shadow_params.normal_bias);
1213 switch(l.shadow_params.type)
1216 currentSmSettings->
m_doBlur =
false;
1222 currentSmSettings->
m_doBlur =
false;
1223 SET_CLAMPED_VAL(currentSmSettings->m_xOffset, l.shadow_params.pcf.x_offset);
1224 SET_CLAMPED_VAL(currentSmSettings->m_yOffset, l.shadow_params.pcf.y_offset);
1227 currentSmSettings->
m_doBlur =
false;
1228 SET_CLAMPED_VAL(currentSmSettings->m_xOffset, l.shadow_params.pcss.penumbra_x_offset);
1229 SET_CLAMPED_VAL(currentSmSettings->m_yOffset, l.shadow_params.pcss.penumbra_y_offset);
1232 currentSmSettings->
m_doBlur = l.shadow_params.vsm.do_blur;
1233 SET_CLAMPED_VAL(currentSmSettings->m_customParam0, l.shadow_params.vsm.min_variance);
1234 SET_CLAMPED_VAL(currentSmSettings->m_customParam1, l.shadow_params.vsm.depth_multiplier);
1235 SET_CLAMPED_VAL(currentSmSettings->m_xOffset, l.shadow_params.vsm.blur_x_offset);
1236 SET_CLAMPED_VAL(currentSmSettings->m_yOffset, l.shadow_params.vsm.blur_y_offset);
1239 currentSmSettings->
m_doBlur = l.shadow_params.esm.do_blur;
1240 SET_CLAMPED_VAL(currentSmSettings->m_customParam0, l.shadow_params.esm.hardness);
1241 SET_CLAMPED_VAL(currentSmSettings->m_customParam1, l.shadow_params.esm.depth_multiplier);
1242 SET_CLAMPED_VAL(currentSmSettings->m_xOffset, l.shadow_params.esm.blur_x_offset);
1243 SET_CLAMPED_VAL(currentSmSettings->m_yOffset, l.shadow_params.esm.blur_y_offset);
1268 uint16_t shadowMapSize = 1 << uint32_t(currentSmSettings->m_sizePwrTwo);
1269 recreateTextures |= current_shadow_map_size_ != shadowMapSize;
1270 recreateTextures |= last_settings.m_smImpl != settings_.
m_smImpl;
1271 recreateTextures |= last_settings.m_numSplits != settings_.
m_numSplits;
1272 recreateTextures |= last_settings.m_lightType != settings_.
m_lightType;
1274 if(recreateTextures)
1276 current_shadow_map_size_ = shadowMapSize;
1278 if(bgfx::isValid(rt_shadow_map_[0]))
1280 bgfx::destroy(rt_shadow_map_[0]);
1281 rt_shadow_map_[0] = {bgfx::kInvalidHandle};
1285 bgfx::TextureHandle fbtextures[] = {
1286 bgfx::createTexture2D(current_shadow_map_size_,
1287 current_shadow_map_size_,
1290 bgfx::TextureFormat::BGRA8,
1292 bgfx::createTexture2D(current_shadow_map_size_,
1293 current_shadow_map_size_,
1296 bgfx::TextureFormat::D24S8,
1299 bgfx::Attachment attachments[2];
1300 attachments[0].init(fbtextures[0], bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_AUTO_GEN_MIPS);
1301 attachments[1].init(fbtextures[1], bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_NONE);
1303 rt_shadow_map_[0] = bgfx::createFrameBuffer(BX_COUNTOF(attachments), attachments,
true);
1310 if(bgfx::isValid(rt_shadow_map_[ii]))
1312 bgfx::destroy(rt_shadow_map_[ii]);
1313 rt_shadow_map_[ii] = {bgfx::kInvalidHandle};
1318 bgfx::TextureHandle fbtextures[] = {
1319 bgfx::createTexture2D(current_shadow_map_size_,
1320 current_shadow_map_size_,
1323 bgfx::TextureFormat::BGRA8,
1325 bgfx::createTexture2D(current_shadow_map_size_,
1326 current_shadow_map_size_,
1329 bgfx::TextureFormat::D24S8,
1333 bgfx::Attachment attachments[2];
1334 attachments[0].init(fbtextures[0], bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_AUTO_GEN_MIPS);
1335 attachments[1].init(fbtextures[1], bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_NONE);
1337 rt_shadow_map_[ii] = bgfx::createFrameBuffer(BX_COUNTOF(attachments), attachments,
true);
1342 if(bgfx::isValid(rt_blur_))
1344 bgfx::destroy(rt_blur_);
1345 rt_blur_ = {bgfx::kInvalidHandle};
1351 if(bVsmOrEsm && currentSmSettings->
m_doBlur)
1353 rt_blur_ = bgfx::createFrameBuffer(current_shadow_map_size_, current_shadow_map_size_, bgfx::TextureFormat::BGRA8);
1357 float currentShadowMapSizef = float(int16_t(current_shadow_map_size_));
1367 uniforms_.
m_XNum = currentSmSettings->m_xNum;
1368 uniforms_.
m_YNum = currentSmSettings->m_yNum;
1369 uniforms_.
m_XOffset = currentSmSettings->m_xOffset;
1370 uniforms_.
m_YOffset = currentSmSettings->m_yOffset;
1380 auto& lightView = light_view_;
1381 auto& lightProj = light_proj_;
1382 auto& lightFrustums = light_frustums_;
1389 const float aspect = 1.0f;
1393 currentSmSettings->m_near,
1394 currentSmSettings->m_far,
1404 const bx::Vec3 at = bx::add(bx::load<bx::Vec3>(point_light_.
m_position.
m_v),
1411 {bx::toRad(0.0f), bx::toRad(27.36780516f), bx::toRad(0.0f)},
1412 {bx::toRad(180.0f), bx::toRad(27.36780516f), bx::toRad(0.0f)},
1413 {bx::toRad(-90.0f), bx::toRad(-27.36780516f), bx::toRad(0.0f)},
1414 {bx::toRad(90.0f), bx::toRad(-27.36780516f), bx::toRad(0.0f)},
1419 const float fovx = 143.98570868f + 3.51f + settings_.
m_fovXAdjust;
1420 const float fovy = 125.26438968f + 9.85f + settings_.
m_fovYAdjust;
1421 const float aspect = bx::tan(bx::toRad(fovx * 0.5f)) / bx::tan(bx::toRad(fovy * 0.5f));
1426 currentSmSettings->m_near,
1427 currentSmSettings->m_far,
1443 const float fovx = 143.98570868f + 7.8f + settings_.
m_fovXAdjust;
1444 const float fovy = 125.26438968f + 3.0f + settings_.
m_fovYAdjust;
1445 const float aspect = bx::tan(bx::toRad(fovx * 0.5f)) / bx::tan(bx::toRad(fovy * 0.5f));
1450 currentSmSettings->m_near,
1451 currentSmSettings->m_far,
1464 mtxYawPitchRoll(mtxTmp, ypr[ii][0], ypr[ii][1], ypr[ii][2]);
1467 -bx::dot(bx::load<bx::Vec3>(point_light_.
m_position.
m_v), bx::load<bx::Vec3>(&mtxTmp[0])),
1468 -bx::dot(bx::load<bx::Vec3>(point_light_.
m_position.
m_v), bx::load<bx::Vec3>(&mtxTmp[4])),
1469 -bx::dot(bx::load<bx::Vec3>(point_light_.
m_position.
m_v), bx::load<bx::Vec3>(&mtxTmp[8])),
1472 bx::mtxTranspose(mtxYpr[ii], mtxTmp);
1474 bx::memCopy(lightView[ii], mtxYpr[ii], 12 *
sizeof(
float));
1475 lightView[ii][12] = tmp[0];
1476 lightView[ii][13] = tmp[1];
1477 lightView[ii][14] = tmp[2];
1478 lightView[ii][15] = 1.0f;
1487 const uint8_t maxNumSplits = 4;
1488 BX_ASSERT(maxNumSplits >= settings_.
m_numSplits,
"Error! Max num splits.");
1491 const float nearClip = currentSmSettings->m_near;
1492 const float farClip = currentSmSettings->m_far;
1493 const float clipRange = farClip - nearClip;
1496 float cascadeSplits[maxNumSplits];
1497 calculateCascadeSplits(cascadeSplits,
1504 const bx::Vec3 lightDir = bx::normalize(bx::Vec3{
1510 const bx::Vec3 lightEye = {0.0f, 0.0f, 0.0f};
1511 const bx::Vec3 lightAt = lightDir;
1514 bx::Vec3 upVec = {0.0f, 1.0f, 0.0f};
1515 if(bx::abs(bx::dot(lightDir, upVec)) > 0.99f)
1517 upVec = {0.0f, 0.0f, 1.0f};
1521 bx::mtxLookAt(lightView[0], lightEye, lightAt, upVec);
1525 bx::mtxOrtho(mtxProj,
1528 -currentSmSettings->m_far,
1529 currentSmSettings->m_far,
1537 const uint8_t numCorners = 8;
1538 float frustumCorners[maxNumSplits][numCorners][3];
1539 float lastSplitDist = 0.0f;
1541 for(uint8_t ii = 0; ii < settings_.
m_numSplits; ++ii)
1543 const float splitDist = cascadeSplits[ii];
1545 const float cascadeNear = nearClip + lastSplitDist * clipRange;
1546 const float cascadeFar = nearClip + splitDist * clipRange;
1552 const float camFovy = cam.
get_fov();
1554 const float projHeight = bx::tan(bx::toRad(camFovy) * 0.5f);
1555 const float projWidth = projHeight * camAspect;
1558 worldSpaceFrustumCorners((
float*)frustumCorners[ii], cascadeNear, cascadeFar, projWidth, projHeight, mtxViewInv);
1560 bx::Vec3 min = {9000.0f, 9000.0f, 9000.0f};
1561 bx::Vec3 max = {-9000.0f, -9000.0f, -9000.0f};
1562 float frustum_radius = 0.0f;
1565 bx::Vec3 frustumCenter = {0.0f, 0.0f, 0.0f};
1566 for(uint8_t jj = 0; jj < numCorners; ++jj)
1569 const bx::Vec3 worldCorner = bx::load<bx::Vec3>(&frustumCorners[ii][jj]);
1570 frustumCenter = bx::add(frustumCenter, worldCorner);
1572 frustumCenter = bx::mul(frustumCenter, 1.0f /
float(numCorners));
1576 const bx::Vec3 lightSpaceCenter = bx::mul(frustumCenter, lightView[0]);
1579 for(uint8_t jj = 0; jj < numCorners; ++jj)
1581 const bx::Vec3 xyz = bx::mul(bx::load<bx::Vec3>(frustumCorners[ii][jj]), lightView[0]);
1584 const float dx = xyz.x - lightSpaceCenter.x;
1585 const float dy = xyz.y - lightSpaceCenter.y;
1586 const float dz = xyz.z - lightSpaceCenter.z;
1587 const float distance = bx::sqrt(dx*dx + dy*dy + dz*dz);
1588 frustum_radius = bx::max(frustum_radius, distance);
1591 min = bx::min(min, xyz);
1592 max = bx::max(max, xyz);
1596 frustum_radius = bx::ceil(frustum_radius * 16.0f) / 16.0f;
1599 const bx::Vec3 minproj = bx::mulH(min, mtxProj);
1600 const bx::Vec3 maxproj = bx::mulH(max, mtxProj);
1603 float scalex = 1.0f / frustum_radius;
1604 float scaley = 1.0f / frustum_radius;
1609 const float quantizer = 64.0f;
1610 scalex = quantizer / bx::ceil(quantizer / scalex);
1611 scaley = quantizer / bx::ceil(quantizer / scaley);
1615 float offsetx = -scalex * (minproj.x + maxproj.x) * 0.5f;
1616 float offsety = -scaley * (minproj.y + maxproj.y) * 0.5f;
1621 float currentShadowMapSizef = float(int16_t(current_shadow_map_size_));
1622 const float halfSize = currentShadowMapSizef * 0.5f;
1625 offsetx = bx::round(offsetx * halfSize) / halfSize;
1626 offsety = bx::round(offsety * halfSize) / halfSize;
1631 bx::mtxIdentity(mtxCrop);
1632 mtxCrop[0] = scalex;
1633 mtxCrop[5] = scaley;
1634 mtxCrop[12] = offsetx;
1635 mtxCrop[13] = offsety;
1636 mtxCrop[14] = -lightSpaceCenter.z;
1639 bx::mtxMul(lightProj[ii], mtxCrop, mtxProj);
1641 lastSplitDist = splitDist;
1647 lightFrustums[0].update(math::make_mat4(lightView[0]),
1684 lightFrustums[0].update(math::make_mat4(lightView[0]), math::make_mat4(lightProj[0]), homogeneousDepth);
1685 lightFrustums[1].update(math::make_mat4(lightView[0]), math::make_mat4(lightProj[1]), homogeneousDepth);
1686 lightFrustums[2].update(math::make_mat4(lightView[0]), math::make_mat4(lightProj[2]), homogeneousDepth);
1687 lightFrustums[3].update(math::make_mat4(lightView[0]), math::make_mat4(lightProj[3]), homogeneousDepth);
1693 float mtxShadow[16];
1695 const float ymul = (originBottomLeft) ? 0.5f : -0.5f;
1699 const float mtxBias[16] =
1701 0.5f, 0.0f, 0.0f, 0.0f,
1702 0.0f, ymul, 0.0f, 0.0f,
1703 0.0f, 0.0f, 0.5f, 0.0f,
1704 0.5f, 0.5f, zadd, 1.0f,
1712 bx::mtxMul(mtxShadow, lightView[0], mtxTmp);
1716 const float s = (originBottomLeft) ? 1.0f : -1.0f;
1725 0.25f, 0.0f, 0.0f, 0.0f,
1726 0.0f, s*0.25f, 0.0f, 0.0f,
1727 0.0f, 0.0f, 0.5f, 0.0f,
1728 0.25f, 0.25f, zadd, 1.0f,
1731 0.25f, 0.0f, 0.0f, 0.0f,
1732 0.0f, s*0.25f, 0.0f, 0.0f,
1733 0.0f, 0.0f, 0.5f, 0.0f,
1734 0.75f, 0.25f, zadd, 1.0f,
1737 0.25f, 0.0f, 0.0f, 0.0f,
1738 0.0f, s*0.25f, 0.0f, 0.0f,
1739 0.0f, 0.0f, 0.5f, 0.0f,
1740 0.25f, 0.75f, zadd, 1.0f,
1743 0.25f, 0.0f, 0.0f, 0.0f,
1744 0.0f, s*0.25f, 0.0f, 0.0f,
1745 0.0f, 0.0f, 0.5f, 0.0f,
1746 0.75f, 0.75f, zadd, 1.0f,
1752 0.25f, 0.0f, 0.0f, 0.0f,
1753 0.0f, s*0.5f, 0.0f, 0.0f,
1754 0.0f, 0.0f, 0.5f, 0.0f,
1755 0.25f, 0.5f, zadd, 1.0f,
1758 0.25f, 0.0f, 0.0f, 0.0f,
1759 0.0f, s*0.5f, 0.0f, 0.0f,
1760 0.0f, 0.0f, 0.5f, 0.0f,
1761 0.75f, 0.5f, zadd, 1.0f,
1764 0.5f, 0.0f, 0.0f, 0.0f,
1765 0.0f, s*0.25f, 0.0f, 0.0f,
1766 0.0f, 0.0f, 0.5f, 0.0f,
1767 0.5f, 0.75f, zadd, 1.0f,
1770 0.5f, 0.0f, 0.0f, 0.0f,
1771 0.0f, s*0.25f, 0.0f, 0.0f,
1772 0.0f, 0.0f, 0.5f, 0.0f,
1773 0.5f, 0.25f, zadd, 1.0f,
1781 static const uint8_t cropBiasIndices[2][2][4] =
1797 uint8_t biasIndex = cropBiasIndices[settings_.
m_stencilPack][uint8_t(originBottomLeft)][ii];
1800 bx::mtxMul(mtxTmp, mtxYpr[ii], lightProj[projType]);
1801 bx::mtxMul(shadow_map_mtx_[ii],
1806 bx::mtxTranslate(mtxShadow
1815 for(uint8_t ii = 0; ii < settings_.
m_numSplits; ++ii)
1819 bx::mtxMul(mtxTmp, lightProj[ii], mtxBias);
1820 bx::mtxMul(shadow_map_mtx_[ii], lightView[0], mtxTmp);
1827 bx::mtxIdentity(tmp);
1829 bx::mtxMul(light_mtx_, tmp, mtxShadow);
1836 auto& lightView = light_view_;
1837 auto& lightProj = light_proj_;
1838 auto& lightFrustums = light_frustums_;
1843 float screenProj[16];
1844 float screenView[16];
1845 bx::mtxIdentity(screenView);
1847 bx::mtxOrtho(screenProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f,
gfx::get_caps()->homogeneousDepth);
1865 auto RENDERVIEW_SHADOWMAP_0_ID = shadowmap_pass_0.
id;
1866 auto RENDERVIEW_SHADOWMAP_1_ID = shadowmap_pass_1.
id;
1867 auto RENDERVIEW_SHADOWMAP_2_ID = shadowmap_pass_2.
id;
1868 auto RENDERVIEW_SHADOWMAP_3_ID = shadowmap_pass_3.
id;
1869 auto RENDERVIEW_SHADOWMAP_4_ID = shadowmap_pass_4.
id;
1870 auto RENDERVIEW_VBLUR_0_ID = shadowmap_vblur_pass_0.
id;
1871 auto RENDERVIEW_HBLUR_0_ID = shadowmap_hblur_pass_0.
id;
1872 auto RENDERVIEW_VBLUR_1_ID = shadowmap_vblur_pass_1.
id;
1873 auto RENDERVIEW_HBLUR_1_ID = shadowmap_hblur_pass_1.
id;
1874 auto RENDERVIEW_VBLUR_2_ID = shadowmap_vblur_pass_2.
id;
1875 auto RENDERVIEW_HBLUR_2_ID = shadowmap_hblur_pass_2.
id;
1876 auto RENDERVIEW_VBLUR_3_ID = shadowmap_vblur_pass_3.
id;
1877 auto RENDERVIEW_HBLUR_3_ID = shadowmap_hblur_pass_3.
id;
1888 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1889 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_1_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1890 bgfx::setViewRect(RENDERVIEW_VBLUR_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1891 bgfx::setViewRect(RENDERVIEW_HBLUR_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1893 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_0_ID, screenView, screenProj);
1894 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_1_ID, lightView[0], lightProj[
ProjType::Horizontal]);
1895 bgfx::setViewTransform(RENDERVIEW_VBLUR_0_ID, screenView, screenProj);
1896 bgfx::setViewTransform(RENDERVIEW_HBLUR_0_ID, screenView, screenProj);
1898 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_0_ID, rt_shadow_map_[0]);
1899 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_1_ID, rt_shadow_map_[0]);
1900 bgfx::setViewFrameBuffer(RENDERVIEW_VBLUR_0_ID, rt_blur_);
1901 bgfx::setViewFrameBuffer(RENDERVIEW_HBLUR_0_ID, rt_shadow_map_[0]);
1915 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1918 const uint16_t f = current_shadow_map_size_;
1919 const uint16_t h = current_shadow_map_size_ / 2;
1920 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_1_ID, 0, 0, f, h);
1921 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_2_ID, 0, h, f, h);
1922 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_3_ID, 0, 0, h, f);
1923 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_4_ID, h, 0, h, f);
1927 const uint16_t h = current_shadow_map_size_ / 2;
1928 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_1_ID, 0, 0, h, h);
1929 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_2_ID, h, 0, h, h);
1930 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_3_ID, 0, h, h, h);
1931 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_4_ID, h, h, h, h);
1933 bgfx::setViewRect(RENDERVIEW_VBLUR_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1934 bgfx::setViewRect(RENDERVIEW_HBLUR_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1936 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_0_ID, screenView, screenProj);
1937 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_1_ID,
1941 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_2_ID,
1947 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_3_ID,
1951 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_4_ID,
1957 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_3_ID,
1961 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_4_ID,
1965 bgfx::setViewTransform(RENDERVIEW_VBLUR_0_ID, screenView, screenProj);
1966 bgfx::setViewTransform(RENDERVIEW_HBLUR_0_ID, screenView, screenProj);
1968 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_0_ID, rt_shadow_map_[0]);
1969 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_1_ID, rt_shadow_map_[0]);
1970 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_2_ID, rt_shadow_map_[0]);
1971 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_3_ID, rt_shadow_map_[0]);
1972 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_4_ID, rt_shadow_map_[0]);
1973 bgfx::setViewFrameBuffer(RENDERVIEW_VBLUR_0_ID, rt_blur_);
1974 bgfx::setViewFrameBuffer(RENDERVIEW_HBLUR_0_ID, rt_shadow_map_[0]);
1993 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_1_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1994 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_2_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1995 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_3_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1996 bgfx::setViewRect(RENDERVIEW_SHADOWMAP_4_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1997 bgfx::setViewRect(RENDERVIEW_VBLUR_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1998 bgfx::setViewRect(RENDERVIEW_HBLUR_0_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
1999 bgfx::setViewRect(RENDERVIEW_VBLUR_1_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
2000 bgfx::setViewRect(RENDERVIEW_HBLUR_1_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
2001 bgfx::setViewRect(RENDERVIEW_VBLUR_2_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
2002 bgfx::setViewRect(RENDERVIEW_HBLUR_2_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
2003 bgfx::setViewRect(RENDERVIEW_VBLUR_3_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
2004 bgfx::setViewRect(RENDERVIEW_HBLUR_3_ID, 0, 0, current_shadow_map_size_, current_shadow_map_size_);
2007 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_1_ID, lightView[0], lightProj[0]);
2008 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_2_ID, lightView[0], lightProj[1]);
2009 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_3_ID, lightView[0], lightProj[2]);
2010 bgfx::setViewTransform(RENDERVIEW_SHADOWMAP_4_ID, lightView[0], lightProj[3]);
2012 bgfx::setViewTransform(RENDERVIEW_VBLUR_0_ID, screenView, screenProj);
2013 bgfx::setViewTransform(RENDERVIEW_HBLUR_0_ID, screenView, screenProj);
2014 bgfx::setViewTransform(RENDERVIEW_VBLUR_1_ID, screenView, screenProj);
2015 bgfx::setViewTransform(RENDERVIEW_HBLUR_1_ID, screenView, screenProj);
2016 bgfx::setViewTransform(RENDERVIEW_VBLUR_2_ID, screenView, screenProj);
2017 bgfx::setViewTransform(RENDERVIEW_HBLUR_2_ID, screenView, screenProj);
2018 bgfx::setViewTransform(RENDERVIEW_VBLUR_3_ID, screenView, screenProj);
2019 bgfx::setViewTransform(RENDERVIEW_HBLUR_3_ID, screenView, screenProj);
2021 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_1_ID, rt_shadow_map_[0]);
2022 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_2_ID, rt_shadow_map_[1]);
2023 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_3_ID, rt_shadow_map_[2]);
2024 bgfx::setViewFrameBuffer(RENDERVIEW_SHADOWMAP_4_ID, rt_shadow_map_[3]);
2025 bgfx::setViewFrameBuffer(RENDERVIEW_VBLUR_0_ID, rt_blur_);
2026 bgfx::setViewFrameBuffer(RENDERVIEW_HBLUR_0_ID, rt_shadow_map_[0]);
2027 bgfx::setViewFrameBuffer(RENDERVIEW_VBLUR_1_ID, rt_blur_);
2028 bgfx::setViewFrameBuffer(RENDERVIEW_HBLUR_1_ID, rt_shadow_map_[1]);
2029 bgfx::setViewFrameBuffer(RENDERVIEW_VBLUR_2_ID, rt_blur_);
2030 bgfx::setViewFrameBuffer(RENDERVIEW_HBLUR_2_ID, rt_shadow_map_[2]);
2031 bgfx::setViewFrameBuffer(RENDERVIEW_VBLUR_3_ID, rt_blur_);
2032 bgfx::setViewFrameBuffer(RENDERVIEW_HBLUR_3_ID, rt_shadow_map_[3]);
2038 : BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL;
2040 bgfx::setViewClear(RENDERVIEW_SHADOWMAP_0_ID,
2046 bgfx::touch(RENDERVIEW_SHADOWMAP_0_ID);
2048 const uint8_t flags1 =
2051 for(uint8_t ii = 0; ii < 4; ++ii)
2053 bgfx::setViewClear(RENDERVIEW_SHADOWMAP_1_ID + ii,
2059 bgfx::touch(RENDERVIEW_SHADOWMAP_1_ID + ii);
2070 bool anythingDrawn =
false;
2078 bgfx::TransientVertexBuffer vb;
2082 const float min = 0.0f;
2083 const float max = 1.0f;
2084 const float center = 0.5f;
2085 const float zz = 0.0f;
2087 vertex[0].
m_x = min;
2088 vertex[0].
m_y = min;
2091 vertex[1].
m_x = max;
2092 vertex[1].
m_y = min;
2103 vertex[4].
m_x = max;
2104 vertex[4].
m_y = max;
2107 vertex[5].
m_x = min;
2108 vertex[5].
m_y = max;
2112 bgfx::setStencil(BGFX_STENCIL_TEST_ALWAYS | BGFX_STENCIL_FUNC_REF(1) | BGFX_STENCIL_FUNC_RMASK(0xff) |
2113 BGFX_STENCIL_OP_FAIL_S_REPLACE | BGFX_STENCIL_OP_FAIL_Z_REPLACE |
2114 BGFX_STENCIL_OP_PASS_Z_REPLACE);
2115 bgfx::setVertexBuffer(0, &vb);
2118 bgfx::submit(RENDERVIEW_SHADOWMAP_0_ID, programs_.
m_black->native_handle());
2124 render_scene_into_shadowmap(RENDERVIEW_SHADOWMAP_1_ID, models, lightFrustums, currentSmSettings, &cam, stats);
2133 if(bVsmOrEsm && currentSmSettings->
m_doBlur)
2135 bgfx::setTexture(4, shadow_map_[0], bgfx::getTexture(rt_shadow_map_[0]));
2136 bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
2137 screenSpaceQuad(originBottomLeft);
2138 programs_.
m_vBlur[depthType]->begin();
2139 bgfx::submit(RENDERVIEW_VBLUR_0_ID, programs_.
m_vBlur[depthType]->native_handle());
2140 programs_.
m_vBlur[depthType]->end();
2142 bgfx::setTexture(4, shadow_map_[0], bgfx::getTexture(rt_blur_));
2143 bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
2144 screenSpaceQuad(originBottomLeft);
2145 programs_.
m_hBlur[depthType]->begin();
2146 bgfx::submit(RENDERVIEW_HBLUR_0_ID, programs_.
m_hBlur[depthType]->native_handle());
2147 programs_.
m_hBlur[depthType]->end();
2151 for(uint8_t ii = 1, jj = 2; ii < settings_.
m_numSplits; ++ii, jj += 2)
2153 const uint8_t viewId = RENDERVIEW_VBLUR_0_ID + jj;
2155 bgfx::setTexture(4, shadow_map_[0], bgfx::getTexture(rt_shadow_map_[ii]));
2156 bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
2157 screenSpaceQuad(originBottomLeft);
2158 bgfx::submit(viewId, programs_.
m_vBlur[depthType]->native_handle());
2160 bgfx::setTexture(4, shadow_map_[0], bgfx::getTexture(rt_blur_));
2161 bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
2162 screenSpaceQuad(originBottomLeft);
2163 bgfx::submit(viewId + 1, programs_.
m_hBlur[depthType]->native_handle());