GLSL.ShaderBump.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. //
  2. // This unit is part of the GLScene Engine, http://glscene.org
  3. //
  4. unit GLSL.ShaderBump;
  5. (*
  6. A GLSL shader that applies bump mapping.
  7. This is a collection of GLSL Bump shaders, comes in these variaties
  8. (to know what these abriviations mean, see GLCustomShader.pas):
  9. - TGLSLBumpShader
  10. - TGLSLBumpShaderMT
  11. - TGLSLBumpShaderAM
  12. - TGLSLMLBumpShader
  13. - TGLSLMLBumpShaderMT
  14. Notes:
  15. 1) Alpha is a synthetic property, in real life your should set each
  16. color's Alpha individualy
  17. 2) TGLSLMLBumpShader takes all Light parameters directly
  18. from OpenGL (that includes TGLLightSource's)
  19. TODO:
  20. 1) Implement IGLShaderDescription in all shaders.
  21. *)
  22. interface
  23. {$I GLScene.inc}
  24. uses
  25. System.Classes,
  26. System.SysUtils,
  27. GLTexture,
  28. GLScene,
  29. GLVectorGeometry,
  30. GLVectorTypes,
  31. GLCadencer,
  32. GLS.Strings,
  33. OpenGLTokens,
  34. GLSL.Shader,
  35. GLS.ShaderCustom,
  36. GLColor,
  37. GLRenderContextInfo,
  38. GLMaterial;
  39. type
  40. EGLSLBumpShaderException = class(EGLSLShaderException);
  41. // An abstract class.
  42. TGLBaseCustomGLSLBumpShader = class(TGLCustomGLSLShader, IGLMaterialLibrarySupported)
  43. private
  44. FBumpHeight: Single;
  45. FBumpSmoothness: Integer;
  46. FSpecularPower: Single;
  47. FSpecularSpread: Single;
  48. FLightPower: Single;
  49. FMaterialLibrary: TGLMaterialLibrary;
  50. FNormalTexture: TGLTexture;
  51. FSpecularTexture: TGLTexture;
  52. FNormalTextureName: TGLLibMaterialName;
  53. FSpecularTextureName: TGLLibMaterialName;
  54. function GetNormalTextureName: TGLLibMaterialName;
  55. function GetSpecularTextureName: TGLLibMaterialName;
  56. procedure SetNormalTextureName(const Value: TGLLibMaterialName);
  57. procedure SetSpecularTextureName(const Value: TGLLibMaterialName);
  58. procedure SetSpecularTexture(const Value: TGLTexture);
  59. procedure SetNormalTexture(const Value: TGLTexture);
  60. // Implementing IGLMaterialLibrarySupported.
  61. function GetMaterialLibrary: TGLAbstractMaterialLibrary;
  62. protected
  63. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  64. function DoUnApply(var rci: TGLRenderContextInfo): Boolean; override;
  65. procedure SetMaterialLibrary(const Value: TGLMaterialLibrary); virtual;
  66. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  67. public
  68. constructor Create(AOwner : TComponent); override;
  69. property BumpHeight: Single read FBumpHeight write FBumpHeight;
  70. property BumpSmoothness: Integer read FBumpSmoothness write FBumpSmoothness;
  71. property SpecularPower: Single read FSpecularPower write FSpecularPower;
  72. property SpecularSpread: Single read FSpecularSpread write FSpecularSpread;
  73. property LightPower: Single read FLightPower write FLightPower;
  74. property NormalTexture: TGLTexture read FNormalTexture write SetNormalTexture;
  75. property SpecularTexture: TGLTexture read FSpecularTexture write SetSpecularTexture;
  76. property NormalTextureName: TGLLibMaterialName read GetNormalTextureName write SetNormalTextureName;
  77. property SpecularTextureName: TGLLibMaterialName read GetSpecularTextureName write SetSpecularTextureName;
  78. property MaterialLibrary: TGLMaterialLibrary read FMaterialLibrary write SetMaterialLibrary;
  79. end;
  80. // An abstract class.
  81. TGLBaseCustomGLSLBumpShaderMT = class(TGLBaseCustomGLSLBumpShader)
  82. private
  83. FMainTexture: TGLTexture;
  84. FMainTextureName: TGLLibMaterialName;
  85. function GetMainTextureName: string;
  86. procedure SetMainTextureName(const Value: string);
  87. protected
  88. procedure SetMaterialLibrary(const Value: TGLMaterialLibrary); override;
  89. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  90. public
  91. property MainTexture: TGLTexture read FMainTexture write FMainTexture;
  92. property MainTextureName: TGLLibMaterialName read GetMainTextureName write SetMainTextureName;
  93. end;
  94. // One Light shaders.
  95. TGLCustomGLSLBumpShaderAM = class(TGLBaseCustomGLSLBumpShaderMT)
  96. private
  97. FAmbientColor: TGLColor;
  98. FDiffuseColor: TGLColor;
  99. FSpecularColor: TGLColor;
  100. function GetAlpha: Single;
  101. procedure SetAlpha(const Value: Single);
  102. protected
  103. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  104. procedure DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject); override;
  105. public
  106. constructor Create(AOwner : TComponent); override;
  107. destructor Destroy; override;
  108. property AmbientColor: TGLColor read FAmbientColor;
  109. property DiffuseColor: TGLColor read FDiffuseColor;
  110. property SpecularColor: TGLColor read FSpecularColor;
  111. property Alpha: Single read GetAlpha write SetAlpha;
  112. end;
  113. TGLCustomGLSLBumpShaderMT = class(TGLBaseCustomGLSLBumpShaderMT)
  114. protected
  115. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  116. procedure DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject); override;
  117. end;
  118. TGLCustomGLSLBumpShader = class(TGLBaseCustomGLSLBumpShader, IGLShaderDescription)
  119. private
  120. // Implementing IGLShaderDescription.
  121. procedure SetShaderTextures(const Textures: array of TGLTexture);
  122. procedure GetShaderTextures(var Textures: array of TGLTexture);
  123. procedure SetShaderColorParams(const AAmbientColor, ADiffuseColor, ASpecularcolor: TVector4f);
  124. procedure GetShaderColorParams(var AAmbientColor, ADiffuseColor, ASpecularcolor: TVector4f);
  125. procedure SetShaderMiscParameters(const ACadencer: TGLCadencer; const AMatLib: TGLMaterialLibrary; const ALightSources: TGLLightSourceSet);
  126. procedure GetShaderMiscParameters(var ACadencer: TGLCadencer; var AMatLib: TGLMaterialLibrary; var ALightSources: TGLLightSourceSet);
  127. function GetShaderAlpha: Single;
  128. procedure SetShaderAlpha(const Value: Single);
  129. function GetShaderDescription: string;
  130. protected
  131. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  132. procedure DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject); override;
  133. end;
  134. // MultiLight shaders.
  135. TGLCustomGLSLMLBumpShader = class(TGLBaseCustomGLSLBumpShader, IGLShaderDescription)
  136. private
  137. FLightSources: TGLLightSourceSet;
  138. FLightCompensation: Single;
  139. procedure SetLightSources(const Value: TGLLightSourceSet);
  140. procedure SetLightCompensation(const Value: Single);
  141. // Implementing IGLShaderDescription.
  142. procedure SetShaderTextures(const Textures: array of TGLTexture);
  143. procedure GetShaderTextures(var Textures: array of TGLTexture);
  144. procedure SetShaderColorParams(const AAmbientColor, ADiffuseColor, ASpecularcolor: TVector4f);
  145. procedure GetShaderColorParams(var AAmbientColor, ADiffuseColor, ASpecularcolor: TVector4f);
  146. procedure SetShaderMiscParameters(const ACadencer: TGLCadencer; const AMatLib: TGLMaterialLibrary; const ALightSources: TGLLightSourceSet);
  147. procedure GetShaderMiscParameters(var ACadencer: TGLCadencer; var AMatLib: TGLMaterialLibrary; var ALightSources: TGLLightSourceSet);
  148. function GetShaderAlpha: Single;
  149. procedure SetShaderAlpha(const Value: Single);
  150. function GetShaderDescription: string;
  151. protected
  152. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  153. procedure DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject); override;
  154. public
  155. constructor Create(AOwner : TComponent); override;
  156. property LightSources: TGLLightSourceSet read FLightSources write SetLightSources default [1];
  157. {Setting LightCompensation to a value less than 1 decreeses individual
  158. light intensity when using multiple lights }
  159. property LightCompensation: Single read FLightCompensation write SetLightCompensation;
  160. end;
  161. TGLCustomGLSLMLBumpShaderMT = class(TGLBaseCustomGLSLBumpShaderMT)
  162. private
  163. FLightSources: TGLLightSourceSet;
  164. FLightCompensation: Single;
  165. procedure SetLightSources(const Value: TGLLightSourceSet);
  166. procedure SetLightCompensation(const Value: Single);
  167. protected
  168. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  169. procedure DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject); override;
  170. public
  171. constructor Create(AOwner : TComponent); override;
  172. property LightSources: TGLLightSourceSet read FLightSources write SetLightSources default [1];
  173. {Setting LightCompensation to a value less than 1 decreeses individual
  174. light intensity when using multiple lights }
  175. property LightCompensation: Single read FLightCompensation write SetLightCompensation;
  176. end;
  177. {************** Published **************}
  178. // One light shaders.
  179. TGLSLBumpShaderMT = class(TGLCustomGLSLBumpShaderMT)
  180. published
  181. property MainTextureName;
  182. property NormalTextureName;
  183. property SpecularTextureName;
  184. property MaterialLibrary;
  185. property BumpHeight;
  186. property BumpSmoothness;
  187. property SpecularPower;
  188. property SpecularSpread;
  189. property LightPower;
  190. end;
  191. TGLSLBumpShader = class(TGLCustomGLSLBumpShader)
  192. published
  193. property NormalTextureName;
  194. property SpecularTextureName;
  195. property MaterialLibrary;
  196. property BumpHeight;
  197. property BumpSmoothness;
  198. property SpecularPower;
  199. property SpecularSpread;
  200. property LightPower;
  201. end;
  202. TGLSLBumpShaderAM = class(TGLCustomGLSLBumpShaderAM)
  203. published
  204. property AmbientColor;
  205. property DiffuseColor;
  206. property SpecularColor;
  207. property Alpha stored False;
  208. property MainTextureName;
  209. property NormalTextureName;
  210. property SpecularTextureName;
  211. property MaterialLibrary;
  212. property BumpHeight;
  213. property BumpSmoothness;
  214. property SpecularPower;
  215. property SpecularSpread;
  216. property LightPower;
  217. end;
  218. // Multi light shaders.
  219. TGLSLMLBumpShader = class(TGLCustomGLSLMLBumpShader)
  220. published
  221. property NormalTextureName;
  222. property SpecularTextureName;
  223. property MaterialLibrary;
  224. property BumpHeight;
  225. property BumpSmoothness;
  226. property SpecularPower;
  227. property SpecularSpread;
  228. property LightPower;
  229. property LightSources;
  230. property LightCompensation;
  231. end;
  232. TGLSLMLBumpShaderMT = class(TGLCustomGLSLMLBumpShaderMT)
  233. published
  234. property MainTextureName;
  235. property NormalTextureName;
  236. property SpecularTextureName;
  237. property MaterialLibrary;
  238. property BumpHeight;
  239. property BumpSmoothness;
  240. property SpecularPower;
  241. property SpecularSpread;
  242. property LightPower;
  243. property LightSources;
  244. property LightCompensation;
  245. end;
  246. //--------------------------------------------------------------
  247. implementation
  248. //--------------------------------------------------------------
  249. procedure GetVertexProgramCode(const Code: TStrings);
  250. begin
  251. with Code do
  252. begin
  253. Clear;
  254. Add('varying vec2 Texcoord; ');
  255. Add('varying vec3 ViewDirection; ');
  256. Add('varying vec3 LightDirection; ');
  257. Add(' ');
  258. Add('void main( void ) ');
  259. Add('{ ');
  260. Add(' gl_Position = ftransform(); ');
  261. Add(' Texcoord = gl_MultiTexCoord0.xy; ');
  262. Add(' ');
  263. Add(' vec3 fvViewDirection = (gl_ModelViewMatrix * gl_Vertex).xyz; ');
  264. Add(' vec3 fvLightDirection = gl_LightSource[0].position.xyz - fvViewDirection; ');
  265. Add(' ');
  266. Add(' vec3 fvNormal = gl_NormalMatrix * gl_Normal; ');
  267. Add(' vec3 fvBinormal = gl_NormalMatrix * gl_MultiTexCoord2.xyz; ');
  268. Add(' vec3 fvTangent = gl_NormalMatrix * gl_MultiTexCoord1.xyz; ');
  269. Add(' ');
  270. Add(' ViewDirection.x = dot( fvTangent, fvViewDirection ); ');
  271. Add(' ViewDirection.y = dot( fvBinormal, fvViewDirection ); ');
  272. Add(' ViewDirection.z = dot( fvNormal, fvViewDirection ); ');
  273. Add(' ');
  274. Add(' LightDirection.x = dot( fvTangent, fvLightDirection ); ');
  275. Add(' LightDirection.y = dot( fvBinormal, fvLightDirection ); ');
  276. Add(' LightDirection.z = dot( fvNormal, fvLightDirection ); ');
  277. Add(' ');
  278. Add(' LightDirection = normalize(LightDirection); ');
  279. Add(' ViewDirection = normalize(ViewDirection); ');
  280. Add('} ');
  281. end;
  282. end;
  283. procedure GetFragmentProgramCodeMP(const Code: TStrings; const UseSpecularMap: Boolean; const UseNormalMap: Boolean);
  284. begin
  285. with Code do
  286. begin
  287. Clear;
  288. Add('uniform vec4 fvAmbient; ');
  289. Add('uniform vec4 fvSpecular; ');
  290. Add('uniform vec4 fvDiffuse; ');
  291. Add(' ');
  292. Add('uniform float fLightPower; ');
  293. Add('uniform float fSpecularPower; ');
  294. Add('uniform float fSpecularSpread; ');
  295. if UseNormalMap then
  296. begin
  297. Add('uniform sampler2D bumpMap; ');
  298. Add('uniform float fBumpHeight; ');
  299. Add('uniform float fBumpSmoothness; ');
  300. end;
  301. Add(' ');
  302. Add('uniform sampler2D baseMap; ');
  303. if UseSpecularMap then
  304. Add('uniform sampler2D specMap; ');
  305. Add(' ');
  306. Add('varying vec2 Texcoord; ');
  307. Add('varying vec3 ViewDirection; ');
  308. Add('varying vec3 LightDirection; ');
  309. Add(' ');
  310. Add('void main( void ) ');
  311. Add('{ ');
  312. if UseNormalMap then
  313. Add(' vec3 fvNormal = normalize( ( texture2D( bumpMap, Texcoord ).xyz * fBumpSmoothness) - fBumpHeight * fBumpSmoothness); ')
  314. else
  315. Add(' vec3 fvNormal = vec3(0.0, 0.0, 1);');
  316. Add(' ');
  317. Add(' float fNDotL = dot( fvNormal, LightDirection ); ');
  318. Add(' vec3 fvReflection = normalize( ( (fSpecularSpread * fvNormal ) * fNDotL ) - LightDirection ); ');
  319. Add(' ');
  320. Add(' float fRDotV = max( dot( fvReflection, -ViewDirection ), 0.0 ); ');
  321. Add(' ');
  322. Add(' vec4 fvBaseColor = texture2D( baseMap, Texcoord ); ');
  323. if UseSpecularMap then
  324. Add(' vec4 fvSpecColor = texture2D( specMap, Texcoord ) * fvSpecular; ')
  325. else
  326. Add(' vec4 fvSpecColor = fvSpecular; ');
  327. Add(' ');
  328. Add(' vec4 fvTotalDiffuse = clamp(fvDiffuse * fNDotL, 0.0, 1.0); ');
  329. Add(' ');
  330. Add(' // (fvTotalDiffuse + 0.2) / 1.2 is used for removing artefacts on the non-lit side ');
  331. Add(' vec4 fvTotalSpecular = clamp((pow(fRDotV, fSpecularPower ) ) * (fvTotalDiffuse + 0.2) / 1.2 * fvSpecColor, 0.0, 1.0); ');
  332. Add(' ');
  333. Add(' gl_FragColor = fLightPower * (fvBaseColor * ( fvAmbient + fvTotalDiffuse ) + fvTotalSpecular); ');
  334. Add('} ');
  335. end;
  336. end;
  337. procedure GetFragmentProgramCode(const Code: TStrings; const UseSpecularMap: Boolean; const UseNormalMap: Boolean);
  338. begin
  339. with Code do
  340. begin
  341. Clear;
  342. Add('uniform float fLightPower; ');
  343. Add('uniform float fSpecularPower; ');
  344. Add('uniform float fSpecularSpread; ');
  345. if UseNormalMap then
  346. begin
  347. Add('uniform sampler2D bumpMap; ');
  348. Add('uniform float fBumpHeight; ');
  349. Add('uniform float fBumpSmoothness; ');
  350. end;
  351. Add(' ');
  352. Add('uniform sampler2D baseMap; ');
  353. if UseSpecularMap then
  354. Add('uniform sampler2D specMap; ');
  355. Add(' ');
  356. Add('varying vec2 Texcoord; ');
  357. Add('varying vec3 ViewDirection; ');
  358. Add('varying vec3 LightDirection; ');
  359. Add(' ');
  360. Add('void main( void ) ');
  361. Add('{ ');
  362. if UseNormalMap then
  363. Add(' vec3 fvNormal = normalize( ( texture2D( bumpMap, Texcoord ).xyz * fBumpSmoothness) - fBumpHeight * fBumpSmoothness); ')
  364. else
  365. Add(' vec3 fvNormal = vec3(0.0, 0.0, 1.0);');
  366. Add(' ');
  367. Add(' float fNDotL = dot( fvNormal, LightDirection ); ');
  368. Add(' vec3 fvReflection = normalize( ( (fSpecularSpread * fvNormal ) * fNDotL ) - LightDirection ); ');
  369. Add(' ');
  370. Add(' float fRDotV = max(dot( fvReflection, -ViewDirection ), 0.0); ');
  371. Add(' ');
  372. Add(' vec4 fvBaseColor = texture2D( baseMap, Texcoord ); ');
  373. if UseSpecularMap then
  374. Add(' vec4 fvSpecColor = texture2D( specMap, Texcoord ) * gl_LightSource[0].specular; ')
  375. else
  376. Add(' vec4 fvSpecColor = gl_LightSource[0].specular; ');
  377. Add(' ');
  378. Add(' vec4 fvTotalDiffuse = clamp(gl_LightSource[0].diffuse * fNDotL, 0.0, 1.0); ');
  379. Add(' ');
  380. Add(' // (fvTotalDiffuse + 0.2) / 1.2 is used for removing artefacts on the non-lit side ');
  381. Add(' vec4 fvTotalSpecular = clamp((pow(fRDotV, fSpecularPower ) ) * (fvTotalDiffuse + 0.2) / 1.2 * fvSpecColor, 0.0, 1.0); ');
  382. Add(' ');
  383. Add(' gl_FragColor = fLightPower * (fvBaseColor * ( gl_LightSource[0].ambient + fvTotalDiffuse ) + fvTotalSpecular); ');
  384. Add('} ');
  385. end;
  386. end;
  387. procedure GetMLVertexProgramCode(const Code: TStrings);
  388. begin
  389. with Code do
  390. begin
  391. Clear;
  392. Add('varying vec2 Texcoord; ');
  393. Add('varying vec3 ViewDirection; ');
  394. Add(' ');
  395. Add('varying vec3 fvViewDirection; ');
  396. Add('varying vec3 fvNormal; ');
  397. Add('varying vec3 fvBinormal; ');
  398. Add('varying vec3 fvTangent; ');
  399. Add(' ');
  400. Add('void main( void ) ');
  401. Add('{ ');
  402. Add(' gl_Position = ftransform(); ');
  403. Add(' Texcoord = gl_MultiTexCoord0.xy; ');
  404. Add(' ');
  405. Add(' fvViewDirection = (gl_ModelViewMatrix * gl_Vertex).xyz; ');
  406. Add(' ');
  407. Add(' fvNormal = gl_NormalMatrix * gl_Normal; ');
  408. Add(' fvBinormal = gl_NormalMatrix * gl_MultiTexCoord2.xyz; ');
  409. Add(' fvTangent = gl_NormalMatrix * gl_MultiTexCoord1.xyz; ');
  410. Add(' ');
  411. Add(' ViewDirection.x = dot( fvTangent, fvViewDirection ); ');
  412. Add(' ViewDirection.y = dot( fvBinormal, fvViewDirection ); ');
  413. Add(' ViewDirection.z = dot( fvNormal, fvViewDirection ); ');
  414. Add(' ');
  415. Add(' ViewDirection = normalize(ViewDirection); ');
  416. Add('} ');
  417. end;
  418. end;
  419. procedure GetMLFragmentProgramCodeBeg(const Code: TStrings; const UseSpecularMap: Boolean; const UseNormalMap: Boolean);
  420. begin
  421. with Code do
  422. begin
  423. Clear;
  424. Add('uniform float fLightPower; ');
  425. Add('uniform float fSpecularPower; ');
  426. Add('uniform float fSpecularSpread; ');
  427. if UseNormalMap then
  428. begin
  429. Add('uniform sampler2D bumpMap; ');
  430. Add('uniform float fBumpHeight; ');
  431. Add('uniform float fBumpSmoothness; ');
  432. end;
  433. Add(' ');
  434. Add('uniform sampler2D baseMap; ');
  435. if UseSpecularMap then
  436. Add('uniform sampler2D specMap; ');
  437. Add(' ');
  438. Add('varying vec2 Texcoord; ');
  439. Add('varying vec3 ViewDirection; ');
  440. Add(' ');
  441. Add('varying vec3 fvViewDirection; ');
  442. Add('varying vec3 fvNormal; ');
  443. Add('varying vec3 fvBinormal; ');
  444. Add('varying vec3 fvTangent; ');
  445. Add(' ');
  446. Add('void main( void ) ');
  447. Add('{ ');
  448. Add(' vec3 LightDirection;');
  449. Add(' vec3 fvLightDirection; ');
  450. Add(' ');
  451. if UseNormalMap then
  452. Add(' vec3 fvBumpNormal = normalize( ( texture2D( bumpMap, Texcoord ).xyz * fBumpSmoothness) - fBumpHeight * fBumpSmoothness); ')
  453. else
  454. Add(' vec3 fvBumpNormal = vec3(0.0, 0.0, 1);');
  455. Add(' ');
  456. Add(' float fNDotL ; ');
  457. Add(' vec3 fvReflection ; ');
  458. Add(' float fRDotV ; ');
  459. Add(' vec4 fvBaseColor = texture2D( baseMap, Texcoord ); ');
  460. if UseSpecularMap then
  461. Add(' vec4 fvSpecColor = texture2D( specMap, Texcoord ); ')
  462. else
  463. Add(' vec4 fvSpecColor = vec4(1.0, 1.0, 1.0, 1.0); ');
  464. Add(' vec4 fvNewDiffuse ; ');
  465. Add(' vec4 fvTotalDiffuse = vec4(0, 0, 0, 0); ');
  466. Add(' vec4 fvTotalAmbient = vec4(0, 0, 0, 0); ');
  467. Add(' vec4 fvTotalSpecular = vec4(0, 0, 0, 0); ');
  468. end;
  469. end;
  470. procedure GetMLFragmentProgramCodeMid(const Code: TStrings; const CurrentLight: Integer);
  471. begin
  472. with Code do
  473. begin
  474. Add(' fvLightDirection = gl_LightSource[' + IntToStr(CurrentLight) + '].position.xyz - fvViewDirection; ');
  475. Add(' ');
  476. Add(' LightDirection.x = dot( fvTangent, fvLightDirection ); ');
  477. Add(' LightDirection.y = dot( fvBinormal, fvLightDirection ); ');
  478. Add(' LightDirection.z = dot( fvNormal, fvLightDirection ); ');
  479. Add(' LightDirection = normalize(LightDirection); ');
  480. Add(' ');
  481. Add(' fNDotL = dot( fvBumpNormal, LightDirection ); ');
  482. Add(' fvReflection = normalize( ( (fSpecularSpread * fvBumpNormal ) * fNDotL ) - LightDirection ); ');
  483. Add(' fRDotV = max( dot( fvReflection, -ViewDirection ), 0.0 ); ');
  484. Add(' fvNewDiffuse = clamp(gl_LightSource[' + IntToStr(CurrentLight) + '].diffuse * fNDotL, 0.0, 1.0); ');
  485. Add(' fvTotalDiffuse = min(fvTotalDiffuse + fvNewDiffuse, 1.0); ');
  486. Add(' fvTotalSpecular = min(fvTotalSpecular + clamp((pow(fRDotV, fSpecularPower ) ) * (fvNewDiffuse + 0.2) / 1.2 * (fvSpecColor * gl_LightSource[' + IntToStr(CurrentLight) + '].specular), 0.0, 1.0), 1.0); ');
  487. Add(' fvTotalAmbient = fvTotalAmbient + gl_LightSource[' + IntToStr(CurrentLight) + '].ambient; ');
  488. end;
  489. end;
  490. procedure GetMLFragmentProgramCodeEnd(const Code: TStrings; const FLightCount: Integer; const FLightCompensation: Single);
  491. var
  492. Temp: AnsiString;
  493. begin
  494. with Code do
  495. begin
  496. Str((1 + (FLightCount - 1) * FLightCompensation) / FLightCount :1 :1, Temp);
  497. if (FLightCount = 1) or (FLightCompensation = 1) then
  498. Add(' gl_FragColor = fLightPower * (fvBaseColor * ( fvTotalAmbient + fvTotalDiffuse ) + fvTotalSpecular); ')
  499. else
  500. Add(' gl_FragColor = fLightPower * (fvBaseColor * ( fvTotalAmbient + fvTotalDiffuse ) + fvTotalSpecular) * ' + string(Temp) + '; ');
  501. Add('} ');
  502. end;
  503. end;
  504. { TGLBaseCustomGLSLBumpShader }
  505. constructor TGLBaseCustomGLSLBumpShader.Create(AOwner: TComponent);
  506. begin
  507. inherited;
  508. FSpecularPower := 6;
  509. FSpecularSpread := 1.5;
  510. FLightPower := 1;
  511. FBumpHeight := 0.5;
  512. FBumpSmoothness := 300;
  513. TStringList(VertexProgram.Code).OnChange := nil;
  514. TStringList(FragmentProgram.Code).OnChange := nil;
  515. VertexProgram.Enabled := True;
  516. FragmentProgram.Enabled := True;
  517. end;
  518. procedure TGLBaseCustomGLSLBumpShader.DoApply(
  519. var rci: TGLRenderContextInfo; Sender: TObject);
  520. begin
  521. // Don't inherit not to call the event.
  522. GetGLSLProg.UseProgramObject;
  523. Param['fSpecularPower'].AsVector1f := FSpecularPower;
  524. Param['fSpecularSpread'].AsVector1f := FSpecularSpread;
  525. Param['fLightPower'].AsVector1f := FLightPower;
  526. if FSpecularTexture <> nil then
  527. Param['specMap'].AsTexture2D[2] := FSpecularTexture;
  528. {$IFNDEF USE_OPTIMIZATIONS}
  529. if FNormalTexture <> nil then
  530. {$ENDIF}
  531. begin
  532. Param['bumpMap'].AsTexture2D[1] := FNormalTexture;
  533. Param['fBumpHeight'].AsVector1f := FBumpHeight;
  534. Param['fBumpSmoothness'].AsVector1f := FBumpSmoothness;
  535. end;
  536. end;
  537. function TGLBaseCustomGLSLBumpShader.DoUnApply(
  538. var rci: TGLRenderContextInfo): Boolean;
  539. begin
  540. //don't inherit not to call the event
  541. Result := False;
  542. GetGLSLProg.EndUseProgramObject;
  543. end;
  544. function TGLBaseCustomGLSLBumpShader.GetMaterialLibrary: TGLAbstractMaterialLibrary;
  545. begin
  546. Result := FMaterialLibrary;
  547. end;
  548. function TGLBaseCustomGLSLBumpShader.GetNormalTextureName: TGLLibMaterialName;
  549. begin
  550. Result := FMaterialLibrary.GetNameOfTexture(FNormalTexture);
  551. if Result = '' then Result := FNormalTextureName;
  552. end;
  553. function TGLBaseCustomGLSLBumpShader.GetSpecularTextureName: TGLLibMaterialName;
  554. begin
  555. Result := FMaterialLibrary.GetNameOfTexture(FSpecularTexture);
  556. if Result = '' then Result := FSpecularTextureName;
  557. end;
  558. procedure TGLBaseCustomGLSLBumpShader.Notification(
  559. AComponent: TComponent; Operation: TOperation);
  560. var
  561. Index: Integer;
  562. begin
  563. inherited;
  564. if Operation = opRemove then
  565. if AComponent = FMaterialLibrary then
  566. if FMaterialLibrary <> nil then
  567. begin
  568. // Need to nil the textures that were ownned by it.
  569. if FNormalTexture <> nil then
  570. begin
  571. Index := FMaterialLibrary.Materials.GetTextureIndex(FNormalTexture);
  572. if Index <> -1 then
  573. SetNormalTexture(nil);
  574. end;
  575. if FSpecularTexture <> nil then
  576. begin
  577. Index := FMaterialLibrary.Materials.GetTextureIndex(FSpecularTexture);
  578. if Index <> -1 then
  579. SetSpecularTexture(nil);
  580. end;
  581. FMaterialLibrary := nil;
  582. end;
  583. end;
  584. procedure TGLBaseCustomGLSLBumpShader.SetMaterialLibrary(
  585. const Value: TGLMaterialLibrary);
  586. begin
  587. if FMaterialLibrary <> nil then
  588. FMaterialLibrary.RemoveFreeNotification(Self);
  589. FMaterialLibrary := Value;
  590. if FMaterialLibrary <> nil then
  591. begin
  592. FMaterialLibrary.FreeNotification(Self);
  593. if FNormalTextureName <> '' then
  594. SetNormalTextureName(FNormalTextureName);
  595. if FSpecularTextureName <> '' then
  596. SetSpecularTextureName(FSpecularTextureName);
  597. end
  598. else
  599. begin
  600. FNormalTextureName := '';
  601. FSpecularTextureName := '';
  602. end;
  603. end;
  604. procedure TGLBaseCustomGLSLBumpShader.SetNormalTexture(
  605. const Value: TGLTexture);
  606. begin
  607. FNormalTexture := Value;
  608. FinalizeShader;
  609. end;
  610. procedure TGLBaseCustomGLSLBumpShader.SetNormalTextureName(
  611. const Value: TGLLibMaterialName);
  612. begin
  613. if FMaterialLibrary = nil then
  614. begin
  615. FNormalTextureName := Value;
  616. if not (csLoading in ComponentState) then
  617. raise EGLSLBumpShaderException.Create(strErrorEx + strMatLibNotDefined);
  618. end
  619. else
  620. begin
  621. SetNormalTexture(FMaterialLibrary.TextureByName(Value));
  622. FNormalTextureName := '';
  623. end;
  624. end;
  625. procedure TGLBaseCustomGLSLBumpShader.SetSpecularTexture(
  626. const Value: TGLTexture);
  627. begin
  628. FSpecularTexture := Value;
  629. FinalizeShader;
  630. end;
  631. procedure TGLBaseCustomGLSLBumpShader.SetSpecularTextureName(
  632. const Value: TGLLibMaterialName);
  633. begin
  634. if FMaterialLibrary = nil then
  635. begin
  636. FSpecularTextureName := Value;
  637. if not (csLoading in ComponentState) then
  638. raise EGLSLBumpShaderException.Create(strErrorEx + strMatLibNotDefined);
  639. end
  640. else
  641. begin
  642. SetSpecularTexture(FMaterialLibrary.TextureByName(Value));
  643. FSpecularTextureName := '';
  644. end;
  645. end;
  646. { TGLBaseCustomGLSLBumpShaderMT }
  647. function TGLBaseCustomGLSLBumpShaderMT.GetMainTextureName: TGLLibMaterialName;
  648. begin
  649. Result := FMaterialLibrary.GetNameOfTexture(FMainTexture);
  650. if Result = '' then Result := FMainTextureName;
  651. end;
  652. procedure TGLBaseCustomGLSLBumpShaderMT.Notification(
  653. AComponent: TComponent; Operation: TOperation);
  654. var
  655. Index: Integer;
  656. begin
  657. if Operation = opRemove then
  658. if AComponent = FMaterialLibrary then
  659. if FMaterialLibrary <> nil then
  660. begin
  661. //need to nil the textures that were ownned by it
  662. if FMainTexture <> nil then
  663. begin
  664. Index := FMaterialLibrary.Materials.GetTextureIndex(FMainTexture);
  665. if Index <> -1 then
  666. FMainTexture := nil;
  667. end;
  668. end;
  669. inherited;
  670. end;
  671. procedure TGLBaseCustomGLSLBumpShaderMT.SetMainTextureName(
  672. const Value: TGLLibMaterialName);
  673. begin
  674. if FMaterialLibrary = nil then
  675. begin
  676. FMainTextureName := Value;
  677. if not (csLoading in ComponentState) then
  678. raise EGLSLBumpShaderException.Create(strErrorEx + strMatLibNotDefined);
  679. end
  680. else
  681. begin
  682. FMainTexture := FMaterialLibrary.TextureByName(Value);
  683. FMainTextureName := '';
  684. end;
  685. end;
  686. procedure TGLBaseCustomGLSLBumpShaderMT.SetMaterialLibrary(
  687. const Value: TGLMaterialLibrary);
  688. begin
  689. inherited;
  690. if FMaterialLibrary <> nil then
  691. begin
  692. if FMainTextureName <> '' then
  693. SetMainTextureName(FMainTextureName);
  694. end
  695. else
  696. FMainTextureName := '';
  697. end;
  698. { TGLCustomGLSLBumpShaderAM }
  699. constructor TGLCustomGLSLBumpShaderAM.Create(AOwner: TComponent);
  700. begin
  701. inherited;
  702. FAmbientColor := TGLColor.Create(Self);
  703. FDiffuseColor := TGLColor.Create(Self);
  704. FSpecularColor := TGLColor.Create(Self);
  705. // Setup initial parameters.
  706. FAmbientColor.SetColor(0.15, 0.15, 0.15, 1);
  707. FDiffuseColor.SetColor(1, 1, 1, 1);
  708. FSpecularColor.SetColor(1, 1, 1, 1);
  709. end;
  710. destructor TGLCustomGLSLBumpShaderAM.Destroy;
  711. begin
  712. FAmbientColor.Destroy;
  713. FDiffuseColor.Destroy;
  714. FSpecularColor.Destroy;
  715. inherited;
  716. end;
  717. procedure TGLCustomGLSLBumpShaderAM.DoApply(var rci: TGLRenderContextInfo;
  718. Sender: TObject);
  719. begin
  720. inherited;
  721. Param['fvAmbient'].AsVector4f := FAmbientColor.Color;
  722. Param['fvDiffuse'].AsVector4f := FDiffuseColor.Color;
  723. Param['fvSpecular'].AsVector4f := FSpecularColor.Color;
  724. Param['baseMap'].AsTexture2D[0] := FMainTexture;
  725. end;
  726. procedure TGLCustomGLSLBumpShaderAM.DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject);
  727. begin
  728. GetVertexProgramCode(VertexProgram.Code);
  729. GetFragmentProgramCodeMP(FragmentProgram.Code, FSpecularTexture <> nil, FNormalTexture <> nil);
  730. VertexProgram.Enabled := True;
  731. FragmentProgram.Enabled := True;
  732. inherited;
  733. end;
  734. function TGLCustomGLSLBumpShaderAM.GetAlpha: Single;
  735. begin
  736. Result := (FAmbientColor.Alpha + FDiffuseColor.Alpha + FSpecularColor.Alpha) / 3;
  737. end;
  738. procedure TGLCustomGLSLBumpShaderAM.SetAlpha(const Value: Single);
  739. begin
  740. FAmbientColor.Alpha := Value;
  741. FDiffuseColor.Alpha := Value;
  742. FSpecularColor.Alpha := Value;
  743. end;
  744. { TGLCustomGLSLMLBumpShaderMT }
  745. constructor TGLCustomGLSLMLBumpShaderMT.Create(AOwner: TComponent);
  746. begin
  747. inherited;
  748. FLightSources := [1];
  749. FLightCompensation := 1;
  750. end;
  751. procedure TGLCustomGLSLMLBumpShaderMT.DoApply(var rci: TGLRenderContextInfo;
  752. Sender: TObject);
  753. begin
  754. inherited;
  755. Param['baseMap'].AsTexture2D[0] := FMainTexture;
  756. end;
  757. procedure TGLCustomGLSLMLBumpShaderMT.DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject);
  758. var
  759. I: Integer;
  760. lLightCount: Integer;
  761. begin
  762. GetMLVertexProgramCode(VertexProgram.Code);
  763. with FragmentProgram.Code do
  764. begin
  765. GetMLFragmentProgramCodeBeg(FragmentProgram.Code, FSpecularTexture <> nil, FNormalTexture <> nil);
  766. lLightCount := 0;
  767. // Repeat for all lights.
  768. for I := 0 to glsShaderMaxLightSources - 1 do
  769. if I + 1 in FLightSources then
  770. begin
  771. GetMLFragmentProgramCodeMid(FragmentProgram.Code, I);
  772. Inc(lLightCount);
  773. end;
  774. GetMLFragmentProgramCodeEnd(FragmentProgram.Code, lLightCount, FLightCompensation);
  775. end;
  776. VertexProgram.Enabled := True;
  777. FragmentProgram.Enabled := True;
  778. inherited;
  779. end;
  780. procedure TGLCustomGLSLMLBumpShaderMT.SetLightCompensation(
  781. const Value: Single);
  782. begin
  783. FLightCompensation := Value;
  784. FinalizeShader;
  785. end;
  786. procedure TGLCustomGLSLMLBumpShaderMT.SetLightSources(
  787. const Value: TGLLightSourceSet);
  788. begin
  789. Assert(Value <> [], strErrorEx + strShaderNeedsAtLeastOneLightSource);
  790. FLightSources := Value;
  791. FinalizeShader;
  792. end;
  793. { TGLCustomGLSLBumpShaderMT }
  794. procedure TGLCustomGLSLBumpShaderMT.DoApply(
  795. var rci: TGLRenderContextInfo; Sender: TObject);
  796. begin
  797. inherited;
  798. Param['baseMap'].AsTexture2D[0] := FMainTexture;
  799. end;
  800. procedure TGLCustomGLSLBumpShaderMT.DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject);
  801. begin
  802. GetVertexProgramCode(VertexProgram.Code);
  803. GetFragmentProgramCode(FragmentProgram.Code, FSpecularTexture <> nil, FNormalTexture <> nil);
  804. inherited;
  805. end;
  806. { TGLCustomGLSLBumpShader }
  807. procedure TGLCustomGLSLBumpShader.DoApply(var rci: TGLRenderContextInfo;
  808. Sender: TObject);
  809. begin
  810. inherited;
  811. Param['baseMap'].AsVector1i := 0; // Use the current texture.
  812. end;
  813. procedure TGLCustomGLSLBumpShader.DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject);
  814. begin
  815. GetVertexProgramCode(VertexProgram.Code);
  816. GetFragmentProgramCode(FragmentProgram.Code, FSpecularTexture <> nil, FNormalTexture <> nil);
  817. VertexProgram.Enabled := True;
  818. FragmentProgram.Enabled := True;
  819. inherited;
  820. end;
  821. function TGLCustomGLSLBumpShader.GetShaderAlpha: Single;
  822. begin
  823. //ignore
  824. Result := -1;
  825. end;
  826. procedure TGLCustomGLSLBumpShader.GetShaderColorParams(var AAmbientColor,
  827. ADiffuseColor, ASpecularcolor: TVector4f);
  828. begin
  829. //ignore
  830. AAmbientColor := NullHmgVector;
  831. ADiffuseColor := NullHmgVector;
  832. ASpecularcolor := NullHmgVector;
  833. end;
  834. procedure TGLCustomGLSLBumpShader.GetShaderTextures(
  835. var Textures: array of TGLTexture);
  836. begin
  837. Textures[0] := FNormalTexture;
  838. Textures[1] := FSpecularTexture;
  839. end;
  840. procedure TGLCustomGLSLBumpShader.GetShaderMiscParameters(var ACadencer: TGLCadencer;
  841. var AMatLib: TGLMaterialLibrary; var ALightSources: TGLLightSourceSet);
  842. begin
  843. ACadencer := nil;
  844. AMatLib := FMaterialLibrary;
  845. ALightSources := [0];
  846. end;
  847. procedure TGLCustomGLSLBumpShader.SetShaderAlpha(const Value: Single);
  848. begin
  849. //ignore
  850. end;
  851. procedure TGLCustomGLSLBumpShader.SetShaderColorParams(const AAmbientColor,
  852. ADiffuseColor, ASpecularcolor: TVector4f);
  853. begin
  854. //ignore
  855. end;
  856. procedure TGLCustomGLSLBumpShader.SetShaderMiscParameters(
  857. const ACadencer: TGLCadencer; const AMatLib: TGLMaterialLibrary;
  858. const ALightSources: TGLLightSourceSet);
  859. begin
  860. SetMaterialLibrary(AMatLib);
  861. end;
  862. procedure TGLCustomGLSLBumpShader.SetShaderTextures(
  863. const Textures: array of TGLTexture);
  864. begin
  865. SetNormalTexture(Textures[0]);
  866. SetSpecularTexture(Textures[1]);
  867. end;
  868. function TGLCustomGLSLBumpShader.GetShaderDescription: string;
  869. begin
  870. Result := 'ShaderTexture1 is NormalMap, ShaderTexture2 is SpecularMap'
  871. end;
  872. { TGLCustomGLSLMLBumpShader }
  873. constructor TGLCustomGLSLMLBumpShader.Create(AOwner: TComponent);
  874. begin
  875. inherited;
  876. FLightSources := [1];
  877. FLightCompensation := 1;
  878. end;
  879. procedure TGLCustomGLSLMLBumpShader.DoApply(var rci: TGLRenderContextInfo;
  880. Sender: TObject);
  881. begin
  882. inherited;
  883. Param['baseMap'].AsVector1i := 0; // Use the current texture.
  884. end;
  885. procedure TGLCustomGLSLMLBumpShader.DoInitialize(var rci : TGLRenderContextInfo; Sender : TObject);
  886. var
  887. I: Integer;
  888. lLightCount: Integer;
  889. begin
  890. GetMLVertexProgramCode(VertexProgram.Code);
  891. with FragmentProgram.Code do
  892. begin
  893. GetMLFragmentProgramCodeBeg(FragmentProgram.Code, FSpecularTexture <> nil, FNormalTexture <> nil);
  894. lLightCount := 0;
  895. // Repeat for all lights.
  896. for I := 0 to glsShaderMaxLightSources - 1 do
  897. if I + 1 in FLightSources then
  898. begin
  899. GetMLFragmentProgramCodeMid(FragmentProgram.Code, I);
  900. Inc(lLightCount);
  901. end;
  902. GetMLFragmentProgramCodeEnd(FragmentProgram.Code, lLightCount, FLightCompensation);
  903. end;
  904. VertexProgram.Enabled := True;
  905. FragmentProgram.Enabled := True;
  906. inherited;
  907. end;
  908. procedure TGLCustomGLSLMLBumpShader.SetLightCompensation(
  909. const Value: Single);
  910. begin
  911. FLightCompensation := Value;
  912. FinalizeShader;
  913. end;
  914. procedure TGLCustomGLSLMLBumpShader.SetLightSources(
  915. const Value: TGLLightSourceSet);
  916. begin
  917. Assert(Value <> [], strErrorEx + strShaderNeedsAtLeastOneLightSource);
  918. FLightSources := Value;
  919. FinalizeShader;
  920. end;
  921. function TGLCustomGLSLMLBumpShader.GetShaderAlpha: Single;
  922. begin
  923. //ignore
  924. Result := -1;
  925. end;
  926. procedure TGLCustomGLSLMLBumpShader.GetShaderColorParams(var AAmbientColor,
  927. ADiffuseColor, ASpecularcolor: TVector4f);
  928. begin
  929. //ignore
  930. AAmbientColor := NullHmgVector;
  931. ADiffuseColor := NullHmgVector;
  932. ASpecularcolor := NullHmgVector;
  933. end;
  934. function TGLCustomGLSLMLBumpShader.GetShaderDescription: string;
  935. begin
  936. Result := 'ShaderTexture1 is NormalMap, ShaderTexture2 is SpecularMap';
  937. end;
  938. procedure TGLCustomGLSLMLBumpShader.GetShaderMiscParameters(
  939. var ACadencer: TGLCadencer; var AMatLib: TGLMaterialLibrary;
  940. var ALightSources: TGLLightSourceSet);
  941. begin
  942. ACadencer := nil;
  943. AMatLib := FMaterialLibrary;
  944. ALightSources := FLightSources;
  945. end;
  946. procedure TGLCustomGLSLMLBumpShader.GetShaderTextures(
  947. var Textures: array of TGLTexture);
  948. begin
  949. Textures[0] := FNormalTexture;
  950. Textures[1] := FSpecularTexture;
  951. end;
  952. procedure TGLCustomGLSLMLBumpShader.SetShaderAlpha(const Value: Single);
  953. begin
  954. //ignore
  955. end;
  956. procedure TGLCustomGLSLMLBumpShader.SetShaderColorParams(const AAmbientColor,
  957. ADiffuseColor, ASpecularcolor: TVector4f);
  958. begin
  959. //ignore
  960. end;
  961. procedure TGLCustomGLSLMLBumpShader.SetShaderMiscParameters(
  962. const ACadencer: TGLCadencer; const AMatLib: TGLMaterialLibrary;
  963. const ALightSources: TGLLightSourceSet);
  964. begin
  965. SetMaterialLibrary(AMatLib);
  966. SetLightSources(ALightSources);
  967. end;
  968. procedure TGLCustomGLSLMLBumpShader.SetShaderTextures(
  969. const Textures: array of TGLTexture);
  970. begin
  971. SetNormalTexture(Textures[0]);
  972. SetSpecularTexture(Textures[1]);
  973. end;
  974. initialization
  975. RegisterClasses([TGLSLBumpShaderMT, TGLSLBumpShader, TGLSLBumpShaderAM,
  976. TGLSLMLBumpShader, TGLSLMLBumpShaderMT]);
  977. end.