fMultiMaterialD.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. unit fMultiMaterialD;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. System.Math,
  8. System.Types,
  9. Vcl.Graphics,
  10. Vcl.Controls,
  11. Vcl.Forms,
  12. Vcl.Dialogs,
  13. Vcl.Imaging.Jpeg,
  14. GLS.Scene,
  15. GLS.Objects,
  16. GLS.SceneViewer,
  17. GLS.Texture,
  18. Stage.VectorGeometry,
  19. GLS.Cadencer,
  20. GLSL.MultiMaterialShader,
  21. GLSL.TextureShaders,
  22. GLS.Material,
  23. GLS.Coordinates,
  24. Stage.Utils,
  25. GLS.BaseClasses,
  26. GLS.SimpleNavigation;
  27. type
  28. TFormMultiMat = class(TForm)
  29. GLScene1: TGLScene;
  30. GLMatLib1: TGLMaterialLibrary;
  31. GLSceneViewer1: TGLSceneViewer;
  32. GLCamera1: TGLCamera;
  33. GLDummyCube1: TGLDummyCube;
  34. GLCube1: TGLCube;
  35. GLLightSource1: TGLLightSource;
  36. GLMatLib2: TGLMaterialLibrary;
  37. GLMultiMaterialShader1: TGLMultiMaterialShader;
  38. GLCadencer1: TGLCadencer;
  39. GLTexCombineShader1: TGLTexCombineShader;
  40. GLSimpleNavigation1: TGLSimpleNavigation;
  41. procedure FormCreate(Sender: TObject);
  42. procedure GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
  43. Shift: TShiftState; X, Y: Integer);
  44. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  45. X, Y: Integer);
  46. procedure GLCadencer1Progress(Sender: TObject;
  47. const deltaTime, newTime: Double);
  48. procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
  49. WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  50. private
  51. public
  52. mx, my: Integer;
  53. end;
  54. var
  55. FormMultiMat: TFormMultiMat;
  56. implementation
  57. {$R *.dfm}
  58. procedure TFormMultiMat.FormCreate(Sender: TObject);
  59. var
  60. Path: TFileName;
  61. LibMat: TGLLibMaterial;
  62. begin
  63. Path := GetCurrentAssetPath();
  64. SetCurrentDir(Path + '\texture');
  65. // GLMatLib1 is the source of the first image
  66. // Add the specular material using tmModulate for shiny text
  67. GLMatLib1.AddTextureMaterial('specular', 'glscene_alpha.bmp');
  68. GLMatLib1.Materials.GetLibMaterialByName('specular').Material.Texture.TextureMode := tmModulate;
  69. // use TextureMode := tmBlend; for shiny background
  70. GLMatLib1.Materials.GetLibMaterialByName('specular').Material.BlendingMode := bmAdditive;
  71. GLMatLib1.Materials.GetLibMaterialByName('specular').Texture2Name := 'specular_tex2';
  72. (* or with delphi with do more short
  73. with GLMatLib1.AddTextureMaterial('specular', 'glscene_alpha.bmp') do
  74. begin
  75. Material.Texture.TextureMode := tmModulate;
  76. Material.BlendingMode := bmAdditive;
  77. Texture2Name := 'specular_tex2';
  78. end;
  79. //*)
  80. GLMatLib1.AddTextureMaterial('specular_tex2', 'rainbow.bmp');
  81. GLMatLib1.Materials.GetLibMaterialByName('specular_tex2').Material.Texture.MappingMode := tmmCubeMapReflection;
  82. GLMatLib1.Materials.GetLibMaterialByName('specular_tex2').Material.Texture.ImageBrightness := 0.3;
  83. // GLMatLib2 is the source of the GLMultiMaterialShader passes.
  84. // Pass 1: Base texture
  85. GLMatLib2.AddTextureMaterial('Pass1', 'glscene.bmp'); // or use glscene_delphi.bmp
  86. // Pass 2: Add a bit of detail
  87. GLMatLib2.AddTextureMaterial('Pass2', 'detailmap.jpg');
  88. GLMatLib2.Materials.GetLibMaterialByName('Pass2').Material.Texture.TextureMode := tmBlend;
  89. GLMatLib2.Materials.GetLibMaterialByName('Pass2').Material.BlendingMode := bmAdditive;
  90. // Pass 3: And a little specular reflection
  91. LibMat := TGLLibMaterial.Create(GLMatLib2.Materials);
  92. LibMat.Material.MaterialLibrary := GLMatLib1;
  93. LibMat.Material.LibMaterialName := 'specular';
  94. // This isn't limited to 3, try adding some more passes!
  95. end;
  96. procedure TFormMultiMat.GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
  97. Shift: TShiftState; X, Y: Integer);
  98. begin
  99. mx := X;
  100. my := Y;
  101. end;
  102. procedure TFormMultiMat.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  103. X, Y: Integer);
  104. begin
  105. if ssLeft in Shift then
  106. GLCamera1.MoveAroundTarget(my - Y, mx - X);
  107. mx := X;
  108. my := Y;
  109. end;
  110. procedure TFormMultiMat.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  111. WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  112. begin
  113. GLCamera1.AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  114. Handled := true
  115. end;
  116. procedure TFormMultiMat.GLCadencer1Progress(Sender: TObject;
  117. const deltaTime, newTime: Double);
  118. begin
  119. GLCube1.Turn(deltaTime * 10);
  120. end;
  121. end.