aboutsummaryrefslogtreecommitdiff
path: root/CgFx/shaveHair.cgfx
blob: ba5806cdea4d2a272e90d367ec8425fa0f3e7167 (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
///////////////////////////////////////////////////////////////////////
// Shaders for regular hair
//
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
//////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////////////////////////////////////


const float4 guideCol = float4(0.0, 0.6, 0.32, 1.0);
const float4 guideSel = float4(0.26, 1.0, 0.63, 1.0);
const float4 knotCol = float4(0.78, 0.0, 0.78, 1.0);
const float4 knotSel = float4(1.0, 1.0, 0.0, 1.0);
const float4 brushCol = float4(1.0, 0.0, 0.0, 1.0);
const float3 greyCol  = float3(0.7, 0.7, 0.7);

const float pi = 3.14159;
const int nsegs = 24;

////////////////////////////////////////////////////////////////////////////////
// Parameters
////////////////////////////////////////////////////////////////////////////////


float4x4 WorldITXf : WorldInverseTranspose <string UIWidget = "none";>;
float4x4 WVPXf : WorldViewProjection <string UIWidget = "none";>;
float4x4 WVXf : WorldView <string UIWidget = "none";>;
float4x4 WorldXf : World <string UIWidget = "none";>;
float4x4 ViewIXf : ViewInverse <string UIWidget = "none";>;
//float3x3 NormalXf :  Normal <string UIWidget = "none";>;

bool gDimmed <
    string UIWidget = "Checkbox";
    string UIName = "UseSolidColor";
> = false;

bool gUseColor <
    string UIWidget = "Checkbox";
    string UIName = "UseSolidColor";
> = true;

bool gUseTexture <
    string UIWidget = "Checkbox";
    string UIName = "UseTexture";
> = false;


texture gTexture : Texture
<
    string UIName = "Diffuse";
>;


sampler2D gSampler : TextureSampler = sampler_state
{
    Texture = <gTexture>;
};


float4 gColor <
    string UIWidget = "Color";
    string UIName = "HairColor";
> = {0.0f, 0.01f, 0.27f, 1.0f};

float gAmbdiff <
    string UIWidget = "slider"; 
    string UIName = "Ambdiff";
> = 0.4f;

float gSpecular <
    string UIWidget = "slider"; 
    string UIName = "Specular";
> = 0.089f;

float gSpecularAmt <
    string UIWidget = "slider"; 
    string UIName = "Gloss";
> = 0.01; // 0.992f;

float3 gSpecularTint <
    string UIWidget = "Color";
    string UIName = "Specular Tint";
> = {1.0f, 1.0f, 1.0f};

float3 gSpecularTint2 <
    string UIWidget = "Color";
    string UIName = "Secondary Specular Tint";
> = {1.0f, 1.0f, 1.0f};

float3 gLightDir <
    string UIWidget = "none";
> = {0.0f, 0.0f, -1.0f};

float gGuideWidth <
    string UIWidget = "slider"; 
    string UIName = "GuideWidth";
> = 0.05f;

////////////////////////////////////////////////////////////////////////////////
// Structures
////////////////////////////////////////////////////////////////////////////////

// Vertex shader input structure.
struct VS_INPUT_Hair
{
    float3 Position : POSITION;
    float4 Color    : COLOR0;
    float2 UV       : TEXCOORD0;
    float3 Tangent  : NORMAL;
};

//Geometry shader 
struct GS_INPUT_Hair
{
    float3 Position : POSITION;
    float4 Color    : COLOR0;
    float2 UV       : TEXCOORD0;
    float3 Tangent  : TEXCOORD1;
};

// Fragment shader input
struct FS_INPUT_Hair
{
    float4 Position : POSITION;
    float4 Color    : COLOR0;
    float3 Tangent  : TEXCOORD0;
    float3 View     : TEXCOORD1;

};

/////////////////////////////////////////////////

struct VS_INPUT_instWire
{
    float3 Position : POSITION;
    
};

struct FS_INPUT_instWire
{
    float4 Position : POSITION;
    
};

/////////////////////////////////////////////////

struct VS_INPUT_instSolid
{
    float3 Position : POSITION; 
    float3 Normal   : NORMAL; 
    float2 UV       : TEXCOORD0;
};

struct FS_INPUT_instSolid
{
    float4 Position : POSITION;
    float2 UV       : TEXCOORD0;
    float3 Normal   : TEXCOORD1; 
};

/////////////////////////////////////////////////

struct VS_INPUT_Guides
{
    float3 Position : POSITION; /*NORMAL;*/
		float4 Color    : COLOR0;
};

struct GS_INPUT_Guides
{
    float3 Position : POSITION;
};

struct FS_INPUT_Guides
{
    float4 Position : POSITION;
		float  Sel    	: COLOR0;
};

///////////////////////////////////////////////////


struct VS_INPUT_Knots
{
    float3 Position : POSITION; 
    float4 Color    : COLOR0;
};

struct GS_INPUT_Knots
{
    float3 Position : POSITION;
};

struct FS_INPUT_Knots
{
    float4 Position : POSITION;
    float  Sel    	: COLOR0;
};

////////////////////////////////////////////////////

struct VS_INPUT_Brush
{
    float3 Position : POSITION; 
};

struct GS_INPUT_Brush
{
    float3 Position : POSITION;
};

struct FS_INPUT_Brush
{
    float4 Position : POSITION;
};

////////////////////////////////////////////////////////////////////////////////
//  Vertex shader - strands
////////////////////////////////////////////////////////////////////////////////

GS_INPUT_Hair vsHair (VS_INPUT_Hair In)
{
    GS_INPUT_Hair Out;
    
    Out.Position =  In.Position.xyz; 
    Out.Color = In.Color;
    Out.UV = In.UV;
    Out.Tangent = In.Tangent;

    
    return Out;
}

FS_INPUT_Hair vsHairPoly (VS_INPUT_Hair In)
{
    FS_INPUT_Hair Out;
    
    Out.Position =  mul(WVPXf, float4(In.Position.xyz,1.0)); 
    //Out.View = -normalize(mul(WVXf, float4(In.Position.xyz,1.0)).xyz);
    //Out.View = float3(0.0,0.0,0.0);
    Out.View = In.Position.xyz;
    
    Out.Color = In.Color;

    Out.Tangent = normalize(In.Tangent);
    //Out.Tangent = float3(0.0,0.0,0.0);
    //Out.Tangent = float3(1.0,0.0,0.0);
    //Out.Tangent = float3(1.0,1.0,1.0);
    //Out.Tangent = normalize(mul(WVXf, float4(In.Tangent,1.0)).xyz);
    //Out.Tangent = normalize(mul(NormalXf,In.Tangent));
    
    return Out;
}

////////////////////////////////////////////////////////////////////////////////
//  geometry shader - strands
////////////////////////////////////////////////////////////////////////////////

LINE TRIANGLE_OUT /*QUAD_OUT*/ void gsHair (AttribArray<GS_INPUT_Hair> In)
{
  
  FS_INPUT_Hair Out;
    
  float r0 = In[0].UV.x; //1.0;
  float r1 = In[1].UV.x; //1.0;
  
  float3 dp = In[1].Position.xyz - In[0].Position.xyz;
  
  float4 vi = mul(ViewIXf, float4(0.0, 0.0, -1.0,1.0));
  float4 vii = mul(ViewIXf, float4(0.0, 0.0, 0.0,1.0));
  float3 vn = normalize(vi.xyz-vii.xyz);
  
  float3 or0 = cross(In[0].Tangent, vn);
  float3 nr0 = normalize(or0);
  
  float3 or1 = cross(In[1].Tangent, vn);
  float3 nr1 = normalize(or1);

  
  float4 p0 = float4(In[0].Position - (nr0*r0), 1.0);
  float4 pw0 = mul(WVPXf, p0);
  float3 pv0 = -normalize(mul(WVXf, p0).xyz);
  
  
  float4 p1 = float4(In[1].Position - (nr1*r1), 1.0);
  float4 pw1 = mul(WVPXf, p1);
  float3 pv1 = -normalize(mul(WVXf, p1).xyz);
 
   float4 p2 = float4(In[0].Position + nr0*r0, 1.0);
   float4 pw2 = mul(WVPXf, p2);
   float3 pv2 = -normalize(mul(WVXf, p2).xyz);
   
   float4 p3 = float4(In[1].Position + nr1*r1, 1.0);
   float4 pw3 = mul(WVPXf, p3);
   float3 pv3 = -normalize(mul(WVXf, p3).xyz);
   
   //is something is wrong with NormalXf
   //float3 t0 = mul(NormalXf, In[0].Tangent);
   //float3 t1 = mul(NormalXf, In[1].Tangent);
   
   float3 pt0 = mul(WVXf, float4(In[0].Position,1.0)).xyz;
   float3 pt01 = mul(WVXf, float4(In[0].Position+In[0].Tangent,1.0)).xyz;
   float3 pt1 = mul(WVXf, float4(In[1].Position,1.0)).xyz;
   float3 pt11 = mul(WVXf, float4(In[1].Position+In[1].Tangent,1.0)).xyz;
   
   float3 t0 = normalize(pt01-pt0);
   float3 t1 = normalize(pt11-pt1);
   
   //first triangle
   Out.Position = pw0;
   Out.View = pv0;
   Out.Color = In[0].Color;
   Out.Tangent = t0;
   emitVertex(Out);

   Out.Position = pw1;
   Out.View = pv1;
   Out.Color = In[1].Color;
   Out.Tangent = t1;
   emitVertex(Out);

   Out.Position = pw2;
   Out.View = pv2;
   Out.Color = In[0].Color;
   Out.Tangent = t0;
   emitVertex(Out);
  
   //second triangle
   
   Out.Position = pw3;
   Out.View = pv3;
   Out.Color = In[1].Color;
   emitVertex(Out);
/*
   Out.Position = pw2;
   Out.View = pv2;
   Out.Color = In[0].Color;
   emitVertex(Out);
   
   Out.Position = pw1;
   Out.View = pv1;
   Out.Color = In[1].Color;
   Out.Tangent = t1;
   emitVertex(Out);
	*/
	
}

////////////////////////////////////////////////////////////////////////////////
//  Fragment shader - strands
////////////////////////////////////////////////////////////////////////////////

float4 fsHair (FS_INPUT_Hair In) : COLOR0
{
    if(gUseColor)
      return gColor;
    else {
    
    ////////////////////////
   // if(gDimmed)
   //   	return float4(In.Color.rgb*0.8, In.Color.a);
   // else
   //   	return In.Color;
    ////////////////////////
    
		float3 D = {0.0f,0.0f,0.0f};
		float3 S = {0.0f,0.0f,0.0f};
		float3 S2 = {0.0f,0.0f,0.0f};
		
			//float3 ldir = -gLightDir;
			//////////////////////////////
			float4 vi = mul(ViewIXf, float4(0.0, 0.0, 0.0, 1.0));
			float4 vii = mul(ViewIXf, float4(gLightDir,1.0));
			float3 ldir = -normalize(vi.xyz-vii.xyz);
			//float3 V = normalize(vi-In.View);
			float3 V = {0.0f,0.0f,0.0f};
			//////////////////////////////
			
			//diffuse 
			float diff  = 0.3f;
			float ltdot = dot(ldir, In.Tangent);
			//ltdot = 0.0f;
			float tsq = ltdot*ltdot;
			float shd2 = sqrt(1.0f - tsq);
			float shd = max(shd2, 0.0f);
			shd *= gAmbdiff;
			shd += (1.0f - gAmbdiff);
			D += shd;
			
			//specular 

			float K =  1.0f/(3.0f*(0.101f - gSpecular));
			float vtdot = dot(V, In.Tangent);
           
			float sqr_vdot2 = sqrt(1.0f - vtdot*vtdot);
			float sp = max(shd2*sqr_vdot2 - ltdot*vtdot, 0.0f);
			float spec = max(pow(sp, K), 0.0f);
			S += spec*float3(1.0,1.0,1.0);

			
			//secondary specular

			float3 ldir2 = normalize(ldir*0.7f+V*0.3f);
			float ltdot2 = dot(ldir2, In.Tangent);
			float sp2 = max(shd2*sqr_vdot2 - ltdot2*vtdot, 0.0f);
			float spec2 = max(pow(sp2, K), 0.0f);
			S2 += spec2*float3(1.0,1.0,1.0);
  
			
		if(D.r > 1.0f) D.r = 1.0f;
		if(D.g > 1.0f) D.g = 1.0f;
		if(D.b > 1.0f) D.b = 1.0f;
		
		if(S.r > 1.0f) S.r = 1.0f;
		if(S.g > 1.0f) S.g = 1.0f;
		if(S.b > 1.0f) S.b = 1.0f;
		
		if(S2.r > 1.0f) S2.r = 1.0f;
		if(S2.g > 1.0f) S2.g = 1.0f;
		if(S2.b > 1.0f) S2.b = 1.0f;
		
		float3 color = D*In.Color.rgb  + gSpecularAmt*(S*gSpecularTint + S2*gSpecularTint2);
		if(gDimmed) color *= 0.8f;
 
		return float4(color, In.Color.a);
		
		/*
		if(gDimmed)
      	return float4(In.Color.rgb*0.8, In.Color.a);
    else
      	return In.Color;       
     */
	}
}

////////////////////////////////////////////////////////////////////////////////
//  Vertex shader - instances wire
////////////////////////////////////////////////////////////////////////////////

FS_INPUT_instWire vsInstWire (VS_INPUT_instWire In) : COLOR0
{
    FS_INPUT_instWire Out;
    Out.Position =  mul(WVPXf, float4(In.Position.xyz,1.0)); 
    return Out;
}

////////////////////////////////////////////////////////////////////////////////
//  Fragment shader - instances wire
////////////////////////////////////////////////////////////////////////////////

float4 fsInstWire (FS_INPUT_instWire In) : COLOR0
{
      return gColor;
}

////////////////////////////////////////////////////////////////////////////////
//  Vertex shader - instances solid
////////////////////////////////////////////////////////////////////////////////

FS_INPUT_instSolid vsInstSolid (VS_INPUT_instSolid In) : COLOR0
{
    FS_INPUT_instSolid Out;
    Out.Position =  mul(WVPXf, float4(In.Position.xyz,1.0)); 
    Out.Normal = In.Normal;
    //Out.Normal = float3(1.0, 1.0, 1.0);
    Out.UV = In.UV;
    return Out;
}

////////////////////////////////////////////////////////////////////////////////
//  Fragment shader - instances solid
////////////////////////////////////////////////////////////////////////////////

float4 fsInstSolid (FS_INPUT_instSolid In) : COLOR0
{
	//float3 ldir = -gLightDir;
	//////////////////////////////
	float4 vi = mul(ViewIXf, float4(0.0, 0.0, 0.0, 1.0));
	float4 vii = mul(ViewIXf, float4(gLightDir,1.0));
	float3 ldir = -normalize(vi.xyz-vii.xyz);
	/////////////////////////////
	float ltdot = dot(ldir, In.Normal);
	/////////////////////////////////////
	if(gUseTexture){
		float4 C = tex2D(gSampler,In.UV);;
		return float4(C.xyz*ltdot,C.w);
	} else {
      return float4(greyCol*ltdot,1.0);
  }
}

////////////////////////////////////////////////////////////////////////////////
//  Vertex shader - guides
////////////////////////////////////////////////////////////////////////////////

GS_INPUT_Guides vsGuides (VS_INPUT_Guides In)
{
    GS_INPUT_Guides Out;
    Out.Position =  In.Position.xyz;
    return Out;
}

FS_INPUT_Guides vsGuidesPoly (VS_INPUT_Guides In)
{
    FS_INPUT_Guides Out;
    Out.Position =  mul(WVPXf, float4(In.Position.xyz,1.0)); 
    Out.Sel = In.Color.r;
    return Out;
}



////////////////////////////////////////////////////////////////////////////////
//  geometry shader - guides
////////////////////////////////////////////////////////////////////////////////

LINE TRIANGLE_OUT void gsGuides (AttribArray<GS_INPUT_Guides> In)
{
  
  FS_INPUT_Guides Out;
    
  float r = gGuideWidth; //0.05;
  
  
  float3 dp = In[1].Position.xyz - In[0].Position.xyz;
  float3 tg = normalize(dp);
  
  float4 vi = mul(ViewIXf, float4(0.0, 0.0, -1.0,1.0));
  float4 vii = mul(ViewIXf, float4(0.0, 0.0, 0.0,1.0));
  float3 vn = normalize(vi.xyz-vii.xyz);
  
  float3 or0 = cross(tg, vn);
  float3 nr0 = normalize(or0);
  
  //float3 or1 = cross(In[1].Tangent, vn);
  //float3 nr1 = normalize(or1);
  float3 nr1 = nr0;
  
  
  float4 p0 = float4(In[0].Position - (nr0*r), 1.0);
  float4 pw0 = mul(WVPXf, p0);
  
  float4 p1 = float4(In[1].Position - (nr1*r), 1.0);
  float4 pw1 = mul(WVPXf, p1);
 
   float4 p2 = float4(In[0].Position + nr0*r, 1.0);
   float4 pw2 = mul(WVPXf, p2);
   
   float4 p3 = float4(In[1].Position + nr1*r, 1.0);
   float4 pw3 = mul(WVPXf, p3);
   
   //first triangle
   Out.Position = pw0;
   emitVertex(Out);

   Out.Position = pw1;
   emitVertex(Out);

   Out.Position = pw2;
   emitVertex(Out);
  
   //second triangle
   
   //Out.Position = pw1;
   //emitVertex(Out);

   Out.Position = pw3;
   emitVertex(Out);

   //Out.Position = pw2;
   //emitVertex(Out);
}

////////////////////////////////////////////////////////////////////////////////
//  Fragment shader - guides
////////////////////////////////////////////////////////////////////////////////

float4 fsGuides (FS_INPUT_Guides In) : COLOR0
{
    if(In.Sel == 0.0)
			return guideCol;       
		else
			return guideSel;
}


////////////////////////////////////////////////////////////////////////////////
//  Vertex shader - knots
////////////////////////////////////////////////////////////////////////////////

GS_INPUT_Knots vsKnots (VS_INPUT_Knots In)
{
    GS_INPUT_Knots Out;
    Out.Position =  In.Position.xyz;//mul(WVPXf, float4(In.Position.xyz,1.0)); 
    return Out;
}


FS_INPUT_Knots vsKnotsPoly (VS_INPUT_Knots In)
{
    FS_INPUT_Knots Out;
    Out.Position =  mul(WVPXf, float4(In.Position.xyz,1.0)); 
    Out.Sel = In.Color.r;
    return Out;
}


////////////////////////////////////////////////////////////////////////////////
//  geometry shader - knots
////////////////////////////////////////////////////////////////////////////////

/*POINT*/ LINE TRIANGLE_OUT void gsKnots (AttribArray<GS_INPUT_Knots> In)
{
  
  FS_INPUT_Knots Out;
  
  float r = gGuideWidth*1.4; 
   
  
  float4 u = mul(ViewIXf, float4(0.0, 1.0, 0.0,1.0));
  float4 l = mul(ViewIXf, float4(1.0, 0.0, 0.0,1.0));
  float4 c = mul(ViewIXf, float4(0.0, 0.0, 0.0,1.0));
  float3 up = normalize(u.xyz-c.xyz);
  float3 left = normalize(l.xyz-c.xyz);
  
  float4 p0 = float4(In[0].Position + (up+left)*r, 1.0);
  float4 pw0 = mul(WVPXf, p0);
  
  float4 p1 = float4(In[0].Position + (up-left)*r, 1.0);
  float4 pw1 = mul(WVPXf, p1);
 
   float4 p2 = float4(In[0].Position + (-up-left)*r, 1.0);
   float4 pw2 = mul(WVPXf, p2);
   
   float4 p3 = float4(In[0].Position + (-up+left)*r, 1.0);
   float4 pw3 = mul(WVPXf, p3);
   
   //frist triangle
   Out.Position = pw0;
   Out.Position.z = 0.0;
   emitVertex(Out);

   Out.Position = pw1;
   //Out.Position.z = 0.0;
   emitVertex(Out);

   Out.Position = pw2;
   //Out.Position.z = 0.0;
   emitVertex(Out);
  
   //secon triangle
   Out.Position = pw2;
   //Out.Position.z = 0.0;
   emitVertex(Out);

   Out.Position = pw3;
   //Out.Position.z = 0.0;
   emitVertex(Out);

   Out.Position = pw0;
   //Out.Position.z = 0.0;
   emitVertex(Out);
}

////////////////////////////////////////////////////////////////////////////////
//  Fragment shader - knots
////////////////////////////////////////////////////////////////////////////////

float4 fsKnots (FS_INPUT_Knots In) : COLOR0
{
			if(In.Sel == 0.0)
				return knotCol;       
			else
				return knotSel;
}

////////////////////////////////////////////////////////////////////////////////
//  Vertex shader - brush
////////////////////////////////////////////////////////////////////////////////

/*POINT*/ LINE LINE_OUT void gsBrush (AttribArray<GS_INPUT_Brush> In)
{
  FS_INPUT_Brush Out;
  
  float R = 0.2;
  float Rx = In[1].Position.x;
  float Ry = In[1].Position.y;
  
  float4 v = mul(ViewIXf, float4(0.0, 0.0, 1.0,1.0));
  float4 u = mul(ViewIXf, float4(0.0, 1.0, 0.0,1.0));
  float4 l = mul(ViewIXf, float4(1.0, 0.0, 0.0,1.0));
  float4 c = mul(ViewIXf, float4(0.0, 0.0, 0.0,1.0));
  
  //////////////////////////////////
  //Out.Position = c;
  //emitVertex(Out);
  //Out.Position = v;
  //emitVertex(Out);
  //////////////////////////////////
  
  float3 up = normalize(u.xyz-c.xyz);
  float3 left = normalize(l.xyz-c.xyz);
  
  float dstep = 360.0f/nsegs;
  float rstep = dstep*pi/(180.0f);
  int pid = 0;
  
  for (int h = 0; h < nsegs; h++){
    int hh = (h+1)%nsegs;
    float a1 = rstep*(float)h;
    float a2 = rstep*(float)hh;

    float x1 = Rx*sin(a1);
    float y1 = Ry*cos(a1);

    float x2 = Rx*sin(a2);
    float y2 = Ry*cos(a2);
    
   // float4 p1 = mul(WVPXf, float4(x1, y1, 0.0,1.0));
   // float4 p2 = mul(WVPXf, float4(x2, y2, 0.0,1.0));
   
   //float4 p1 = float4(x1, y1, 0.0,1.0);
   //float4 p2 = float4(x2, y2, 0.0,1.0);
   
   float4 p1 = float4(In[0].Position.xyz, 0.0) + float4(x1, y1, 0.0,1.0);
   float4 p2 = float4(In[0].Position.xyz, 0.0) + float4(x2, y2, 0.0,1.0);
   
   //float4 p1 = float4(0.2, 0.0, 0.0, 0.0) + float4(x1, y1, 0.0,1.0);
   //float4 p2 = float4(x2, y2, 0.0,1.0);
  
  
    Out.Position = p1;
    Out.Position.z = 0.0;
    emitVertex(Out);
    
    Out.Position = p2;
    Out.Position.z = 0.0;
    emitVertex(Out);
  }
}

GS_INPUT_Brush vsBrush (VS_INPUT_Brush In)
{
    //FS_INPUT_Brush Out;
    GS_INPUT_Brush Out;
    Out.Position =  In.Position.xyz; // mul(WVPXf, float4(In.Position.xyz,1.0)); 
    return Out;
}

FS_INPUT_Brush vsBrushLine (VS_INPUT_Brush In)
{
    FS_INPUT_Brush Out;
    Out.Position = float4(In.Position.xyz,1.0);
    //Out.Position =  mul(WVPXf, float4(In.Position.xyz,1.0)); 
    Out.Position.z = 0.0;
    return Out;
}

float4 fsBrush (FS_INPUT_Brush In) : COLOR0
{
      return brushCol;       
}


////////////////////////////////////////////////////////////////////////////////
//  Techniques 
////////////////////////////////////////////////////////////////////////////////

technique StrandLines
{
    pass p0
    {
      AlphaBlendEnable = true;
      AlphaTestEnable = true;
       BlendEnable     = true;
       BlendFunc = int2(SrcAlpha, OneMinusSrcAlpha);
      // DepthTestEnable = true;
      // DepthMask       = true;
       CullFaceEnable  = false;

	//VertexShader = compile  gp4vp vsHair();
     	//GeometryProgram = compile gp4gp gsHair();

       	//VertexShader = compile  gp4vp vsHairPoly();
        //PixelShader = compile gp4fp fsHair();

	VertexShader = compile  glslv vsHairPoly();
        PixelShader = compile glslf fsHair();
        
    }
}

technique InstanceWire
{
    pass p0
    {
       //AlphaBlendEnable = true;
       CullFaceEnable  = false;

       //VertexShader    = compile gp4vp vsInstWire();
       //PixelShader     = compile gp4fp fsInstWire();

       VertexShader    = compile glslv vsInstWire();
       PixelShader     = compile glslf fsInstWire();
    }
}

technique InstanceSolid
{
    pass p0
    {
       CullFaceEnable  = false;
       AlphaBlendEnable = true;
       AlphaTestEnable = true;
       BlendEnable     = true;
       BlendFunc = int2(SrcAlpha, OneMinusSrcAlpha);

       //VertexShader    = compile gp4vp vsInstSolid();
       //PixelShader     = compile gp4fp fsInstSolid();
       
       VertexShader    = compile glslv vsInstSolid();
       PixelShader     = compile glslf fsInstSolid();
    }
}

technique Guides
{
    pass p0
    {
       //AlphaBlendEnable = true;
       CullFaceEnable  = false;
       

       //VertexShader    = compile gp4vp vsGuides();
       //GeometryProgram = compile gp4gp gsGuides();

       //VertexShader    = compile gp4vp vsGuidesPoly();
       //PixelShader     = compile gp4fp fsGuides();
    
       VertexShader    = compile glslv vsGuidesPoly();
       PixelShader     = compile glslf fsGuides();
    }
}

technique Knots
{
    pass p0
    {
       //AlphaBlendEnable = true;
       CullFaceEnable  = false;

       //VertexShader    = compile gp4vp vsKnots();
       //GeometryProgram = compile gp4gp gsKnots();

       VertexShader    = compile gp4vp vsKnotsPoly();
       PixelShader     = compile gp4fp fsKnots();
    
       VertexShader    = compile glslv vsKnotsPoly();
       PixelShader     = compile glslf fsKnots();

    }
}


technique Brush
{
    pass p0
    {
       //AlphaBlendEnable = true;
       CullFaceEnable  = false;

       //VertexShader    = compile gp4vp vsBrush();
       //GeometryProgram = compile gp4gp gsBrush();
       //PixelShader     = compile gp4fp fsBrush();
       
       VertexShader    = compile glslv vsBrushLine();
       PixelShader     = compile glslf fsBrush();
    }
}