Debian Codegraph @

tests/data/inline_shader_code.x3dv

raw
1 #X3D V4.0 utf8
2 PROFILE Interchange
3
4 # Testcase from
5 # https://github.com/peardox/SimpleDelphiTest01
6 # https://github.com/castle-engine/castle-engine/issues/541
7
8 # ---------------------------------------------------------------------------
9 # Using a separate image that acts like a "mask" (overrides alpha channel)
10 # applied in a shader.
11 # This way you change the base image and the mask independently.
12 # ---------------------------------------------------------------------------
13
14 # Make things brighter.
15 PointLight {
16 intensity 5
17 location 0 0 10
18 }
19
20 # Define a Shape with Effect.
21 Shape {
22 appearance Appearance {
23 alphaMode "MASK"
24 # Another valid option would be "BLEND", this means that we use blending
25 # and can account for alpha being between 0 and 1.
26 #alphaMode "BLEND"
27 material PhysicalMaterial {
28 baseTexture ImageTexture {
29 url "textures/bread.png"
30 }
31 }
32 effects DEF MyEffect Effect {
33 language "GLSL"
34 initializeOnly SFNode mask_texture ImageTexture {
35 url "textures/cat_mask.png"
36 }
37 parts DEF MyPartWithInlineCode EffectPart {
38 type "FRAGMENT"
39 url "data:text/plain,
40 uniform sampler2D mask_texture;
41
42 void PLUG_texture_color(inout vec4 texture_color, const in sampler2D texture_in, const in vec4 tex_coord)
43 {
44 // For debugging, use this line to confirm that mask_texture is good.
45 // texture_color = texture2D(mask_texture, tex_coord.st);
46
47 /* The mask_texture is grayscale, we could access any (r,g,b) channel,
48 they all are equal. */
49 float alpha = texture2D(mask_texture, tex_coord.st).r;
50 texture_color = vec4(texture_color.xyz, alpha);
51 }"
52 }
53 }
54 }
55 geometry DEF MyQuadSet QuadSet {
56 solid FALSE
57 coord Coordinate { point [ -0.5 -0.5 0, 0.5 -0.5 0, 0.5 0.5 0, -0.5 0.5 0 ] }
58 }
59 }
60
61 # Reuse the effect, including mask texture, on another shape,
62 # with different base textre and different material color.
63
64 Transform {
65 translation 1 0 0
66 children Shape {
67 appearance Appearance {
68 alphaMode "MASK"
69 material PhysicalMaterial {
70 baseColor 1 0 0
71 baseTexture ImageTexture {
72 url "textures/floortiles.png"
73 }
74 }
75 effects USE MyEffect
76 }
77 geometry USE MyQuadSet
78 }
79 }
80
81 Transform {
82 translation 2 0 0
83 children Shape {
84 appearance Appearance {
85 alphaMode "MASK"
86 material PhysicalMaterial {
87 baseColor 1 1 0
88 baseTexture ImageTexture {
89 url "textures/tarmac_0.png"
90 }
91 normalTexture ImageTexture {
92 url "textures/tarmac_0_normalmap.png"
93 }
94 }
95 effects USE MyEffect
96 }
97 geometry USE MyQuadSet
98 }
99 }
100