# 2d light implemetations

**URL:** <https://forum.defold.com/t/2d-light-implemetations/3636>\
**Category:** Questions\
**Created:** [December 9, 2016, 8:22pm UTC](https://forum.defold.com/t/2d-light-implemetations/3636 "2016-12-09T20:22:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [December 11, 2016, 3:27pm UTC](https://forum.defold.com/t/2d-light-implemetations/3636/5 "2016-12-11T15:27:36Z")

</div>

You want to change the vertices in the _vertex_ shader. However, this is tricky, since 1) we’re using OpenGLES 2.0 which doesn’t feature gl\_VertexID, and 2) We currently only support 4 user defined constants per shader.

However, a simple test allowed me to modify the vertices of my box, using a custom material and custom shader. The yellow rectangle is the original location of my box, and the gradient polygon is my custom vertices (pretend there’s a light source in the bottom left corner):

 ![](https://forum-defold-uploads.b-cdn.net/original/2X/e/e48664a5a25712b5bc92a60f27402e32cd5dd0f4.png)

Setting render constants is straight forward. Copy the material and shaders you wish to use into your project (from the builtins folder), and then add extra constants into the material file. See the [manual](http://www.defold.com/manuals/materials/#_constants) for further reference.

In my test, I pass 3 constants: the center of the box, and the 4 vertices:

```lua
    go.set("#sprite", "center", vmath.vector4(pos.x, pos.y, 0, 0))
    go.set("#sprite", "p1p2", vmath.vector4(p1.x, p1.y, p2.x, p2.y))
    go.set("#sprite", "p3p4", vmath.vector4(p3.x, p3.y, p4.x, p4.y))

```

Using a technique this, you could render them into a stencil buffer an use that for rendering the scene. See this [flashlight example](https://forum.defold.com/t/making-a-flashlight/286/3)

I’ve uploaded this (very basic) example of the custom box [here](https://github.com/JCash/defoldexamples/tree/master/main/visibility)

Hopefully, we can soon render custom shapes a bit more easily 😉

---

_[View the full topic](https://forum.defold.com/t/2d-light-implemetations/3636)._
