Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/modes/shaders/common_hair_lib.glsl
| /** | /** | ||||
| * Library to create hairs dynamically from control points. | * Library to create hairs dynamically from control points. | ||||
| * This is less bandwidth intensive than fetching the vertex attributes | * This is less bandwidth intensive than fetching the vertex attributes | ||||
| * but does more ALU work per vertex. This also reduce the number | * but does more ALU work per vertex. This also reduce the number | ||||
| * of data the CPU has to precompute and transfert for each update. | * of data the CPU has to precompute and transfert for each update. | ||||
| **/ | */ | ||||
| /** | /** | ||||
| * hairStrandsRes: Number of points per hair strand. | * hairStrandsRes: Number of points per hair strand. | ||||
| * 2 - no subdivision | * 2 - no subdivision | ||||
| * 3+ - 1 or more interpolated points per hair. | * 3+ - 1 or more interpolated points per hair. | ||||
| **/ | */ | ||||
| uniform int hairStrandsRes = 8; | uniform int hairStrandsRes = 8; | ||||
| /** | /** | ||||
| * hairThicknessRes : Subdiv around the hair. | * hairThicknessRes : Subdiv around the hair. | ||||
| * 1 - Wire Hair: Only one pixel thick, independent of view distance. | * 1 - Wire Hair: Only one pixel thick, independent of view distance. | ||||
| * 2 - Polystrip Hair: Correct width, flat if camera is parallel. | * 2 - Polystrip Hair: Correct width, flat if camera is parallel. | ||||
| * 3+ - Cylinder Hair: Massive calculation but potentially perfect. Still need proper support. | * 3+ - Cylinder Hair: Massive calculation but potentially perfect. Still need proper support. | ||||
| **/ | */ | ||||
| uniform int hairThicknessRes = 1; | uniform int hairThicknessRes = 1; | ||||
| /* Hair thickness shape. */ | /* Hair thickness shape. */ | ||||
| uniform float hairRadRoot = 0.01; | uniform float hairRadRoot = 0.01; | ||||
| uniform float hairRadTip = 0.0; | uniform float hairRadTip = 0.0; | ||||
| uniform float hairRadShape = 0.5; | uniform float hairRadShape = 0.5; | ||||
| uniform bool hairCloseTip = true; | uniform bool hairCloseTip = true; | ||||
| Show All 24 Lines | |||||
| /* -- Subdivision stage -- */ | /* -- Subdivision stage -- */ | ||||
| /** | /** | ||||
| * We use a transform feedback to preprocess the strands and add more subdivision to it. | * We use a transform feedback to preprocess the strands and add more subdivision to it. | ||||
| * For the moment theses are simple smooth interpolation but one could hope to see the full | * For the moment theses are simple smooth interpolation but one could hope to see the full | ||||
| * children particle modifiers being evaluated at this stage. | * children particle modifiers being evaluated at this stage. | ||||
| * | * | ||||
| * If no more subdivision is needed, we can skip this step. | * If no more subdivision is needed, we can skip this step. | ||||
| **/ | */ | ||||
| #ifdef HAIR_PHASE_SUBDIV | #ifdef HAIR_PHASE_SUBDIV | ||||
| int hair_get_base_id(float local_time, int strand_segments, out float interp_time) | int hair_get_base_id(float local_time, int strand_segments, out float interp_time) | ||||
| { | { | ||||
| float time_per_strand_seg = 1.0 / float(strand_segments); | float time_per_strand_seg = 1.0 / float(strand_segments); | ||||
| float ratio = local_time / time_per_strand_seg; | float ratio = local_time / time_per_strand_seg; | ||||
| interp_time = fract(ratio); | interp_time = fract(ratio); | ||||
| Show All 29 Lines | if (id + 1 >= strand_segments) { | ||||
| data3 = data2 * 2.0 - data1; | data3 = data2 * 2.0 - data1; | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* -- Drawing stage -- */ | /* -- Drawing stage -- */ | ||||
| /** | /** | ||||
| * For final drawing, the vertex index and the number of vertex per segment | * For final drawing, the vertex index and the number of vertex per segment | ||||
| **/ | */ | ||||
| #ifndef HAIR_PHASE_SUBDIV | #ifndef HAIR_PHASE_SUBDIV | ||||
| int hair_get_strand_id(void) | int hair_get_strand_id(void) | ||||
| { | { | ||||
| return gl_VertexID / (hairStrandsRes * hairThicknessRes); | return gl_VertexID / (hairStrandsRes * hairThicknessRes); | ||||
| } | } | ||||
| int hair_get_base_id(void) | int hair_get_base_id(void) | ||||
| ▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines | |||||