‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
gfx_shared.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\filter_shared;
5 #using scripts\shared\math_shared;
6 #using scripts\shared\system_shared;
7 #using scripts\shared\util_shared;
8 
9 #insert scripts\shared\shared.gsh;
10 
11 #namespace gfx;
12 
13 
14 //-----------------------------------------------------------------------------------------------------------
15 
16 function ‪SetStage( localClientNum, bundle, filterid, stagePrefix, stageLength, accumTime, totalAccumTime, setConstants )
17 {
18  num_consts = ‪Gfx::GetStructFieldOrZero( bundle, stagePrefix + "num_consts" );
19  for ( constIdx = 0 ; constIdx < num_consts ; constIdx++ )
20  {
21  constPrefix = stagePrefix + "c";
22  if ( constIdx < 10 ) constPrefix += "0";
23  constPrefix += constIdx + "_";
24 
25  startValue = ‪gfx::getShaderConstantValue( bundle, constPrefix, "start", false );
26  endValue = ‪gfx::getShaderConstantValue( bundle, constPrefix, "end", false );
27  delays = ‪gfx::getShaderConstantValue( bundle, constPrefix, "delay", true );
28 
29  channels = GetStructField( bundle, constPrefix + "channels" );
30  isColor = IsString( channels ) && ( channels == "color" || channels == "color+alpha" );
31 
32  animName = GetStructField( bundle, constPrefix + "anm" );
33 
34  values = [];
35  for ( i=0 ; i<4 ; i++ )
36  values[i] = 0;
37 
38  // Ease in/out: http://gizma.com/easing/
39  for ( chanIdx = 0 ; chanIdx < startValue.size ; chanIdx++ )
40  {
41  delayTime = delays[ ( isColor ? 0 : chanIdx ) ] * 1000;
42 
43  if ( accumTime > delayTime && stageLength > delayTime )
44  {
45  timeRatio = ( accumTime - delayTime ) / ( stageLength - delayTime );
46  timeRatio = ‪math::clamp( timeRatio, 0, 1 );
47 
48  lerpRatio = 0.0;
49  delta = endValue[ chanIdx ] - startValue[ chanIdx ];
50 
51  switch ( animName )
52  {
53  case "linear":
54  lerpRatio = timeRatio;
55  break;
56 
57  case "step":
58  lerpRatio = 1;
59  break;
60 
61  case "ease in":
62  // quadratic ease in
63  lerpRatio = timeRatio * timeRatio;
64  break;
65 
66  case "ease out":
67  // quadratic ease out
68  lerpRatio = -timeRatio * ( timeRatio - 2 );
69  break;
70 
71  case "ease inout":
72  // quadratic easing in/out
73  timeRatio *= 2;
74  if ( timeRatio < 1 )
75  {
76  lerpRatio = 0.5 * lerpRatio * lerpRatio;
77  }
78  else
79  {
80  timeRatio -= 1;
81  lerpRatio = -0.5 * ( lerpRatio * ( lerpRatio - 2 ) - 1 );
82  }
83  break;
84 
85  case "linear repeat":
86  lerpRatio = timeRatio;
87  break;
88 
89  case "linear mirror":
90  if ( timeRatio > 0.5 )
91  lerpRatio = 1.0 - timeRatio;
92  else
93  lerpRatio = timeRatio;
94  break;
95 
96  case "sin":
97  lerpRatio = 0.5 - 0.5*cos( 360.0 * timeRatio );
98  break;
99 
100  default: // "hold"
101  break;
102  }
103 
104  lerpRatio = ‪math::clamp( lerpRatio, 0, 1 );
105 
106  values[ chanIdx ] = startValue[ chanIdx ] + lerpRatio * delta;
107  }
108  else
109  {
110  values[ chanIdx ] = startValue[ chanIdx ];
111  }
112  }
113 
114  [[ setConstants ]]( localClientNum, GetStructField( bundle, constPrefix + "name" ), filterid, values );
115  }
116 
117  // Set the time variables in scriptvector7 (all in milliseconds):
118  // x: total accumulated time (since the start of the postFX bundle)
119  // y: current stage accumulated time
120  // z: current stage length
121  stageConstants = [];
122  stageConstants[0] = totalAccumTime;
123  stageConstants[1] = accumTime;
124  stageConstants[2] = stageLength;
125  stageConstants[3] = 0;
126 
127  [[ setConstants ]]( localClientNum, "scriptvector7", filterid, stageConstants );
128 }
129 
130 //-----------------------------------------------------------------------------
131 function ‪getShaderConstantValue( bundle, constPrefix, constName, ‪delay )
132 {
133  channels = GetStructField( bundle, constPrefix + "channels" );
134 
135  // Color has only single delay value
136  if ( ‪delay && IsString( channels ) && ( channels == "color" || channels == "color+alpha" ) )
137  channels = "1";
138 
139  vals = [];
140 
141  switch ( channels )
142  {
143  case 1:
144  case "1":
145  vals[0] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_x" );
146  break;
147 
148  case 2:
149  case "2":
150  vals[0] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_x" );
151  vals[1] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_y" );
152  break;
153 
154  case 3:
155  case "3":
156  vals[0] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_x" );
157  vals[1] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_y" );
158  vals[2] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_z" );
159  break;
160 
161  case 4:
162  case "4":
163  vals[0] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_x" );
164  vals[1] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_y" );
165  vals[2] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_z" );
166  vals[3] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_w" );
167  break;
168 
169  case "color":
170  vals[0] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_r" );
171  vals[1] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_g" );
172  vals[2] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_b" );
173  break;
174 
175  case "color+alpha":
176  vals[0] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_r" );
177  vals[1] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_g" );
178  vals[2] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_b" );
179  vals[3] = ‪GetStructFieldOrZero( bundle, constPrefix + constName + "_clr_a" );
180  break;
181  }
182 
183  return vals;
184 }
185 
186 //-----------------------------------------------------------------------------
187 function ‪GetStructFieldOrZero( bundle, field )
188 {
189  ret = GetStructField( bundle, field );
190  if ( !isdefined( ret ) )
191  ret = 0;
192 
193  return ret;
194 }
195 
196 //-----------------------------------------------------------------------------
197 // Should be done in code?
198 function ‪getShaderConstantIndex( codeConstName )
199 {
200  switch ( codeConstName )
201  {
202  case "scriptvector0": return 0;
203  case "scriptvector1": return 4;
204  case "scriptvector2": return 8;
205  case "scriptvector3": return 12;
206  case "scriptvector4": return 16;
207  case "scriptvector5": return 20;
208  case "scriptvector6": return 24;
209  case "scriptvector7": return 28;
210  }
211 
212  return -1;
213 }
214 
‪GetStructFieldOrZero
‪function GetStructFieldOrZero(bundle, field)
Definition: gfx_shared.csc:187
‪getShaderConstantIndex
‪function getShaderConstantIndex(codeConstName)
Definition: gfx_shared.csc:198
‪SetStage
‪function SetStage(localClientNum, bundle, filterid, stagePrefix, stageLength, accumTime, totalAccumTime, setConstants)
Definition: gfx_shared.csc:16
‪getShaderConstantValue
‪function getShaderConstantValue(bundle, constPrefix, constName, delay)
Definition: gfx_shared.csc:131
‪delay
‪function delay(time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:784
‪clamp
‪function clamp(val, val_min, val_max)
Definition: math_shared.csc:16