Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_shader_material_volume_info.glsl « material « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e6d7b9d3721fac97e5335bc25abc8f1d18b15662 (plain)
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

/* Uniforms to convert smoke grid values into standard range. */
uniform vec3 volumeColor = vec3(1.0);
uniform vec2 volumeTemperature = vec2(0.0);

/* Generic volume attribute. */
void node_attribute_volume(sampler3D tex, mat4 transform, out vec3 outvec)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
  vec3 cos = volumeObjectLocalCoord;
#else
  vec3 cos = vec3(0.0);
#endif

  /* Optional per-grid transform. */
  if (transform[3][3] != 0.0) {
    cos = (transform * vec4(cos, 1.0)).xyz;
  }

  outvec = texture(tex, cos).rgb;
}

/* Special color attribute for smoke. */
void node_attribute_volume_color(sampler3D tex, mat4 transform, out vec3 outvec)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
  vec3 cos = volumeObjectLocalCoord;
#else
  vec3 cos = vec3(0.0);
#endif

  /* Optional per-grid transform. */
  if (transform[3][3] != 0.0) {
    cos = (transform * vec4(cos, 1.0)).xyz;
  }

  /* Density is premultiplied for interpolation, divide it out here. */
  vec4 value = texture(tex, cos).rgba;
  if (value.a > 1e-8) {
    value.rgb /= value.a;
  }

  outvec = value.rgb * volumeColor;
}

/* Special temperature attribute for smoke. */
void node_attribute_volume_temperature(sampler3D tex, mat4 transform, out float outf)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
  vec3 cos = volumeObjectLocalCoord;
#else
  vec3 cos = vec3(0.0);
#endif

  /* Optional per-grid transform. */
  if (transform[3][3] != 0.0) {
    cos = (transform * vec4(cos, 1.0)).xyz;
  }

  float value = texture(tex, cos).r;
  if (volumeTemperature.x < volumeTemperature.y) {
    outf = (value > 0.01) ?
               volumeTemperature.x + value * (volumeTemperature.y - volumeTemperature.x) :
               0.0;
  }
  else {
    outf = value;
  }
}