-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader.go
59 lines (51 loc) · 1.1 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
58
59
package shader
import "./gyu3d"
type PSColor uint32;
func (p PSColor) RGBA() (r, g, b, a uint32) {
x := uint32(p);
a = x >> 24;
a |= a << 8;
a |= a << 16;
r = (x >> 16) & 0xFF;
r |= r << 8;
r |= r << 16;
g = (x >> 8) & 0xFF;
g |= g << 8;
g |= g << 16;
b = x & 0xFF;
b |= b << 8;
b |= b << 16;
return;
}
func (p PSColor) Mul(f float) PSColor {
if (f<0) {f=0}
x := uint32(p);
a := x >> 24;
r := (x >> 16) & 0xFF;
g := (x >> 8) & 0xFF;
b := x & 0xFF;
r = uint32( float(r)*f );
g = uint32( float(g)*f );
b = uint32( float(b)*f );
if (r>255) {r = 255}
if (g>255) {g = 255}
if (b>255) {b = 255}
return PSColor((a<<24)|(r<<16)|(g<<8)|b);
}
type ShaderData interface {
GetVec3(index int) *gyu3d.Vec3;
GetVec4(index int) *gyu3d.Vec4;
GetTexCoord2D(index int) *gyu3d.TexCoord2D;
}
type PixelShader interface {
DoPixel(tu, tv, nx, ny, nz float) (PSColor, bool);
}
type VertexShader interface {
DoVertex(vsdata *ShaderData, g *gyu3d.G3DContext);
}
func TransformVertices(list []ShaderData, sh VertexShader, g *gyu3d.G3DContext) {
for i := range list {
d := list[i];
sh.DoVertex(&d, g);
}
}