/
daryadevx
/
KMiVVR
Обзор
Документация
Войти
/
daryadevx
/
KMiVVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Lab11/Lab11b/fShaders.cpp
183 строки
7 KB
daryadevx
fix
24 дек 2024, 21:14
24 дек 2024, 21:14
5d0eeb2
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #include <tchar.h> #include <System.Math.hpp> #pragma hdrstop #include "fShaders.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Cadencer" #pragma link "GLS.Coordinates" #pragma link "GLSL.CustomShader" #pragma link "GLS.GeomObjects" #pragma link "GLS.Graph" #pragma link "GLS.Material" #pragma link "GLS.Objects" #pragma link "GLS.Scene" #pragma link "GLSL.Shader" #pragma link "GLS.VectorFileObjects" #pragma link "GLS.SceneViewer" #pragma link "GLS.FileSMD" #pragma link "GLS.FileMD2" #pragma link "GLS.File3DS" #pragma link "Formats.DDSImage" #pragma link "GLS.FileMS3D" #pragma link "GLS.BaseClasses" #pragma link "GLSL.Shader" #pragma link "GLSL.BumpShaders" #pragma resource "*.dfm" TForm1* Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {} //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject* Sender) { int I; //First load models TFileName DataPath; DataPath = ExtractFilePath(ParamStr(0)) + "Data"; SetCurrentDir(DataPath); // Then load textures MaterialLibrary->LibMaterialByName("Earth") ->Material->Texture->Image->LoadFromFile("Earth.jpg"); MaterialLibrary->LibMaterialByName("EarthGross") ->Material->Texture->Image->LoadFromFile("EarthSpec.dds"); MaterialLibrary->LibMaterialByName("EarthNormals") ->Material->Texture->Image->LoadFromFile("EarthNormals.jpg"); // Create Shader MultiLightShader = new TGLSLMLBumpShader(this); MultiLightShader->LightSources = MultiLightShader->LightSources << 1, 2; MultiLightShader->LightCompensation = 0.7; MultiLightShader->NormalTexture = MaterialLibrary->LibMaterialByName("EarthNormals")->Material->Texture; MultiLightShader->SpecularTexture = MaterialLibrary->LibMaterialByName("EarthGross")->Material->Texture; // Attach shader to the material MaterialLibrary->LibMaterialByName("Earth")->Shader = MyBumpShader; for (I = 0; I < TrinityMatlib->Materials->Count - 1; I++) TrinityMatlib->Materials->Items[I]->Shader = MyBumpShader; ShowNotGLSceneObjectsCheckBoxClick(this); MyBumpShader->Enabled = ShaderEnabledCheckBox->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::ShaderEnabledCheckBoxClick(TObject* Sender) { MyBumpShader->Enabled = ShaderEnabledCheckBox->Checked; MultiLightShader->Enabled = ShaderEnabledCheckBox->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::ShowNotGLSceneObjectsCheckBoxClick(TObject* Sender) { GLSphere->Visible = ShowNotGLSceneObjectsCheckBox->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::MultiLightShaderCheckBoxClick(TObject* Sender) { int I; if (MultiLightShaderCheckBox->Checked) { MaterialLibrary->LibMaterialByName("Earth")->Shader = MultiLightShader; for (I = 0; I < TrinityMatlib->Materials->Count - 1; I++) TrinityMatlib->Materials->Items[I]->Shader = MultiLightShader; } else { MaterialLibrary->LibMaterialByName("Earth")->Shader = MyBumpShader; for (I = 0; I < TrinityMatlib->Materials->Count - 1; I++) TrinityMatlib->Materials->Items[I]->Shader = MyBumpShader; } Light2->Shining = MultiLightShaderCheckBox->Checked; LightCube2->Visible = MultiLightShaderCheckBox->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::UseSpecularTextureCheckBoxClick(TObject* Sender) { if (UseSpecularTextureCheckBox->Checked) { MyBumpShader->SpecularTexture = MaterialLibrary->LibMaterialByName("EarthGross")->Material->Texture; MultiLightShader->SpecularTexture = MaterialLibrary->LibMaterialByName("EarthGross")->Material->Texture; } else { MyBumpShader->SpecularTexture = NULL; MultiLightShader->SpecularTexture = NULL; } } //--------------------------------------------------------------------------- void __fastcall TForm1::UseNormalTextureCheckBoxClick(TObject* Sender) { if (UseNormalTextureCheckBox->Checked) { MyBumpShader->NormalTexture = MaterialLibrary->LibMaterialByName("EarthNormals") ->Material->Texture; MultiLightShader->NormalTexture = MaterialLibrary->LibMaterialByName("EarthNormals") ->Material->Texture; } else { MyBumpShader->NormalTexture = NULL; MultiLightShader->NormalTexture = NULL; } } //--------------------------------------------------------------------------- void __fastcall TForm1::CadencerProgress( TObject* Sender, const double deltaTime, const double newTime) { Viewer->Invalidate(); if (RollPitchTurnCheckBox->Checked) { GLSphere->Turn(-deltaTime * 15); } } //--------------------------------------------------------------------------- void __fastcall TForm1::ViewerMouseDown( TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::ViewerMouseMove( TObject* Sender, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssRight) && Shift.Contains(ssLeft)) Camera->AdjustDistanceToTarget(Power(1.01, Y - my)); else if (Shift.Contains(ssRight) || Shift.Contains(ssLeft)) Camera->MoveAroundTarget(my - Y, mx - X); mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject* Sender) { Caption = "Лабораторная работа №11b - " + Viewer->FramesPerSecondText(); Viewer->ResetPerformanceMonitor(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseWheel(TObject* Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { Camera->AdjustDistanceToTarget(Power(1.1, WheelDelta / 120)); } //--------------------------------------------------------------------------- void __fastcall TForm1::LightCubeProgress( TObject* Sender, const double deltaTime, const double newTime) { if (LightMovingCheckBox->Checked) LightCube->MoveObjectAround(Camera->TargetObject, sin(newTime) * deltaTime * 10, deltaTime * 20); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject* Sender, TCloseAction &Action) { Cadencer->Enabled = false; } //---------------------------------------------------------------------------