<p>You can do it by only rendering a flat plane and then making a grid in fragment shader. This is actually a nice exercise. </p>

<p>To get these two color values, you can use color selector, which is available in any graphic software for example MS Paint</p>

<p>Some code hints:</p>

<pre><code>vec2 coord = worldPos.xz / stepSize; //square size in world space
vec2 frac = fract(coord); //fractional parts of squares
//interpolation, grad is smoothness of line gradients
vec2 mult = smoothstep(0.0, grad, frac) - smoothstep(1.0-grad, 1.0, frac);
vec3 col = mix(col1, col2, mult.x * mult.y);
</code></pre>

CC BY-SA 4.0
2018-11-16T17:08:20.320Z
2018-11-16T17:08:20.320Z
mdkdy
<p>Make a tiling texture of a cross. When this texture repeats in all dimensions, it will make a grid-like pattern. Next render a ground plane as above and unwrap the texture on it with the appropriate tiling rate. Change the intensity of the color based on the dot product of the ground plane normal and the view direction to get the lighting/fade effect (you can experiment with different falloff functions and ranges).</p>

CC BY-SA 4.0
2018-11-16T07:16:17.220Z
2018-11-16T07:16:17.220Z
jeremyong
<p>This is easy to do in javascript or gl, but for expediency let's do it in mathematica. We first need the background image and an alpha mask:</p>

<pre><code>bg = ImageRotate[
   LinearGradientImage[
    RGBColor @@@ {{0.024, 0.051, 0.125}, {0.122, 0.078, 
       0.212}, {0.216, 0.102, 0.275}, {0.216, 0.102, 0.275}}, {300, 
     Round[300*1.394]}], -90 \[Degree]]

mask = ImageRotate[
   LinearGradientImage[{Sequence @@ Table[RGBColor[0, 0, 0, 0], 5],
     RGBColor[0.09, 0.07, 0.196, .3],
     RGBColor[0.09, 0.07, 0.196, .9], 
     RGBColor[0.023, 0.050, 0.125, 1]},
    {300, Round[300*1.394]}], 90 \[Degree]]
</code></pre>

<p><a href="https://i.sstatic.net/nTzUx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nTzUx.png" alt="enter image description here"></a></p>

<p>Now we can draw the grid in 3D space using infinite lines:</p>

<pre><code>grid[j_ : 5] := Module[{g3d, b},
  Overlay[{Image[bg, ImageSize -&gt; All], 
    g3d = Graphics3D[{Thickness[0.005],RGBColor[0.905, 0.352, 0.713],
       Sequence @@ Table[InfiniteLine[{{0, i + j, 0}, {1, i + j, 0}}], {i, -10, 20}],
       Table[InfiniteLine[{{i, 0, 0}, {i, 1, 0}}], {i, -20, 20}]}, 
      Boxed -&gt; False, ViewAngle -&gt; Pi/3, ViewVector -&gt; {{0, -5, 6}, {0, -1, 2}}, Background -&gt; None, PlotRange -&gt; All, ImageSize -&gt; is], 
    b = Blur[Rasterize[g3d, RasterSize -&gt; is], {20, 20}];
    Image[SetAlphaChannel[b, ColorNegate@ColorConvert[b, "Grayscale"]], 
     ImageSize -&gt; is]}, {1, 3, 2}]
  ]
</code></pre>

<p>Lastly, make some frames and export the animation:</p>

<pre><code>frames = Table[Overlay[{grid[j], Image[mask, ImageSize -&gt; All]}, All] , {j, 5, 6, .01}];
Export["~/grid.gif", frames, AnimationRepetitions -&gt; \[Infinity]]
</code></pre>

<p>Et voila!</p>

<p><a href="https://i.sstatic.net/mjZG8.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mjZG8.gif" alt="enter image description here"></a></p>

CC BY-SA 4.0
2020-03-09T08:29:11.970Z
I’m glad this fits your needs!
M.R.
CC BY-SA 4.0
2020-03-05T09:59:46.053Z
2020-03-05T09:59:46.053Z
M.R.
<p>I'm trying to write code (in any language) to render this 3D grid, matching the look and colors as closely as possible:</p>

<p><a href="https://i.sstatic.net/4vTSd.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4vTSd.jpg" alt="enter image description here"></a></p>

CC BY-SA 4.0
2018-11-10T03:41:47.577Z
What have you tried and what are you stuck on? We're not a code writing site, but we can help you figure things out if  you can be more specific about what you've tried. If you haven't tried  anything,  do that first and come back with questions about whatever isn't working.
user1118321
CC BY-SA 4.0
2020-03-05T05:50:58.550Z
@user1118321 since this is a simple problem, I might just write the solution here. Are there any other sites we can refer the user to that does share more code? If so perhaps I'll answer it there...
M.R.
<opengl><shader><3d><color>
How can I draw this style of grid?
user5601
# How can I draw this style of grid?

(Asked by: username_0 on 2018-11-10)

I'm trying to write code (in any language) to render this 3D grid, matching the look and colors as closely as possible:

[![enter image description here](https://i.sstatic.net/4vTSd.jpg)](https://i.sstatic.net/4vTSd.jpg)

**Tags:** opengl, shader, 3d, color

> **Comments:**
> **username_1**: What have you tried and what are you stuck on? We're not a code writing site, but we can help you figure things out if  you can be more specific about what you've tried. If you haven't tried  anything,  do that first and come back with questions about whatever isn't working.  
> **username_2**: @username_1 since this is a simple problem, I might just write the solution here. Are there any other sites we can refer the user to that does share more code? If so perhaps I'll answer it there...  

---

## 3 answers

### Answer by username_2 on 2020-03-05. Score: 4 | Accepted answer

This is easy to do in javascript or gl, but for expediency let's do it in mathematica. We first need the background image and an alpha mask:

```
bg = ImageRotate[
   LinearGradientImage[
    RGBColor @@@ {{0.024, 0.051, 0.125}, {0.122, 0.078, 
       0.212}, {0.216, 0.102, 0.275}, {0.216, 0.102, 0.275}}, {300, 
     Round[300*1.394]}], -90 \[Degree]]

mask = ImageRotate[
   LinearGradientImage[{Sequence @@ Table[RGBColor[0, 0, 0, 0], 5],
     RGBColor[0.09, 0.07, 0.196, .3],
     RGBColor[0.09, 0.07, 0.196, .9], 
     RGBColor[0.023, 0.050, 0.125, 1]},
    {300, Round[300*1.394]}], 90 \[Degree]]

```

[![enter image description here](https://i.sstatic.net/nTzUx.png)](https://i.sstatic.net/nTzUx.png)

Now we can draw the grid in 3D space using infinite lines:

```
grid[j_ : 5] := Module[{g3d, b},
  Overlay[{Image[bg, ImageSize -> All], 
    g3d = Graphics3D[{Thickness[0.005],RGBColor[0.905, 0.352, 0.713],
       Sequence @@ Table[InfiniteLine[{{0, i + j, 0}, {1, i + j, 0}}], {i, -10, 20}],
       Table[InfiniteLine[{{i, 0, 0}, {i, 1, 0}}], {i, -20, 20}]}, 
      Boxed -> False, ViewAngle -> Pi/3, ViewVector -> {{0, -5, 6}, {0, -1, 2}}, Background -> None, PlotRange -> All, ImageSize -> is], 
    b = Blur[Rasterize[g3d, RasterSize -> is], {20, 20}];
    Image[SetAlphaChannel[b, ColorNegate@ColorConvert[b, "Grayscale"]], 
     ImageSize -> is]}, {1, 3, 2}]
  ]

```

Lastly, make some frames and export the animation:

```
frames = Table[Overlay[{grid[j], Image[mask, ImageSize -> All]}, All] , {j, 5, 6, .01}];
Export["~/grid.gif", frames, AnimationRepetitions -> \[Infinity]]

```

Et voila!

[![enter image description here](https://i.sstatic.net/mjZG8.gif)](https://i.sstatic.net/mjZG8.gif)

> **Comments:**
> **username_2**: I’m glad this fits your needs!  

---

### Answer by username_3 on 2018-11-16. Score: 3

You can do it by only rendering a flat plane and then making a grid in fragment shader. This is actually a nice exercise.

To get these two color values, you can use color selector, which is available in any graphic software for example MS Paint

Some code hints:

```
vec2 coord = worldPos.xz / stepSize; //square size in world space
vec2 frac = fract(coord); //fractional parts of squares
//interpolation, grad is smoothness of line gradients
vec2 mult = smoothstep(0.0, grad, frac) - smoothstep(1.0-grad, 1.0, frac);
vec3 col = mix(col1, col2, mult.x * mult.y);

```


---

### Answer by username_4 on 2018-11-16. Score: 0

Make a tiling texture of a cross. When this texture repeats in all dimensions, it will make a grid-like pattern. Next render a ground plane as above and unwrap the texture on it with the appropriate tiling rate. Change the intensity of the color based on the dot product of the ground plane normal and the view direction to get the lighting/fade effect (you can experiment with different falloff functions and ranges).


---

