Light2D.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "Precompiled.h"
  5. #include "../Core/Context.h"
  6. #include "../Graphics/Graphics.h"
  7. #include "../Graphics/Viewport.h"
  8. #include "../Scene/Scene.h"
  9. #include "../Graphics/Camera.h"
  10. #include "../Graphics/Octree.h"
  11. #include "../Atomic2D/Light2D.h"
  12. #include "../Graphics/Renderer.h"
  13. #include "../Resource/XMLFile.h"
  14. #include "../Graphics/GraphicsEvents.h"
  15. #include "../Graphics/RenderPath.h"
  16. #include "../Graphics/Material.h"
  17. #include "../Graphics/Technique.h"
  18. #include "../Atomic2D/RigidBody2D.h"
  19. #include "../Atomic2D/Renderer2D.h"
  20. #include "../IO/Log.h"
  21. #include "../Resource/ResourceCache.h"
  22. namespace Atomic
  23. {
  24. extern const char* ATOMIC2D_CATEGORY;
  25. Light2D::Light2D(Context* context) : Component(context),
  26. castShadows_(false),
  27. softShadows_(false),
  28. softShadowLength_(2.5f),
  29. backtrace_(false)
  30. {
  31. SetNumRays(32);
  32. }
  33. Light2D::~Light2D()
  34. {
  35. }
  36. void Light2D::SetNumRays(int numRays)
  37. {
  38. rays_.Resize(numRays);
  39. }
  40. void Light2D::OnSetEnabled()
  41. {
  42. Component::OnSetEnabled();
  43. if (lightgroup_)
  44. lightgroup_->SetDirty();
  45. if (!enabled_)
  46. {
  47. vertices_.Clear();
  48. }
  49. }
  50. void Light2D::AddVertices(Vector<Vertex2D>& vertices)
  51. {
  52. vertices += vertices_;
  53. }
  54. void Light2D::RegisterObject(Context* context)
  55. {
  56. context->RegisterFactory<Light2D>(ATOMIC2D_CATEGORY);
  57. COPY_BASE_ATTRIBUTES(Component);
  58. }
  59. void Light2D::CastRays()
  60. {
  61. PhysicsWorld2D* physicsWorld = lightgroup_->GetPhysicsWorld();
  62. if (physicsWorld && castShadows_) {
  63. for (unsigned i = 0; i < rays_.Size(); i++) {
  64. Light2DRay& ray = rays_[i];
  65. Vector2 oend = ray.end_;
  66. float distance = (ray.end_ - ray.start_).Length();
  67. if (Abs(distance < .01f))
  68. distance = .01f;
  69. float bestDistance = 999999;
  70. PODVector<PhysicsRaycastResult2D> results;
  71. physicsWorld->Raycast(results, ray.start_, ray.end_);
  72. RigidBody2D* body = NULL;
  73. for (PODVector<PhysicsRaycastResult2D>::ConstIterator itr = results.Begin(); itr != results.End(); itr++)
  74. {
  75. const PhysicsRaycastResult2D& result = *itr;
  76. if (result.body_->GetCastShadows() && result.distance_ < distance && result.distance_ < bestDistance)
  77. {
  78. bestDistance = result.distance_;
  79. body = result.body_;
  80. ray.fraction_ = result.distance_ / distance;
  81. ray.end_.x_ = result.position_.x_;
  82. ray.end_.y_ = result.position_.y_;
  83. }
  84. }
  85. // backtracing can introduce artifacts, for now don't backtrace
  86. // on static hit... also, may need to clamp on a body size
  87. if (backtrace_ && body && body->GetBodyType() != BT_STATIC)
  88. {
  89. results.Clear();
  90. bestDistance = -999999;
  91. physicsWorld->Raycast(results, oend, ray.end_);
  92. for (PODVector<PhysicsRaycastResult2D>::ConstIterator itr = results.Begin(); itr != results.End(); itr++)
  93. {
  94. const PhysicsRaycastResult2D& result = *itr;
  95. if (result.distance_ > bestDistance && result.body_->GetBodyType() != BT_STATIC)
  96. {
  97. bestDistance = result.distance_;
  98. ray.fraction_ = (distance - result.distance_) / distance;
  99. ray.end_.x_ = result.position_.x_;
  100. ray.end_.y_ = result.position_.y_;
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. DirectionalLight2D::DirectionalLight2D(Context* context) : Light2D(context),
  108. direction_(-45.0f)
  109. {
  110. lightType_ = LIGHT2D_DIRECTIONAL;
  111. }
  112. DirectionalLight2D::~DirectionalLight2D()
  113. {
  114. }
  115. void DirectionalLight2D::RegisterObject(Context* context)
  116. {
  117. context->RegisterFactory<DirectionalLight2D>(ATOMIC2D_CATEGORY);
  118. COPY_BASE_ATTRIBUTES(Light2D);
  119. }
  120. void DirectionalLight2D::UpdateVertices()
  121. {
  122. vertices_.Clear();
  123. if (!lightgroup_ || !enabled_)
  124. return;
  125. const BoundingBox& frustumBox = lightgroup_->GetFrustumBox();
  126. float cos = Cos(direction_);
  127. float sin = Sin(direction_);
  128. float width = frustumBox.Size().x_;
  129. float height = frustumBox.Size().y_;
  130. float sizeOfScreen = width > height ? width : height;
  131. float xAxelOffSet = sizeOfScreen * cos;
  132. float yAxelOffSet = sizeOfScreen * sin;
  133. // preventing length <0 assertion error on box2d.
  134. if ((xAxelOffSet * xAxelOffSet < 0.1f) && (yAxelOffSet * yAxelOffSet < 0.1f)) {
  135. xAxelOffSet = 1;
  136. yAxelOffSet = 1;
  137. }
  138. float widthOffSet = sizeOfScreen * -sin;
  139. float heightOffSet = sizeOfScreen * cos;
  140. float x = (frustumBox.min_.x_ + frustumBox.max_.x_) * 0.5f - widthOffSet;
  141. float y = (frustumBox.min_.y_ + frustumBox.max_.y_) * 0.5f - heightOffSet;
  142. unsigned rayNum = rays_.Size();
  143. float portionX = 2.0f * widthOffSet / (rayNum - 1);
  144. x = (floorf(x / (portionX * 2))) * portionX * 2;
  145. float portionY = 2.0f * heightOffSet / (rayNum - 1);
  146. y = (ceilf(y / (portionY * 2))) * portionY * 2;
  147. for (unsigned i = 0; i < rayNum; i++)
  148. {
  149. Light2DRay& ray = rays_[i];
  150. float steppedX = float(i) * portionX + x;
  151. float steppedY = float(i) * portionY + y;
  152. ray.start_.x_ = steppedX - xAxelOffSet;
  153. ray.start_.y_ = steppedY - yAxelOffSet;
  154. ray.end_.x_ = steppedX + xAxelOffSet;
  155. ray.end_.y_ = steppedY + yAxelOffSet;
  156. ray.fraction_ = 0.0f;
  157. }
  158. CastRays();
  159. Vertex2D vertex0;
  160. Vertex2D vertex1;
  161. Vertex2D vertex2;
  162. Vertex2D vertex3;
  163. vertex0.color_ = vertex1.color_ = vertex2.color_ = vertex3.color_ = color_.ToUInt();
  164. for (unsigned i = 0; i < rayNum - 1; i++) {
  165. Light2DRay& ray0 = rays_[i];
  166. Light2DRay& ray1 = rays_[i + 1];
  167. vertex0.position_ = Vector3( ray0.start_.x_, ray0.start_.y_, 0.0f);
  168. vertex1.position_ = Vector3( ray0.end_.x_, ray0.end_.y_, 0.0f);
  169. vertex2.position_ = Vector3( ray1.start_.x_, ray1.start_.y_, 0.0f);
  170. vertex3.position_ = Vector3( ray1.end_.x_, ray1.end_.y_, 0.0f);
  171. vertex0.uv_.x_ = 1.0f;
  172. vertex2.uv_.x_ = 1.0 ;
  173. vertex1.uv_.x_ = 1.0f;
  174. vertex3.uv_.x_ = 1.0f;
  175. vertices_.Push(vertex0);
  176. vertices_.Push(vertex1);
  177. vertices_.Push(vertex3);
  178. vertices_.Push(vertex0);
  179. vertices_.Push(vertex3);
  180. vertices_.Push(vertex2);
  181. }
  182. if (softShadows_ && castShadows_)
  183. {
  184. unsigned uambient = lightgroup_->GetAmbientColor().ToUInt();
  185. // THIS CAN BE OPTIMIZED!
  186. for (unsigned i = 0; i < rays_.Size() - 1; i++) {
  187. Light2DRay& ray0 = rays_[i];
  188. Light2DRay& ray1 = rays_[i + 1];
  189. vertex0.position_ = Vector3( ray0.end_.x_, ray0.end_.y_, 0.0f);
  190. Vector2 v0 = (ray0.end_ - ray0.start_).Normalized();
  191. Vector2 v1 = (ray1.end_ - ray1.start_).Normalized();
  192. vertex1.position_ = Vector3( ray0.end_.x_ + v0.x_ * softShadowLength_,
  193. ray0.end_.y_ + v0.y_ * softShadowLength_, 0.0f);
  194. vertex2.position_ = Vector3( ray1.end_.x_ + v1.x_ * softShadowLength_,
  195. ray1.end_.y_ + v1.y_ * softShadowLength_, 0.0f);
  196. vertex3.position_ = Vector3( ray1.end_.x_, ray1.end_.y_, 0.0f);
  197. vertex0.color_ = 0;
  198. vertex3.color_ = 0;
  199. vertex0.uv_.x_ = 0;
  200. vertex3.uv_.x_ = 0;
  201. vertex1.color_ = 0;
  202. vertex2.color_ = 0;
  203. vertex1.uv_.x_ = 1.0;
  204. vertex2.uv_.x_ = 1.0;
  205. vertices_.Push(vertex0);
  206. vertices_.Push(vertex1);
  207. vertices_.Push(vertex2);
  208. vertices_.Push(vertex0);
  209. vertices_.Push(vertex2);
  210. vertices_.Push(vertex3);
  211. }
  212. }
  213. }
  214. PositionalLight2D::PositionalLight2D(Context* context) : Light2D(context)
  215. {
  216. }
  217. PositionalLight2D::~PositionalLight2D()
  218. {
  219. }
  220. void PositionalLight2D::RegisterObject(Context* context)
  221. {
  222. context->RegisterFactory<PositionalLight2D>(ATOMIC2D_CATEGORY);
  223. COPY_BASE_ATTRIBUTES(Light2D);
  224. }
  225. void PositionalLight2D::UpdateVertices()
  226. {
  227. vertices_.Clear();
  228. if (!lightgroup_ || !enabled_)
  229. return;
  230. CastRays();
  231. Vertex2D vertex0;
  232. Vertex2D vertex1;
  233. Vertex2D vertex2;
  234. Vertex2D vertex3;
  235. vertex0.color_ = vertex1.color_ = vertex2.color_ = vertex3.color_ = color_.ToUInt();
  236. for (unsigned i = 0; i < rays_.Size() - 1; i++) {
  237. Light2DRay& ray0 = rays_[i];
  238. Light2DRay& ray1 = rays_[i + 1];
  239. vertex0.position_ = Vector3( ray0.start_.x_, ray0.start_.y_, 0.0f);
  240. vertex1.position_ = Vector3( ray0.end_.x_, ray0.end_.y_, 0.0f);
  241. vertex2.position_ = Vector3( ray1.end_.x_, ray1.end_.y_, 0.0f);
  242. vertex0.uv_.x_ = 1.0f;
  243. vertex1.uv_.x_ = 1.0f - ray0.fraction_;
  244. vertex2.uv_.x_ = 1.0f - ray1.fraction_;
  245. vertices_.Push(vertex0);
  246. vertices_.Push(vertex1);
  247. vertices_.Push(vertex2);
  248. }
  249. if (softShadows_ && castShadows_)
  250. {
  251. // THIS CAN BE OPTIMIZED!
  252. for (unsigned i = 0; i < rays_.Size(); i++) {
  253. Light2DRay& ray0 = rays_[i];
  254. Light2DRay& ray1 = rays_[i + 1 == rays_.Size() ? 0 : i + 1];
  255. float s0 = (1.0f - ray0.fraction_);
  256. float s1 = (1.0f - ray1.fraction_);
  257. vertex0.position_ = Vector3( ray0.end_.x_, ray0.end_.y_, 0.0f);
  258. vertex1.position_ = Vector3( ray0.end_.x_ + s0 * softShadowLength_ * ray0.cos_,
  259. (ray0.end_.y_ + s0 * softShadowLength_ * ray0.sin_), 0.0f);
  260. vertex2.position_ = Vector3( ray1.end_.x_ + s1 * softShadowLength_ * ray1.cos_,
  261. (ray1.end_.y_ + s1 * softShadowLength_ * ray1.sin_), 0.0f);
  262. vertex3.position_ = Vector3( ray1.end_.x_, ray1.end_.y_, 0.0f);
  263. vertex1.uv_.x_ = 0;
  264. vertex2.uv_.x_ = 0;
  265. vertex1.color_ = 0x00000000;
  266. vertex2.color_ = 0x00000000;
  267. // darkness of shadow, we should break this all out of uint
  268. vertex0.uv_.x_ = s0 * .65f;
  269. vertex3.uv_.x_ = s1 * .65f;
  270. vertices_.Push(vertex0);
  271. vertices_.Push(vertex1);
  272. vertices_.Push(vertex2);
  273. vertices_.Push(vertex0);
  274. vertices_.Push(vertex2);
  275. vertices_.Push(vertex3);
  276. }
  277. }
  278. }
  279. PointLight2D::PointLight2D(Context* context) : PositionalLight2D(context),
  280. radius_(1.0f)
  281. {
  282. lightType_ = LIGHT2D_POINT;
  283. }
  284. PointLight2D::~PointLight2D()
  285. {
  286. }
  287. void PointLight2D::RegisterObject(Context* context)
  288. {
  289. context->RegisterFactory<PointLight2D>(ATOMIC2D_CATEGORY);
  290. COPY_BASE_ATTRIBUTES(PositionalLight2D);
  291. }
  292. void PointLight2D::UpdateVertices()
  293. {
  294. vertices_.Clear();
  295. if (!lightgroup_ || !enabled_)
  296. return;
  297. const PhysicsWorld2D* physicsWorld = lightgroup_->GetPhysicsWorld();
  298. const Node* lightNode = GetNode();
  299. Vector2 start = lightNode->GetWorldPosition2D();
  300. float angleNum = 360.0f / float((rays_.Size() - 1));
  301. for (unsigned i = 0; i < rays_.Size(); i++) {
  302. float angle = angleNum * i;
  303. Light2DRay& ray = rays_[i];
  304. ray.start_ = start;
  305. ray.sin_ = Sin(angle);
  306. ray.cos_ = Cos(angle);
  307. ray.end_.x_ = ray.start_.x_ + radius_ * ray.cos_;
  308. ray.end_.y_ = ray.start_.y_ + radius_ * ray.sin_;
  309. ray.fraction_ = 1.0f;
  310. }
  311. PositionalLight2D::UpdateVertices();
  312. }
  313. void Light2DGroup::RegisterObject(Context* context)
  314. {
  315. context->RegisterFactory<Light2DGroup>(ATOMIC2D_CATEGORY);
  316. COPY_BASE_ATTRIBUTES(Drawable2D);
  317. }
  318. void Light2DGroup::OnNodeSet(Node* node)
  319. {
  320. // Do not call Drawable2D::OnNodeSet(node)
  321. if (node)
  322. {
  323. if (renderer_.Null())
  324. {
  325. renderer_ = node->GetOrCreateComponent<Renderer2D>();
  326. renderer_->SetUseTris(true);
  327. }
  328. if (light2DMaterial_.Null())
  329. CreateLight2DMaterial();
  330. Scene* scene = GetScene();
  331. if (scene)
  332. {
  333. if (IsEnabledEffective())
  334. renderer_->AddDrawable(this);
  335. }
  336. node->AddListener(this);
  337. }
  338. else
  339. {
  340. if (renderer_)
  341. renderer_->RemoveDrawable(this);
  342. }
  343. }
  344. Light2DGroup::Light2DGroup(Context* context) : Drawable2D(context),
  345. ambientColor_(0, 0, 0, 0),
  346. frustum_(0)
  347. {
  348. SubscribeToEvent(E_BEGINRENDERING, HANDLER(Light2DGroup, HandleBeginRendering));
  349. SubscribeToEvent(E_BEGINVIEWUPDATE, HANDLER(Light2DGroup, HandleBeginViewUpdate));
  350. }
  351. Light2DGroup::~Light2DGroup()
  352. {
  353. Renderer* renderer = GetSubsystem<Renderer>();
  354. if (renderer)
  355. {
  356. Viewport* viewport = renderer->GetViewport(0);
  357. if (viewport)
  358. {
  359. RenderPath* renderpath = viewport->GetRenderPath();
  360. if (renderpath)
  361. renderpath->RemoveCommands("Light2D");
  362. }
  363. }
  364. }
  365. void Light2DGroup::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData)
  366. {
  367. using namespace BeginViewUpdate;
  368. Scene* scene = GetScene();
  369. // Check that we are updating the correct scene
  370. if (scene != eventData[P_SCENE].GetPtr())
  371. return;
  372. Camera* camera = static_cast<Camera*>(eventData[P_CAMERA].GetPtr());
  373. frustum_ = &camera->GetFrustum();
  374. if (camera->IsOrthographic())// && camera->GetNode()->GetWorldDirection() == Vector3::FORWARD)
  375. {
  376. // Define bounding box with min and max points
  377. // todo: handle rotation
  378. frustumBoundingBox_.Define(frustum_->vertices_[2], frustum_->vertices_[4]);
  379. }
  380. }
  381. void Light2DGroup::HandleBeginRendering(StringHash eventType, VariantMap& eventData)
  382. {
  383. verticesDirty_ = true;
  384. }
  385. void Light2DGroup::OnWorldBoundingBoxUpdate()
  386. {
  387. boundingBox_.Define(-M_LARGE_VALUE, M_LARGE_VALUE);
  388. worldBoundingBox_.Define(-M_LARGE_VALUE, M_LARGE_VALUE);
  389. }
  390. void Light2DGroup::UpdateVertices()
  391. {
  392. // This is the shadow map
  393. if (!verticesDirty_)
  394. return;
  395. vertices_.Clear();
  396. for (Vector<WeakPtr<Light2D> >::Iterator itr = lights_.Begin(); itr != lights_.End(); itr++)
  397. {
  398. Light2D* light = *itr;
  399. if (!light->IsEnabled())
  400. continue;
  401. light->UpdateVertices();
  402. light->AddVertices(vertices_);
  403. }
  404. verticesDirty_ = false;
  405. }
  406. void Light2DGroup::AddLight(Light2D* light)
  407. {
  408. for (Vector<WeakPtr<Light2D> >::ConstIterator itr = lights_.Begin(); itr != lights_.End(); itr++)
  409. if (*itr == light)
  410. return;
  411. light->SetLightGroup(this);
  412. lights_.Push(WeakPtr<Light2D>(light));
  413. }
  414. void Light2DGroup::SetPhysicsWorld(PhysicsWorld2D* physicsWorld)
  415. {
  416. physicsWorld_ = physicsWorld;
  417. }
  418. void Light2DGroup::SetAmbientColor(const Color& color)
  419. {
  420. if (color == ambientColor_)
  421. return;
  422. ambientColor_ = color;
  423. Renderer* renderer = GetSubsystem<Renderer>();
  424. // only on main viewport atm and viewport must first be set
  425. if (renderer)
  426. {
  427. Viewport* viewport = renderer->GetViewport(0);
  428. if (viewport)
  429. {
  430. RenderPath* renderpath = viewport->GetRenderPath();
  431. renderpath->SetShaderParameter("ShadowAmbient", ambientColor_);
  432. }
  433. }
  434. }
  435. void Light2DGroup::CreateLight2DMaterial()
  436. {
  437. Renderer* renderer = GetSubsystem<Renderer>();
  438. // only on main viewport atm and viewport must first be set
  439. Viewport* viewport = renderer->GetViewport(0);
  440. RenderPath* renderpath = viewport->GetRenderPath();
  441. RenderTargetInfo ntarget;
  442. ntarget.enabled_ = true;
  443. ntarget.name_ = "light2dtarget";
  444. ntarget.tag_ = "Light2D";
  445. ntarget.format_ = Graphics::GetRGBAFormat();
  446. ntarget.sizeMode_ = SIZE_VIEWPORTDIVISOR;
  447. ntarget.size_ = Vector2(4, 4);
  448. // try true
  449. ntarget.filtered_ = false;
  450. renderpath->AddRenderTarget(ntarget);
  451. RenderPathCommand clearCommand;
  452. clearCommand.tag_ = "Light2D";
  453. clearCommand.type_ = CMD_CLEAR;
  454. clearCommand.clearColor_ = Color(0, 0, 0, 0);
  455. clearCommand.clearFlags_ = CLEAR_COLOR;
  456. clearCommand.enabled_ = true;
  457. clearCommand.SetNumOutputs(1);
  458. clearCommand.SetOutputName(0, "light2dtarget");
  459. renderpath->AddCommand(clearCommand);
  460. RenderPathCommand passCommand;
  461. passCommand.tag_ = "Light2D";
  462. passCommand.type_ = CMD_SCENEPASS;
  463. passCommand.pass_ = "light2d";
  464. passCommand.enabled_ = true;
  465. passCommand.SetNumOutputs(1);
  466. passCommand.SetOutputName(0, "light2dtarget");
  467. renderpath->AddCommand(passCommand);
  468. ResourceCache* cache = GetSubsystem<ResourceCache>();
  469. XMLFile* light2DBlur = cache->GetResource<XMLFile>("PostProcess/Light2DBlur.xml");
  470. renderpath->Append(light2DBlur);
  471. RenderPathCommand copyCommand;
  472. copyCommand.enabled_ = true;
  473. copyCommand.tag_ = "Light2D";
  474. copyCommand.type_ = CMD_QUAD;
  475. copyCommand.vertexShaderName_ = "Shadow2D";
  476. copyCommand.pixelShaderName_ = "Shadow2D";
  477. copyCommand.SetTextureName(TU_DIFFUSE, "viewport");
  478. copyCommand.SetTextureName(TU_EMISSIVE, "light2dtarget");
  479. copyCommand.SetShaderParameter("ShadowAmbient", ambientColor_);
  480. copyCommand.SetNumOutputs(1);
  481. copyCommand.SetOutputName(0, "viewport");
  482. renderpath->AddCommand(copyCommand);
  483. light2DMaterial_ = new Material(context_);
  484. light2DMaterial_->SetName("Light2DMaterial");
  485. Technique* tech = new Technique(context_);
  486. Pass* pass = tech->CreatePass(PASS_LIGHT2D);
  487. pass->SetBlendMode(BLEND_ADDALPHA);
  488. pass->SetDepthTestMode(CMP_ALWAYS);
  489. pass->SetVertexShader("Light2D");
  490. pass->SetPixelShader("Light2D");
  491. pass->SetDepthWrite(false);
  492. light2DMaterial_->SetTechnique(0, tech);
  493. light2DMaterial_->SetCullMode(CULL_NONE);
  494. SetCustomMaterial(light2DMaterial_);
  495. }
  496. }