-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmultitexture.py
75 lines (65 loc) · 2.04 KB
/
multitexture.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from omega import *
from euclid import *
from cyclops import *
from omegaToolkit import *
scene = getSceneManager()
scene.createProgramFromString("multiTexture",
# Vertex shader
'''
varying vec2 var_TexCoord;
void main(void)
{
gl_Position = ftransform();
var_TexCoord = gl_MultiTexCoord0.xy;
}
''',
# Fragment shader
'''
varying vec2 var_TexCoord;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform float texture1Weight;
uniform float texture2Weight;
uniform float texture3Weight;
void main (void)
{
vec4 c1 = texture1Weight * texture2D(texture1, var_TexCoord);
vec4 c2 = texture2Weight * texture2D(texture2, var_TexCoord);
vec4 c3 = texture3Weight * texture2D(texture3, var_TexCoord);
gl_FragColor = c1 + c2 + c3;
}
''')
plane = PlaneShape.create(0.8, 0.8)
plane.setPosition(Vector3(1, 2, -3))
# Attach three textures to the plane
material = plane.getMaterial()
material.setProgram("multiTexture")
material.setTexture("cyclops/test/checker.jpg", 0, "texture1")
material.setTexture("cyclops/test/soil0.jpg", 1, "texture2")
material.setTexture("cyclops/test/wall002.jpg", 2, "texture3")
texture1Weight = material.addUniform('texture1Weight', UniformType.Float)
texture2Weight = material.addUniform('texture2Weight', UniformType.Float)
texture3Weight = material.addUniform('texture3Weight', UniformType.Float)
texture1Weight.setFloat(1)
texture2Weight.setFloat(0)
texture3Weight.setFloat(0)
# Add transparency sliders
ui = UiModule.createAndInitialize().getUi()
c = Container.create(ContainerLayout.LayoutVertical, ui)
c.setPosition(Vector2(5, 20))
l1 = Label.create(c)
l1.setText("Texture 1 Opacity")
s1 = Slider.create(c)
s1.setTicks(10)
s1.setUIEventCommand("texture1Weight.setFloat(%value%.0 / 10)")
l2 = Label.create(c)
l2.setText("Texture 2 Opacity")
s2 = Slider.create(c)
s2.setTicks(10)
s2.setUIEventCommand("texture2Weight.setFloat(%value%.0 / 10)")
l3 = Label.create(c)
l3.setText("Texture 3 Opacity")
s3 = Slider.create(c)
s3.setTicks(10)
s3.setUIEventCommand("texture3Weight.setFloat(%value%.0 / 10)")