This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/shaders/material/gpu_shader_material_geometry.glsl
Omar Emara 1c2f7b022a Cycles: Add Random Per Island attribute.
The Random Per Island attribute is a random float associated with each
connected component (island) of the mesh. It is particularly useful
when artists want to add variations to meshes composed of separate
units. Like tree leaves created using particle systems, wood planks
created using array modifiers, or abstract splines created using AN.

Reviewed By: Sergey Sharybin, Jacques Lucke

Differential Revision: https://developer.blender.org/D6154
2019-11-27 12:07:20 +02:00

49 lines
1.4 KiB
GLSL

void node_geometry(vec3 I,
vec3 N,
vec3 orco,
mat4 objmat,
mat4 toworld,
vec2 barycentric,
out vec3 position,
out vec3 normal,
out vec3 tangent,
out vec3 true_normal,
out vec3 incoming,
out vec3 parametric,
out float backfacing,
out float pointiness,
out float random_per_island)
{
/* handle perspective/orthographic */
vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
incoming = -(toworld * vec4(I_view, 0.0)).xyz;
#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
position = -incoming;
true_normal = normal = incoming;
tangent = parametric = vec3(0.0);
vec3(0.0);
backfacing = 0.0;
pointiness = 0.0;
#else
position = worldPosition;
# ifndef VOLUMETRICS
normal = normalize(N);
vec3 B = dFdx(worldPosition);
vec3 T = dFdy(worldPosition);
true_normal = normalize(cross(B, T));
# else
normal = (toworld * vec4(N, 0.0)).xyz;
true_normal = normal;
# endif
tangent_orco_z(orco, orco);
node_tangent(N, orco, objmat, tangent);
parametric = vec3(barycentric, 0.0);
backfacing = (gl_FrontFacing) ? 0.0 : 1.0;
pointiness = 0.5;
random_per_island = 0.0;
#endif
}