/
shader.go
57 lines (50 loc) · 1.16 KB
/
shader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package texture
import (
_ "embed"
"unsafe"
"github.com/rajveermalviya/go-webgpu/wgpu"
)
//go:embed texture.wgsl
var TextureShaderCode string
type Vertex struct {
position [3]float32
texCoords [2]float32
}
var VertexBufferLayout = wgpu.VertexBufferLayout{
ArrayStride: uint64(unsafe.Sizeof(Vertex{})),
StepMode: wgpu.VertexStepMode_Vertex,
Attributes: []wgpu.VertexAttribute{
{
Offset: 0,
ShaderLocation: 0,
Format: wgpu.VertexFormat_Float32x3,
},
{
Offset: uint64(unsafe.Sizeof([3]float32{})),
ShaderLocation: 1,
Format: wgpu.VertexFormat_Float32x2,
},
},
}
var VERTICES = [...]Vertex{
{
position: [3]float32{-1.0, -1.0, 0.0}, // bottom left
texCoords: [2]float32{0.0, 1},
},
{
position: [3]float32{1.0, -1.0, 0.0}, // bottom right
texCoords: [2]float32{1.0, 1},
},
{
position: [3]float32{-1.0, 1.0, 0.0}, // top left
texCoords: [2]float32{0.0, 0},
},
{
position: [3]float32{1.0, 1.0, 0.0}, // top right
texCoords: [2]float32{1.0, 0},
},
}
var INDICES = [...]uint16{
0, 1, 2, // first triangle
2, 1, 3, // second triangle
}