forked from raphaelmenges/MolecularDynamicsVisualization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSurfaceDynamicsVisualization.cpp
More file actions
3238 lines (2782 loc) · 143 KB
/
SurfaceDynamicsVisualization.cpp
File metadata and controls
3238 lines (2782 loc) · 143 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//============================================================================
// Distributed under the MIT License. Author: Raphael Menges
//============================================================================
#include "SurfaceDynamicsVisualization.h"
#include "Utils/OrbitCamera.h"
#include "ShaderTools/Renderer.h"
#include "Molecule/MDtrajLoader/MdTraj/MdTrajWrapper.h"
#include "Molecule/MDtrajLoader/Data/Protein.h"
#include "SimpleLoader.h"
#include "imgui/imgui.h"
#include "imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h"
#include "text-csv/include/text/csv/ostream.hpp"
#include <glm/gtx/component_wise.hpp>
#include <sstream>
#include <iomanip>
// stb_image wants those defines
#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"
// Namespace for text-csv
namespace csv = ::text::csv;
// ### Class implementation ###
SurfaceDynamicsVisualization::SurfaceDynamicsVisualization(std::string filepathPDB, std::string filepathXTC)
{
Logger::instance().print("Welcome to Surface Dynamics Visualization!");
// # Setup members
mCameraDeltaRotation = glm::vec2(0,0);
mCameraRotationSmoothTime = 1.f;
mLightDirection = glm::normalize(glm::vec3(-0.5, -0.75, -0.3));
mWindowWidth = mInitialWindowWidth;
mWindowHeight = mInitialWindowHeight;
mPDBFilepath = filepathPDB;
mXTCFilepath = filepathXTC;
// # Setup paths
resetPath(mGlobalAnalysisFilePath, "/GlobalAnalysis.csv");
resetPath(mGroupAnalysisFilePath, "/GroupAnalysis.csv");
resetPath(mSurfaceIndicesFilePath, "/SurfaceIndices.csv");
resetPath(mAminoAcidAnalysisAccumulatedFilePath, "/AminoAcidAnalysis-accumulated.csv");
resetPath(mAminoAcidAnalysisAvgLayersFilePath, "/AminoAcidAnalysis-avgLayers.csv");
resetPath(mAminoAcidAnalysisInverseAvgLayersFilePath, "/AminoAcidAnalysis-inverseAvgLayer.csv");
resetPath(mAminoAcidAnalysisAvgLayersDeltaFilePath, "/AminoAcidAnalysis-avgLayersDelta.csv");
resetPath(mAminoAcidAnalysisInverseAvgLayersDeltaFilePath, "/AminoAcidAnalysis-inverseAverageLayersDelta.csv");
// Create window (which initializes OpenGL)
Logger::instance().print("Create window..");
mpWindow = generateWindow(mWindowTitle, mWindowWidth, mWindowHeight);
Logger::instance().print("..done");
// Init ImGui and load font
Logger::instance().print("Load GUI..");
ImGui_ImplGlfwGL3_Init(mpWindow, true);
ImGuiIO& io = ImGui::GetIO();
std::string fontpath = std::string(RESOURCES_PATH) + "/fonts/dejavu-fonts-ttf-2.35/ttf/DejaVuSans.ttf";
io.Fonts->AddFontFromFileTTF(fontpath.c_str(), 14);
// Add icons to font atlas
ImFontConfig config;
config.MergeMode = true;
static const ImWchar ranges[] =
{
0x25B8, 0x25B8, // play
0x5f0, 0x5f0, // pause
0x2794, 0x2794, // right arrow
0x25cb, 0x25cb, // circle
0x212b, 0x212b, // angstrom
0x2023, 0x2023, // triangle bullet
0
}; // has to be static to be available during run
io.Fonts->AddFontFromFileTTF(fontpath.c_str(), 16, &config, ranges);
Logger::instance().print("..done");
// Clear color (has to be zero for sake of framebuffers)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// # Callbacks after ImGui
// Register keyboard callback
std::function<void(int, int, int, int)> kC = [&](int k, int s, int a, int m)
{
// Check whether ImGui is handling this
ImGuiIO& io = ImGui::GetIO();
if(io.WantCaptureKeyboard) { return; }
this->keyCallback(k, s, a, m);
};
setKeyCallback(mpWindow, kC);
// Register mouse button callback
std::function<void(int, int, int)> kB = [&](int b, int a, int m)
{
// Check whether ImGui is handling this
ImGuiIO& io = ImGui::GetIO();
if(io.WantCaptureMouse) { return; }
this->mouseButtonCallback(b, a, m);
};
setMouseButtonCallback(mpWindow, kB);
// Register scroll callback
std::function<void(double, double)> kS = [&](double x, double y)
{
// Check whether ImGui is handling this
ImGuiIO& io = ImGui::GetIO();
if(io.WantCaptureMouse) { return; }
this->scrollCallback(x,y);
};
setScrollCallback(mpWindow, kS);
// # Load molecule
// Loading molecule
Logger::instance().print("Import molecule..");
MdTrajWrapper mdwrap;
std::vector<std::string> paths;
paths.push_back(mPDBFilepath);
if(!mXTCFilepath.empty()) { paths.push_back(mXTCFilepath); }
std::unique_ptr<Protein> upProtein = std::move(mdwrap.load(paths));
mupGPUProtein = std::unique_ptr<GPUProtein>(new GPUProtein(upProtein.get()));
Logger::instance().print("..done");
// # Prepare framebuffers for rendering
Logger::instance().print("Create framebuffer..");
mupMoleculeFramebuffer = std::unique_ptr<Framebuffer>(new Framebuffer(mWindowWidth, mWindowHeight, mSuperSampling));
mupMoleculeFramebuffer->bind();
mupMoleculeFramebuffer->addAttachment(Framebuffer::ColorFormat::RGBA); // color
mupMoleculeFramebuffer->addAttachment(Framebuffer::ColorFormat::RGB); // picking index
mupMoleculeFramebuffer->unbind();
mupSelectedAtomFramebuffer = std::unique_ptr<Framebuffer>(new Framebuffer(mWindowWidth, mWindowHeight, mSuperSampling));
mupSelectedAtomFramebuffer->bind();
mupSelectedAtomFramebuffer->addAttachment(Framebuffer::ColorFormat::RGBA); // color
mupSelectedAtomFramebuffer->unbind();
mupOverlayFramebuffer = std::unique_ptr<Framebuffer>(new Framebuffer(mWindowWidth, mWindowHeight));
mupOverlayFramebuffer->bind();
mupOverlayFramebuffer->addAttachment(Framebuffer::ColorFormat::RGBA);
mupOverlayFramebuffer->unbind();
Logger::instance().print("..done");
// # Prepare background cubemaps
Logger::instance().print("Load cubemaps..");
mScientificCubemapTexture = createCubemapTexture(
std::string(RESOURCES_PATH) + "/cubemaps/Scientific/posx.png",
std::string(RESOURCES_PATH) + "/cubemaps/Scientific/negx.png",
std::string(RESOURCES_PATH) + "/cubemaps/Scientific/posy.png",
std::string(RESOURCES_PATH) + "/cubemaps/Scientific/negy.png",
std::string(RESOURCES_PATH) + "/cubemaps/Scientific/posz.png",
std::string(RESOURCES_PATH) + "/cubemaps/Scientific/negz.png");
mCVCubemapTexture = createCubemapTexture(
std::string(RESOURCES_PATH) + "/cubemaps/CV/posx.png",
std::string(RESOURCES_PATH) + "/cubemaps/CV/negx.png",
std::string(RESOURCES_PATH) + "/cubemaps/CV/posy.png",
std::string(RESOURCES_PATH) + "/cubemaps/CV/negy.png",
std::string(RESOURCES_PATH) + "/cubemaps/CV/posz.png",
std::string(RESOURCES_PATH) + "/cubemaps/CV/negz.png");
mBeachCubemapTexture = createCubemapTexture(
std::string(RESOURCES_PATH) + "/cubemaps/NissiBeach/posx.jpg",
std::string(RESOURCES_PATH) + "/cubemaps/NissiBeach/negx.jpg",
std::string(RESOURCES_PATH) + "/cubemaps/NissiBeach/posy.jpg",
std::string(RESOURCES_PATH) + "/cubemaps/NissiBeach/negy.jpg",
std::string(RESOURCES_PATH) + "/cubemaps/NissiBeach/posz.jpg",
std::string(RESOURCES_PATH) + "/cubemaps/NissiBeach/negz.jpg");
mWhiteCubemapTexture = createCubemapTexture(
std::string(RESOURCES_PATH) + "/textures/white.png",
std::string(RESOURCES_PATH) + "/textures/white.png",
std::string(RESOURCES_PATH) + "/textures/white.png",
std::string(RESOURCES_PATH) + "/textures/white.png",
std::string(RESOURCES_PATH) + "/textures/white.png",
std::string(RESOURCES_PATH) + "/textures/white.png");
Logger::instance().print("..done");
// # Create camera
Logger::instance().print("Create camera..");
glm::vec3 cameraCenter = (mupGPUProtein->getMinCoordinates() + mupGPUProtein->getMaxCoordinates()) / 2.f;
glm::vec3 maxAbsCoordinates(
glm::max(glm::abs(mupGPUProtein->getMinCoordinates().x), glm::abs(mupGPUProtein->getMaxCoordinates().x)),
glm::max(glm::abs(mupGPUProtein->getMinCoordinates().y), glm::abs(mupGPUProtein->getMaxCoordinates().y)),
glm::max(glm::abs(mupGPUProtein->getMinCoordinates().z), glm::abs(mupGPUProtein->getMaxCoordinates().z)) );
float cameraRadius = glm::compMax(maxAbsCoordinates - cameraCenter);
mupCamera = std::unique_ptr<OrbitCamera>(
new OrbitCamera(
cameraCenter,
mCameraDefaultAlpha,
mCameraDefaultBeta,
2.f * cameraRadius,
cameraRadius / 2.f,
8.f * cameraRadius,
45.f,
0.1f));
Logger::instance().print("..done");
// # Surface extraction
Logger::instance().print("Prepare surface extraction..");
// Construct GPUSurfaceExtraction object after OpenGL has been initialized
mupGPUSurfaceExtraction = std::unique_ptr<GPUSurfaceExtraction>(new GPUSurfaceExtraction);
Logger::instance().print("..done");
// # Analysis
Logger::instance().print("Prepare analysis..");
// Create path for analysis group
mupPath = std::unique_ptr<Path>(new Path());
// Group for highlighting
mupGroupIndicators = std::unique_ptr<GPUBuffer<GLfloat> >(new GPUBuffer<GLfloat>);
mupGroupIndicators->fill(std::vector<GLfloat>(mupGPUProtein->getAtomCount(), 0.f), GL_DYNAMIC_DRAW); // create buffer with zeros for startup since nothing is highlighted
// Hull samples
mupHullSamples = std::unique_ptr<GPUHullSamples>(new GPUHullSamples());
// Create empty outline atoms indices after OpenGL initialization
mupOutlineAtomIndices = std::unique_ptr<GPUTextureBuffer>(new GPUTextureBuffer(0)); // create empty outline atom indices buffer
Logger::instance().print("..done");
// # Ascension
Logger::instance().print("Prepare ascension..");
// Ascension
mupAscension = std::unique_ptr<GPUBuffer<GLfloat> >(new GPUBuffer<GLfloat>);
Logger::instance().print("..done");
// # Validation
Logger::instance().print("Prepare validation..");
// Prepare validation of the surface
mupSurfaceValidation = std::unique_ptr<SurfaceValidation>(new SurfaceValidation());
Logger::instance().print("..done");
// # Group rendering texture and semaphore
Logger::instance().print("Prepare group rendering..");
mupGroupRenderingTexture = std::unique_ptr<GPURenderTexture>(
new GPURenderTexture(
mupMoleculeFramebuffer->getWidth(),
mupMoleculeFramebuffer->getHeight(),
GPURenderTexture::Type::RGBA32F));
std::vector<GLuint> emptyDataSemaphore(mupMoleculeFramebuffer->getWidth() * mupMoleculeFramebuffer->getHeight(), 0.f);
mupGroupRenderingSemaphore = std::unique_ptr<GPUTextureBuffer>(new GPUTextureBuffer(emptyDataSemaphore));
Logger::instance().print("..done");
// # Prepare residue proximity rendering
Logger::instance().print("Prepare residue proximity rendering..");
mupKBufferTexture = std::unique_ptr<GPURenderTexture>(
new GPURenderTexture(
mupMoleculeFramebuffer->getWidth(),
mupMoleculeFramebuffer->getHeight(),
GPURenderTexture::Type::RG32F,
mKBufferLayerCount));
mupKBufferCounter = std::unique_ptr<GPURenderTexture>(
new GPURenderTexture(
mupMoleculeFramebuffer->getWidth(),
mupMoleculeFramebuffer->getHeight(),
GPURenderTexture::Type::R32UI));
mupLayersDeltaBuffer = std::unique_ptr<GPUBuffer<GLfloat> >(new GPUBuffer<GLfloat>());
Logger::instance().print("..done");
// # Ascension helper texture
Logger::instance().print("Prepare ascension helper..");
glGenTextures(1, &mAscensionHelperTexture);
glBindTexture(GL_TEXTURE_2D, mAscensionHelperTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Load image from disk
int channelCount;
unsigned char* pData = stbi_load(std::string(std::string(RESOURCES_PATH) + "/surfaceDynamics/AscensionHelper.png").c_str(), &mAscensionHelperWidth, &mAscensionHelperHeight, &channelCount, 0);
// Set texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mAscensionHelperWidth, mAscensionHelperHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pData);
// Delete raw image data
stbi_image_free(pData);
glBindTexture(GL_TEXTURE_2D, 0);
Logger::instance().print("..done");
// # Other
// Set endframe in GUI to maximum number
mEndFrame = mupGPUProtein->getFrameCount() - 1;
}
SurfaceDynamicsVisualization::~SurfaceDynamicsVisualization()
{
Logger::instance().print("Clean up..");
// Delete cubemaps
glDeleteTextures(1, &mScientificCubemapTexture);
glDeleteTextures(1, &mCVCubemapTexture);
glDeleteTextures(1, &mBeachCubemapTexture);
glDeleteTextures(1, &mWhiteCubemapTexture);
// Delete ascension helper texture
glDeleteTextures(1, &mAscensionHelperTexture);
Logger::instance().print("..done");
Logger::instance().print("Goodbye!");
}
void SurfaceDynamicsVisualization::renderLoop()
{
Logger::instance().print("Prepare rendering loop..");
// Setup OpenGL
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
// Cursor is saved for camera rotation smoothing
float prevCursorX, prevCursorY = 0;
// # Create gizmo to display coordinate system axes
GLuint axisGizmoVBO = 0;
GLuint axisGizmoVAO = 0;
ShaderProgram axisGizmoProgram("/SurfaceDynamicsVisualization/axis.vert", "/SurfaceDynamicsVisualization/axis.frag");
// Generate and bind vertex array object
glGenVertexArrays(1, &axisGizmoVAO);
glBindVertexArray(axisGizmoVAO);
// Fill vertex buffer with vertices
std::vector<glm::vec3> axisVertices;
axisVertices.push_back(glm::vec3(0,0,0));
axisVertices.push_back(glm::vec3(1,0,0));
glGenBuffers(1, &axisGizmoVBO);
glBindBuffer(GL_ARRAY_BUFFER, axisGizmoVBO);
glBufferData(GL_ARRAY_BUFFER, axisVertices.size() * sizeof(glm::vec3), axisVertices.data(), GL_STATIC_DRAW);
// Bind it to shader program
GLint posAttrib = glGetAttribLocation(axisGizmoProgram.getProgramHandle(), "position");
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
// Unbind everything
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
// # Prepare shader programs
// Shader programs for rendering the molecule
ShaderProgram hullProgram("/SurfaceDynamicsVisualization/hull.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/impostor.frag");
ShaderProgram ascensionProgram("/SurfaceDynamicsVisualization/ascension.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/impostor.frag");
ShaderProgram coloringProgram("/SurfaceDynamicsVisualization/coloring.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/impostor.frag");
ShaderProgram analysisProgram("/SurfaceDynamicsVisualization/analysis.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/impostor.frag");
ShaderProgram fallbackProgram("/SurfaceDynamicsVisualization/fallback.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/impostor.frag");
ShaderProgram selectionProgram("/SurfaceDynamicsVisualization/selection.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/impostor.frag");
ShaderProgram residueRSPPeelProgram("/SurfaceDynamicsVisualization/rsp-peel.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/rsp-peel.frag");
ShaderProgram residueRSPResolveProgram("/SurfaceDynamicsVisualization/screenfilling.vert", "/SurfaceDynamicsVisualization/screenfilling.geom", "/SurfaceDynamicsVisualization/rsp-resolve.frag");
// Shader program to mark surface atoms
ShaderProgram surfaceMarksProgram("/SurfaceDynamicsVisualization/point.vert", "/SurfaceDynamicsVisualization/point.geom", "/SurfaceDynamicsVisualization/point.frag");
// Shader program for screenfilling quad rendering
ShaderProgram screenFillingProgram("/SurfaceDynamicsVisualization/screenfilling.vert", "/SurfaceDynamicsVisualization/screenfilling.geom", "/SurfaceDynamicsVisualization/screenfilling.frag");
// Shader program for cubemap
ShaderProgram cubemapProgram("/SurfaceDynamicsVisualization/cubemap.vert", "/SurfaceDynamicsVisualization/cubemap.geom", "/SurfaceDynamicsVisualization/cubemap.frag");
// Shader program for outline rendering
ShaderProgram outlineProgram("/SurfaceDynamicsVisualization/hull.vert", "/SurfaceDynamicsVisualization/impostor.geom", "/SurfaceDynamicsVisualization/outline.frag");
Logger::instance().print("..done");
Logger::instance().print("Enter render loop..");
// Call render function of Rendering.h with lambda function
render(mpWindow, [&] (float deltaTime)
{
if(mFrameLogging) { Logger::instance().print("### New Frame ###"); }
// Time accumulation
mAccTime += deltaTime;
mAccTime = glm::mod(mAccTime, 60.f * 30.f); // reset time after 30 minutes. Otherwise float not precise enough
// Viewport size
glm::vec2 resolution = getResolution(mpWindow);
mWindowWidth = resolution.x;
mWindowHeight = resolution.y;
// # Update everything before drawing
// ### MOLECULE ANIMATION ##################################################################################
if(mFrameLogging) { Logger::instance().print("Update animations.."); }
// If playing, decide whether to switch to next frame of animation
if(mPlayAnimation)
{
// Time each frame of animation should be displayed
float duration = 1.f / (float)mPlayAnimationRate;
// Go as many frames in animation forward as necessary to catch the time
float dT = deltaTime;
if(dT > 0)
{
mFramePlayTime += deltaTime;
if(mFramePlayTime >= duration)
{
// Decrement dT by time which was to much for that animation frame
dT -= mFramePlayTime - duration;
// Reset frame play time
mFramePlayTime = 0;
// Next frame
int nextFrame = mFrame + 1;
// Cylce if enabled
if(mRepeatOnlyComputed && mComputedStartFrame >= 0 && mComputedEndFrame >= 0)
{
if(mRepeatAnimation && nextFrame > mComputedEndFrame)
{
nextFrame = mComputedStartFrame;
}
}
else
{
if(mRepeatAnimation && nextFrame > mEndFrame)
{
nextFrame = mStartFrame;
}
}
// Increment time (checks are done by method)
if(!setFrame(nextFrame))
{
mPlayAnimation = false;
}
}
}
}
if(mFrameLogging) { Logger::instance().print("..done"); }
// ### CAMERA UPDATE #######################################################################################
if(mFrameLogging) { Logger::instance().print("Update camera.."); }
// Calculate cursor movement
double cursorX, cursorY;
glfwGetCursorPos(mpWindow, &cursorX, &cursorY);
GLfloat cursorDeltaX = (float)cursorX - prevCursorX;
GLfloat cursorDeltaY = (float)cursorY - prevCursorY;
bool lockCursorPosition = false;
// Rotate camera
if(mRotateCamera)
{
mCameraDeltaRotation = 0.25f * glm::vec2(cursorDeltaX, cursorDeltaY); // just weighted down a little bit
mCameraRotationSmoothTime = 1.f;
lockCursorPosition = true;
}
else
{
mCameraRotationSmoothTime -= deltaTime / mCameraSmoothDuration;
mCameraRotationSmoothTime = glm::max(mCameraRotationSmoothTime, 0.f);
}
glm::vec2 cameraMovement = glm::lerp(glm::vec2(0), mCameraDeltaRotation, mCameraRotationSmoothTime);
mupCamera->setAlpha(mupCamera->getAlpha() + 0.25f * cameraMovement.x);
mupCamera->setBeta(mupCamera->getBeta() - 0.25f * cameraMovement.y);
// Move camera
if(mMoveCamera)
{
glm::vec3 a = glm::normalize(
glm::cross(
glm::vec3(0,1,0),
mupCamera->getDirection())); // use up vector for cross product
glm::vec3 b = glm::normalize(
glm::cross(
mupCamera->getDirection(),
a));
mupCamera->setCenter(
mupCamera->getCenter()
+ (deltaTime * mupCamera->getRadius() * 0.3f
* (((float)cursorDeltaX * a)
+ ((float)cursorDeltaY * b))));
lockCursorPosition = true;
}
// Update camera
mupCamera->update(mWindowWidth, mWindowHeight, mUsePerspectiveCamera);
// Remember about cursor position
if(lockCursorPosition)
{
glfwSetCursorPos(mpWindow, prevCursorX, prevCursorY);
}
else
{
prevCursorX = cursorX;
prevCursorY = cursorY;
}
if(mFrameLogging) { Logger::instance().print("..done"); }
// ### OVERLAY RENDERING ###################################################################################
if(mFrameLogging) { Logger::instance().print("Render overlay.."); }
// # Fill overlay framebuffer
mupOverlayFramebuffer->bind();
mupOverlayFramebuffer->resize(mWindowWidth, mWindowHeight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Only show analysis visualization when frame is computed
if(frameComputed())
{
// Get count of atoms which will get a outline (size of buffer can be used here because all elements are valid)
int outlineAtomCount = mupOutlineAtomIndices->getSize();
if(mRenderOutline && (outlineAtomCount > 0))
{
// Bind buffers of radii and trajectory for rendering
mupGPUProtein->bind(0, 1);
// Slot 2 and 3 are not filled since GroupIndicatorBuffer and semaphore is not necessary
// Bind ascension
mupAscension->bind(5);
// Bind texture buffer with input atoms
mupOutlineAtomIndices->bindAsImage(6, GPUAccess::READ_ONLY);
// Probe radius
float probeRadius = mRenderWithProbeRadius ? mComputedProbeRadius : 0.f;
// Enable stencil test
glEnable(GL_STENCIL_TEST);
// Set up shader for outline drawing
outlineProgram.use();
outlineProgram.update("view", mupCamera->getViewMatrix());
outlineProgram.update("projection", mupCamera->getProjectionMatrix());
outlineProgram.update("frame", mFrame);
outlineProgram.update("atomCount", mupGPUProtein->getAtomCount());
outlineProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
outlineProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
outlineProgram.update("frameCount", mupGPUProtein->getFrameCount());
outlineProgram.update("outlineColor", mOutlineColor);
outlineProgram.update("localFrame", mFrame - mComputedStartFrame);
outlineProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
// Create stencil
glStencilFunc(GL_ALWAYS, 1, 0xFF); // set reference value for new stencil values
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); // use reference when stencil and depth test successful
glStencilMask(0xFF); // write to stencil buffer
glClear(GL_STENCIL_BUFFER_BIT); // clear stencil buffer (0 by default)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // disable to write color
glDepthMask(GL_FALSE); // disable to write depth
outlineProgram.update("probeRadius", probeRadius);
glDrawArrays(GL_POINTS, 0, outlineAtomCount);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // enable to write color
glDepthMask(GL_TRUE); // enable to write depth
// Draw outline
glStencilFunc(GL_NOTEQUAL, 1, 0xFF); // pass test if stencil at that pixel is not eqaul one
glStencilMask(0x00); // do not write to stencil buffer
outlineProgram.update("probeRadius", probeRadius + mOutlineWidth); // just add outline radius to probe radius
glDrawArrays(GL_POINTS, 0, outlineAtomCount);
// Disable stencil test
glDisable(GL_STENCIL_TEST);
}
// Render point inside of surface atoms for marking
if(mMarkSurfaceAtoms)
{
// Bind protein
mupGPUProtein->bind(0, 1);
// Bind surface indices
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindSurfaceIndices(mLayer, 2);
// Setup shader
glPointSize(mSurfaceMarkPointSize);
surfaceMarksProgram.use();
surfaceMarksProgram.update("view", mupCamera->getViewMatrix());
surfaceMarksProgram.update("projection", mupCamera->getProjectionMatrix());
surfaceMarksProgram.update("clippingPlane", mClippingPlane);
surfaceMarksProgram.update("frame", mFrame);
surfaceMarksProgram.update("atomCount", mupGPUProtein->getAtomCount());
surfaceMarksProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
surfaceMarksProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
surfaceMarksProgram.update("frameCount", mupGPUProtein->getFrameCount());
surfaceMarksProgram.update("color", glm::vec4(mSurfaceAtomColor, 1.f));
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfSurfaceAtoms(mLayer));
}
// Hull samples
if(mRenderHullSamples)
{
mupHullSamples->drawSamples(
mFrame,
mSamplePointSize,
mInternalHullSampleColor,
mSurfaceHullSampleColor,
mupCamera->getViewMatrix(),
mupCamera->getProjectionMatrix(),
mClippingPlane);
}
// Drawing of path (does not care for depth)
if(mShowPath)
{
mupPath->draw(
mFrame,
mPathFrameRadius,
mupCamera->getViewMatrix(),
mupCamera->getProjectionMatrix(),
mPastPathColor,
mFuturePathColor,
mPathPointSize);
}
}
// Drawing of surface validation before molecules, so sample points at same z coordinate as impostor are in front
if(mShowValidationSamples)
{
mupSurfaceValidation->drawSamples(
mSamplePointSize,
mInternalValidationSampleColor,
mSurfaceValidationSampleColor,
mupCamera->getViewMatrix(),
mupCamera->getProjectionMatrix(),
mClippingPlane,
mShowInternalSamples,
mShowSurfaceSamples);
}
// Drawing of coordinates system axes
if(mShowAxesGizmo)
{
glDisable(GL_DEPTH_TEST);
glBindVertexArray(axisGizmoVAO);
// General shader setup
axisGizmoProgram.use();
axisGizmoProgram.update("view", mupCamera->getViewMatrix());
axisGizmoProgram.update("projection", mupCamera->getProjectionMatrix());
// X axis
glm::mat4 axisModelMatrix = glm::translate(glm::mat4(1.f), glm::vec3(0,0,0));
axisGizmoProgram.update("model", axisModelMatrix);
axisGizmoProgram.update("color", glm::vec3(1.f, 0.f, 0.f));
glDrawArrays(GL_LINES, 0, axisVertices.size());
// Y axis
axisModelMatrix = glm::translate(glm::mat4(1.f), glm::vec3(0,0,0));
axisModelMatrix = glm::rotate(axisModelMatrix, glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
axisGizmoProgram.update("model", axisModelMatrix);
axisGizmoProgram.update("color", glm::vec3(0.f, 1.f, 0.f));
glDrawArrays(GL_LINES, 0, axisVertices.size());
// Z axis
axisModelMatrix = glm::translate(glm::mat4(1.f), glm::vec3(0,0,0));
axisModelMatrix = glm::rotate(axisModelMatrix, glm::radians(270.0f), glm::vec3(0.0f, 1.0f, 0.0f));
axisGizmoProgram.update("model", axisModelMatrix);
axisGizmoProgram.update("color", glm::vec3(0.f, 0.f, 1.f));
glDrawArrays(GL_LINES, 0, axisVertices.size());
glBindVertexArray(0);
glEnable(GL_DEPTH_TEST);
}
// Unbind framebuffer for overlay
mupOverlayFramebuffer->unbind();
if(mFrameLogging) { Logger::instance().print("..done"); }
// ### MOLECULE RENDERING ##################################################################################
if(mFrameLogging) { Logger::instance().print("Render molecule.."); }
// # Fill molecule framebuffer
mupMoleculeFramebuffer->bind();
bool wasResized = mupMoleculeFramebuffer->resize(mWindowWidth, mWindowHeight, mSuperSampling);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// When molecule framebuffer has been resized, do so for other buffers too
if(wasResized)
{
// Group rendering texture
mupGroupRenderingTexture->resize(mupMoleculeFramebuffer->getWidth(), mupMoleculeFramebuffer->getHeight());
std::vector<GLuint> emptyDataSemaphore(mupMoleculeFramebuffer->getWidth() * mupMoleculeFramebuffer->getHeight(), 0.f);
mupGroupRenderingSemaphore = std::unique_ptr<GPUTextureBuffer>(new GPUTextureBuffer(emptyDataSemaphore));
// K-Buffer
mupKBufferTexture->resize(mupMoleculeFramebuffer->getWidth(), mupMoleculeFramebuffer->getHeight());
mupKBufferCounter->resize(mupMoleculeFramebuffer->getWidth(), mupMoleculeFramebuffer->getHeight());
}
else
{
// Clear group rendering texture
mupGroupRenderingTexture->clear();
// Clear k-Buffer (only counter must be cleared, not buffer itself)
mupKBufferCounter->clear();
}
// Bind buffers of radii and trajectory for rendering molecule
mupGPUProtein->bind(0, 1);
// Bind group indicator
mupGroupIndicators->bind(2);
// Bind image for group rendering
mupGroupRenderingTexture->bindAsImage(3, GPUAccess::READ_WRITE);
// Bind semaphore image for group rendering
mupGroupRenderingSemaphore->bindAsImage(4, GPUAccess::READ_WRITE);
// Selected atom (is -1 if selection shall be hidden)
int selectedAtom = mRenderSelection ? mSelectedAtom : -1;
// Decide about surface rendering
if(frameComputed())
{
// Bind ascension
mupAscension->bind(5);
// Frame is computed, decide how to render it
switch(mRendering)
{
case Rendering::HULL:
// Prepare shader program
hullProgram.use();
hullProgram.update("time", mAccTime);
hullProgram.update("view", mupCamera->getViewMatrix());
hullProgram.update("projection", mupCamera->getProjectionMatrix());
hullProgram.update("cameraWorldPos", mupCamera->getPosition());
hullProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
hullProgram.update("lightDir", mLightDirection);
hullProgram.update("selectedIndex", selectedAtom);
hullProgram.update("clippingPlane", mClippingPlane);
hullProgram.update("frame", mFrame);
hullProgram.update("atomCount", mupGPUProtein->getAtomCount());
hullProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
hullProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
hullProgram.update("frameCount", mupGPUProtein->getFrameCount());
hullProgram.update("depthDarkeningStart", mDepthDarkeningStart);
hullProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
hullProgram.update("selectionColor", mSelectionColor);
hullProgram.update("localFrame", mFrame - mComputedStartFrame);
hullProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
hullProgram.update("highlightMultiplier", mRenderOutline ? 1.f : 0.f);
hullProgram.update("highlightColor", mOutlineColor);
hullProgram.update("framebufferWidth", mupMoleculeFramebuffer->getWidth());
// Draw internal (first, because at clipping plane are all set to same
// viewport depth which means internal are always in front of surface)
if(mShowInternal)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindInternalIndices(mLayer, 6);
hullProgram.update("color", mInternalAtomColor);
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfInternalAtoms(mLayer));
}
// Draw surface
if(mShowSurface)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindSurfaceIndices(mLayer, 6);
hullProgram.update("color", mSurfaceAtomColor);
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfSurfaceAtoms(mLayer));
}
break;
case Rendering::ASCENSION:
// Prepare shader program
ascensionProgram.use();
ascensionProgram.update("time", mAccTime);
ascensionProgram.update("view", mupCamera->getViewMatrix());
ascensionProgram.update("projection", mupCamera->getProjectionMatrix());
ascensionProgram.update("cameraWorldPos", mupCamera->getPosition());
ascensionProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
ascensionProgram.update("lightDir", mLightDirection);
ascensionProgram.update("selectedIndex", selectedAtom);
ascensionProgram.update("clippingPlane", mClippingPlane);
ascensionProgram.update("frame", mFrame);
ascensionProgram.update("atomCount", mupGPUProtein->getAtomCount());
ascensionProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
ascensionProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
ascensionProgram.update("frameCount", mupGPUProtein->getFrameCount());
ascensionProgram.update("depthDarkeningStart", mDepthDarkeningStart);
ascensionProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
ascensionProgram.update("localFrame", mFrame - mComputedStartFrame);
ascensionProgram.update("ascensionColorOffsetAngle", mAscensionColorOffsetAngle);
ascensionProgram.update("selectionColor", mSelectionColor);
ascensionProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
ascensionProgram.update("highlightMultiplier", mRenderOutline ? 1.f : 0.f);
ascensionProgram.update("highlightColor", mOutlineColor);
ascensionProgram.update("framebufferWidth", mupMoleculeFramebuffer->getWidth());
glDrawArrays(GL_POINTS, 0, mupGPUProtein->getAtomCount());
break;
case Rendering::ELEMENTS:
// Bind coloring
mupGPUProtein->bindColorsElement(6);
// Prepare shader program
coloringProgram.use();
coloringProgram.update("time", mAccTime);
coloringProgram.update("view", mupCamera->getViewMatrix());
coloringProgram.update("projection", mupCamera->getProjectionMatrix());
coloringProgram.update("cameraWorldPos", mupCamera->getPosition());
coloringProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
coloringProgram.update("lightDir", mLightDirection);
coloringProgram.update("selectedIndex", selectedAtom);
coloringProgram.update("clippingPlane", mClippingPlane);
coloringProgram.update("frame", mFrame);
coloringProgram.update("atomCount", mupGPUProtein->getAtomCount());
coloringProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
coloringProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
coloringProgram.update("frameCount", mupGPUProtein->getFrameCount());
coloringProgram.update("depthDarkeningStart", mDepthDarkeningStart);
coloringProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
coloringProgram.update("selectionColor", mSelectionColor);
coloringProgram.update("localFrame", mFrame - mComputedStartFrame);
coloringProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
coloringProgram.update("highlightMultiplier", mRenderOutline ? 1.f : 0.f);
coloringProgram.update("highlightColor", mOutlineColor);
coloringProgram.update("framebufferWidth", mupMoleculeFramebuffer->getWidth());
// Draw internal (first, because at clipping plane are all set to same
// viewport depth which means internal are always in front of surface)
if(mShowInternal)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindInternalIndices(mLayer, 7);
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfInternalAtoms(mLayer));
}
// Draw surface
if(mShowSurface)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindSurfaceIndices(mLayer, 7);
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfSurfaceAtoms(mLayer));
}
break;
case Rendering::AMINOACIDS:
// Bind coloring
mupGPUProtein->bindColorsAminoAcid(6);
// Prepare shader program
coloringProgram.use();
coloringProgram.update("time", mAccTime);
coloringProgram.update("view", mupCamera->getViewMatrix());
coloringProgram.update("projection", mupCamera->getProjectionMatrix());
coloringProgram.update("cameraWorldPos", mupCamera->getPosition());
coloringProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
coloringProgram.update("lightDir", mLightDirection);
coloringProgram.update("selectedIndex", selectedAtom);
coloringProgram.update("clippingPlane", mClippingPlane);
coloringProgram.update("frame", mFrame);
coloringProgram.update("atomCount", mupGPUProtein->getAtomCount());
coloringProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
coloringProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
coloringProgram.update("frameCount", mupGPUProtein->getFrameCount());
coloringProgram.update("depthDarkeningStart", mDepthDarkeningStart);
coloringProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
coloringProgram.update("selectionColor", mSelectionColor);
coloringProgram.update("localFrame", mFrame - mComputedStartFrame);
coloringProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
coloringProgram.update("highlightMultiplier", mRenderOutline ? 1.f : 0.f);
coloringProgram.update("highlightColor", mOutlineColor);
coloringProgram.update("framebufferWidth", mupMoleculeFramebuffer->getWidth());
// Draw internal (first, because at clipping plane are all set to same
// viewport depth which means internal are always in front of surface)
if(mShowInternal)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindInternalIndices(mLayer, 7);
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfInternalAtoms(mLayer));
}
// Draw surface
if(mShowSurface)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindSurfaceIndices(mLayer, 7);
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfSurfaceAtoms(mLayer));
}
break;
case Rendering::ANALYSIS:
// Bind indices of analysis atoms
mupOutlineAtomIndices->bindAsImage(6, GPUAccess::READ_ONLY);
// Prepare shader program
analysisProgram.use();
analysisProgram.update("time", mAccTime);
analysisProgram.update("view", mupCamera->getViewMatrix());
analysisProgram.update("projection", mupCamera->getProjectionMatrix());
analysisProgram.update("cameraWorldPos", mupCamera->getPosition());
analysisProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
analysisProgram.update("lightDir", mLightDirection);
analysisProgram.update("selectedIndex", selectedAtom);
analysisProgram.update("clippingPlane", mClippingPlane);
analysisProgram.update("frame", mFrame);
analysisProgram.update("atomCount", mupGPUProtein->getAtomCount());
analysisProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
analysisProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
analysisProgram.update("frameCount", mupGPUProtein->getFrameCount());
analysisProgram.update("depthDarkeningStart", mDepthDarkeningStart);
analysisProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
analysisProgram.update("groupAtomCount", (int)mupOutlineAtomIndices->getSize());
analysisProgram.update("selectionColor", mSelectionColor);
analysisProgram.update("localFrame", mFrame - mComputedStartFrame);
analysisProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
analysisProgram.update("highlightMultiplier", mRenderOutline ? 1.f : 0.f);
analysisProgram.update("highlightColor", mOutlineColor);
analysisProgram.update("framebufferWidth", mupMoleculeFramebuffer->getWidth());
glDrawArrays(GL_POINTS, 0, mupGPUProtein->getAtomCount());
break;
case Rendering::LAYERS:
// Only proceed when layers were extracted
if(mGPUSurfaces.at(mFrame - mComputedStartFrame)->layersExtracted())
{
// Reuse hull proram for that purpose
hullProgram.use();
hullProgram.update("time", mAccTime);
hullProgram.update("view", mupCamera->getViewMatrix());
hullProgram.update("projection", mupCamera->getProjectionMatrix());
hullProgram.update("cameraWorldPos", mupCamera->getPosition());
hullProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
hullProgram.update("lightDir", mLightDirection);
hullProgram.update("selectedIndex", selectedAtom);
hullProgram.update("clippingPlane", mClippingPlane);
hullProgram.update("frame", mFrame);
hullProgram.update("atomCount", mupGPUProtein->getAtomCount());
hullProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
hullProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
hullProgram.update("frameCount", mupGPUProtein->getFrameCount());
hullProgram.update("depthDarkeningStart", mDepthDarkeningStart);
hullProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
hullProgram.update("selectionColor", mSelectionColor);
hullProgram.update("localFrame", mFrame - mComputedStartFrame);
hullProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);
hullProgram.update("highlightMultiplier", mRenderOutline ? 1.f : 0.f);
hullProgram.update("highlightColor", mOutlineColor);
hullProgram.update("framebufferWidth", mupMoleculeFramebuffer->getWidth());
// Draw inner to outer layers in given colors
int layerCount = mGPUSurfaces.at(mFrame - mComputedStartFrame)->getLayerCount();
for(int i = layerCount - 1; i >= 0; i--)
{
mGPUSurfaces.at(mFrame - mComputedStartFrame)->bindSurfaceIndices(i, 6);
glm::vec3 layerColor = glm::vec3(glm::pow3(float(i)/(layerCount - 1)), float(i)/(layerCount - 1), 160.0f/255.0f);
hullProgram.update("color", layerColor);
// hullProgram.update("color", mLayerColors.at(i % (int)mLayerColors.size()));
glDrawArrays(GL_POINTS, 0, mGPUSurfaces.at(mFrame - mComputedStartFrame)->getCountOfSurfaceAtoms(i));
}
}
break;
case Rendering::RESIDUE_SURFACE_PROXIMITY:
// # Render into k-Buffer
// Disable depth test
glDisable(GL_DEPTH_TEST);
// Bind program and fill uniforms
residueRSPPeelProgram.use();
residueRSPPeelProgram.update("time", mAccTime);
residueRSPPeelProgram.update("view", mupCamera->getViewMatrix());
residueRSPPeelProgram.update("projection", mupCamera->getProjectionMatrix());
residueRSPPeelProgram.update("cameraWorldPos", mupCamera->getPosition());
residueRSPPeelProgram.update("probeRadius", mRenderWithProbeRadius ? mComputedProbeRadius : 0.f);
residueRSPPeelProgram.update("lightDir", mLightDirection);
residueRSPPeelProgram.update("selectedIndex", selectedAtom);
residueRSPPeelProgram.update("clippingPlane", mClippingPlane);
residueRSPPeelProgram.update("frame", mFrame);
residueRSPPeelProgram.update("atomCount", mupGPUProtein->getAtomCount());
residueRSPPeelProgram.update("smoothAnimationRadius", mSmoothAnimationRadius);
residueRSPPeelProgram.update("smoothAnimationMaxDeviation", mSmoothAnimationMaxDeviation);
residueRSPPeelProgram.update("frameCount", mupGPUProtein->getFrameCount());
residueRSPPeelProgram.update("depthDarkeningStart", mDepthDarkeningStart);
residueRSPPeelProgram.update("depthDarkeningEnd", mDepthDarkeningEnd);
residueRSPPeelProgram.update("selectionColor", mSelectionColor);
residueRSPPeelProgram.update("localFrame", mFrame - mComputedStartFrame);
residueRSPPeelProgram.update("localFrameCount", mComputedEndFrame - mComputationStartFrame + 1);
residueRSPPeelProgram.update("ascensionChangeRadiusMultiplier", mAscensionChangeRadiusMultiplier);