-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path144b24f4-1a25-47ad-84f8-927dc738ae11.mop
411 lines (411 loc) · 15.3 KB
/
144b24f4-1a25-47ad-84f8-927dc738ae11.mop
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
{
"Name": "Chrome",
"_id": "144b24f4-1a25-47ad-84f8-927dc738ae11",
"Namespace": "lib.geometry.material",
"Description": "",
"Inputs": [
{
"Name": "Code",
"MetaInstanceID": "fe34e83c-994a-4c21-bf73-e8c716e111f7",
"DefaultValue": {
"Type": "Text",
"Value": [
"float4x4 objectToWorldMatrix;\r",
"float4x4 worldToCameraMatrix;\r",
"float4x4 cameraToObjectMatrix; // modelview inverse\r",
"float4x4 projMatrix;\r",
"float4x4 textureMatrix;\r",
"\r",
"\r",
"struct PointLight\r",
"{\r",
" float4 position;\r",
" float4 ambient;\r",
" float4 diffuse;\r",
" float4 specular;\r",
" float4 attenuation;\r",
"};\r",
"\r",
"struct SpotLight\r",
"{\r",
" float4 ambient;\r",
" float4 diffuse;\r",
" float4 specular;\r",
" float constantAttenuation;\r",
" float linearAttenuation;\r",
" float quadraticAttenuation;\r",
" float spotCutoff;\r",
" float spotCosCutoff;\r",
" float spotExponent;\r",
"};\r",
"\r",
"cbuffer FogSettings\r",
"{\r",
" float4 fogColor;\r",
" float fogStart;\r",
" float fogEnd;\r",
" float fogScale;\r",
"}\r",
"\r",
"cbuffer MaterialBuffer\r",
"{\r",
" float4 materialAmbient;\r",
" float4 materialDiffuse;\r",
" float4 materialSpecular;\r",
" float4 materialEmission;\r",
" float materialShininess;\r",
"};\r",
"\r",
"\r",
"cbuffer PointLightsBuffer\r",
"{\r",
" int numPointLights;\r",
" PointLight pointLights[3];\r",
"};\r",
"\r",
"\r",
"Texture2D txDiffuse;\r",
"TextureCube CubeMap;\r",
"TextureCube Irradiance;\r",
"\r",
"SamplerState samLinear\r",
"{\r",
" Filter = MIN_MAG_MIP_LINEAR;\r",
" AddressU = Wrap;\r",
" AddressV = Wrap;\r",
"};\r",
"\r",
"\r",
"struct VS_IN\r",
"{\r",
" float4 pos : POSITION;\r",
" float3 normal : NORMAL;\r",
" float4 col : COLOR;\r",
" float2 texCoord : TEXCOORD0;\r",
" float3 tangent : TANGENT0;\r",
" float3 binormal : BINORMAL0;\r",
"};\r",
"\r",
"\r",
"struct PS_IN\r",
"{\r",
" float4 pos : SV_POSITION;\r",
" float4 posInWorld : WORLD_POS;\r",
" float3 normal : NORMAL; \r",
" float2 texCoord : TEXCOORD0;\r",
" float4 vertexColor : COLOR;\r",
" float3 fragPosToCamPos : POS;\r",
" float fogFragCoord : FALLO;\r",
"};\r",
"\r",
"\r",
"float mod(float a, float b)\r",
"{\r",
" return a - b*floor(a/b);\r",
"}\r",
"\r",
"float3 mod(float3 a, float b)\r",
"{\r",
" return a - b*floor(a/b);\r",
"}\r",
"\r",
"\r",
"\r",
"//>>>> VS2\r",
"PS_IN VS( VS_IN input )",
"{",
" PS_IN output = (PS_IN)0;",
"",
" output.posInWorld = mul(input.pos, objectToWorldMatrix);",
" output.pos = mul(output.posInWorld, worldToCameraMatrix);",
" output.normal = mul(input.normal, (float3x3)objectToWorldMatrix);",
" output.fogFragCoord = abs(output.pos.z / input.pos.w);",
" output.pos = mul(output.pos, projMatrix);",
" output.texCoord = mul(float4(input.texCoord, 0, 1), textureMatrix).xy;",
" output.fragPosToCamPos = normalize(mul(cameraToObjectMatrix[3], objectToWorldMatrix) - output.posInWorld);",
" output.vertexColor = input.col;",
" ",
" return output;",
"}",
"//<<< VS\r",
"\r",
"float4 calcLightSource(float3 fragPosInWorld, int lightIdx, float3 cameraVector, float3 norm, float4 baseColor)\r",
"{\r",
" float3 lightVector = pointLights[lightIdx].position - fragPosInWorld;\r",
" float dist = length(lightVector);\r",
" lightVector = normalize(lightVector);\r",
" float nxDir = max(0.0, dot(norm, lightVector));\r",
" float4 diffuse = pointLights[lightIdx].diffuse * nxDir;\r",
" float specularPower = 0.0;\r",
" if (nxDir > 0.0)\r",
" {\r",
" float3 r = reflect(-lightVector, norm);\r",
" float rl = max(0.0, dot(r, cameraVector));\r",
" specularPower = pow(rl, materialShininess);\r",
" }\r",
"\r",
" float attenuation = 1.0 / (pointLights[lightIdx].attenuation.x +\r",
" pointLights[lightIdx].attenuation.y * dist +\r",
" pointLights[lightIdx].attenuation.z * dist * dist);\r",
" float4 color = materialAmbient * pointLights[lightIdx].ambient * attenuation +\r",
" materialDiffuse * (diffuse * baseColor * attenuation) +\r",
" materialSpecular * pointLights[lightIdx].specular * specularPower * attenuation;\r",
"\r",
" return color;\r",
"}\r",
"\r",
"\r",
"\r",
"//>>>> PS\r",
"float4 PS( PS_IN input ) : SV_Target\r",
"{\r",
" float2 newTexCoords = input.texCoord;\r",
" float3 norm = normalize(input.normal);\r",
" float4 baseColor = float4(0.3, 0.3, 0.3, 1);//materialDiffuse;//txDiffuse.Sample(samLinear, input.texCoord);\r",
" baseColor *= Irradiance.Sample(samLinear, norm);\r",
" float4 v = mul(cameraToObjectMatrix[3], objectToWorldMatrix) - input.posInWorld;\r",
" float3 incident = normalize(v.xyz);\r",
" float3 r = reflect(-incident, norm);\r",
" baseColor = lerp(baseColor, CubeMap.Sample(samLinear, r), 0.7);\r",
"\r",
" float4 color = baseColor;//float4(0, 0, 0, 1);\r",
" for (int lightIdx = 0; lightIdx < numPointLights; ++lightIdx)\r",
" {\r",
"// color += calcLightSource(input.posInWorld, lightIdx, input.fragPosToCamPos, norm, baseColor);\r",
" }\r",
" color += materialEmission*baseColor;\r",
"\r",
" float fog = (fogEnd - input.fogFragCoord) * fogScale;\r",
" fog = clamp(fog, 0.0, 1.0);\r",
" return float4(lerp(fogColor.rgb, color.rgb, fog), materialDiffuse.a * baseColor.a);\r",
"}\r",
"//<<< PS\r",
"\r",
"technique10 Render\r",
"{\r",
" pass P0\r",
" {\r",
" SetGeometryShader( 0 );\r",
" SetVertexShader( CompileShader( vs_4_0, VS() ) );\r",
" SetPixelShader( CompileShader( ps_4_0, PS() ) );\r",
" }\r",
"} "
]
},
"MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
"IsMultiInput": "False",
"Relevance": "Optional",
"Description": "",
"Min": "-100000",
"Max": "100000",
"Scale": "0.1",
"ScaleType": "Linear",
"EnumValues": []
},
{
"Name": "Scene",
"MetaInstanceID": "ec71ca9d-55e7-474e-ade1-1561ed83e1ea",
"DefaultValue": {
"Type": "Scene",
"Value": "Framefield.Core.Scene"
},
"MetaID": "79122951-7bc4-4c68-b085-866eab828248",
"IsMultiInput": "False",
"Relevance": "Required",
"Description": "",
"Min": "-100000",
"Max": "100000",
"Scale": "0.1",
"ScaleType": "Linear",
"EnumValues": []
},
{
"Name": "CubeMap",
"MetaInstanceID": "6f2a5008-1cfb-4b31-9b3e-a462edb28380",
"DefaultValue": {
"Type": "Image",
"Value": "Framefield.Core.Image"
},
"MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab",
"IsMultiInput": "False",
"Relevance": "Relevant",
"Description": "",
"Min": "-100000",
"Max": "100000",
"Scale": "0.1",
"ScaleType": "Linear",
"EnumValues": []
},
{
"Name": "Irradiance",
"MetaInstanceID": "8ca0d879-9d6d-4765-b2bf-a9777b2cabf0",
"DefaultValue": {
"Type": "Image",
"Value": "Framefield.Core.Image"
},
"MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab",
"IsMultiInput": "False",
"Relevance": "Required",
"Description": "",
"Min": "-100000",
"Max": "100000",
"Scale": "0.1",
"ScaleType": "Linear",
"EnumValues": []
}
],
"Outputs": [
{
"Name": "Scene",
"MetaInstanceID": "3e8ac177-d71b-4dbf-bb2f-418abad0ecc1",
"MetaID": "79122951-7bc4-4c68-b085-866eab828248"
}
],
"OperatorParts": [
{
"MetaInstanceID": "c9ec41b9-684a-49a1-998e-3962bcf87753",
"MetaID": "440a69fb-8ff1-4185-b512-28259b2b7c9c",
"Name": "ChromeFunc",
"Version": "82aeb584-a7e7-4ad5-b358-4561342eb710",
"Type": "Float",
"IsMultiInput": "True",
"Script": [
"//>>> _using",
"using System;",
"using System.Collections.Generic;",
"using System.Linq;",
"using System.Text;",
"using SharpDX;",
"using SharpDX.Direct3D11;",
"using SharpDX.Windows;",
"//<<< _using",
"using Framefield.Core.Rendering;",
"",
"namespace Framefield.Core.ID440a69fb_8ff1_4185_b512_28259b2b7c9c",
"{",
" public class Class_Chrome : FXSourceCodeFunction",
" {",
" //>>> _inputids",
" private enum InputId",
" {",
" Code = 0,",
" Scene = 1,",
" CubeMap = 2,",
" Irradiance = 3",
" }",
" //<<< _inputids",
"",
" #region Renderer",
" public class Renderer : BaseRenderer",
" {",
" public override void SetupEffect(OperatorPartContext context)",
" {",
" base.SetupEffect(context);",
" try",
" {",
" SetupMaterialConstBuffer(context);",
" SetupFogSettingsConstBuffer(context);",
" SetupPointLightsConstBuffer(context);",
" }",
" catch (Exception e)",
" {",
" Logger.Error(ParentFunc, \"Error building constant buffer: {0} - Source: {1}\", e.Message, e.Source);",
" }",
" }",
" public OperatorPart.Function ParentFunc {get;set;}",
" }",
" #endregion",
"",
" public Class_Chrome()",
" {",
" _renderer = new Renderer(){ParentFunc = this};",
" }",
"",
" public override void Dispose()",
" {",
" Utilities.DisposeObj(ref _renderer);",
" base.Dispose();",
" }",
"",
" bool _firstEval = true;",
" public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
" {",
" //>>> _params",
" var Code = inputs[(int)InputId.Code].Eval(context).Text;",
" var Scene = inputs[(int)InputId.Scene];",
" var CubeMap = inputs[(int)InputId.CubeMap].Eval(context).Image; if (CubeMap == null) return context;",
" var Irradiance = inputs[(int)InputId.Irradiance].Eval(context).Image; if (Irradiance == null) return context;",
" //<<< _params",
"",
" if (_firstEval)",
" {",
" for (int i = 0; i < NumCodes(); ++i)",
" Compile(i);",
" _firstEval = false;",
" Changed = true;",
" }",
"",
" //>>> __setup",
" using (var CubeMapView = new ShaderResourceView(context.D3DDevice, CubeMap))",
" using (var IrradianceView = new ShaderResourceView(context.D3DDevice, Irradiance))",
" {",
" _effect.GetVariableByName(\"CubeMap\").AsShaderResource().SetResource(CubeMapView);",
" _effect.GetVariableByName(\"Irradiance\").AsShaderResource().SetResource(IrradianceView);",
" //<<< __setup",
" ",
" using (new PropertyStasher<OperatorPartContext>(context, \"Effect\", \"Renderer\"))",
" {",
" context.Effect = _effect;",
" context.Renderer = _renderer;",
" ",
" Scene.Eval(context);",
" }",
" }",
"",
" return context;",
" }",
"",
" Renderer _renderer;",
" }",
"}",
"",
"",
""
],
"AdditionalAssemblies": []
}
],
"Operators": [],
"Connections": [
{
"SourceOp": "00000000-0000-0000-0000-000000000000",
"SourceOpPart": "c9ec41b9-684a-49a1-998e-3962bcf87753",
"TargetOp": "00000000-0000-0000-0000-000000000000",
"TargetOpPart": "3e8ac177-d71b-4dbf-bb2f-418abad0ecc1"
},
{
"SourceOp": "00000000-0000-0000-0000-000000000000",
"SourceOpPart": "fe34e83c-994a-4c21-bf73-e8c716e111f7",
"TargetOp": "00000000-0000-0000-0000-000000000000",
"TargetOpPart": "c9ec41b9-684a-49a1-998e-3962bcf87753"
},
{
"SourceOp": "00000000-0000-0000-0000-000000000000",
"SourceOpPart": "ec71ca9d-55e7-474e-ade1-1561ed83e1ea",
"TargetOp": "00000000-0000-0000-0000-000000000000",
"TargetOpPart": "c9ec41b9-684a-49a1-998e-3962bcf87753"
},
{
"SourceOp": "00000000-0000-0000-0000-000000000000",
"SourceOpPart": "6f2a5008-1cfb-4b31-9b3e-a462edb28380",
"TargetOp": "00000000-0000-0000-0000-000000000000",
"TargetOpPart": "c9ec41b9-684a-49a1-998e-3962bcf87753"
},
{
"SourceOp": "00000000-0000-0000-0000-000000000000",
"SourceOpPart": "8ca0d879-9d6d-4765-b2bf-a9777b2cabf0",
"TargetOp": "00000000-0000-0000-0000-000000000000",
"TargetOpPart": "c9ec41b9-684a-49a1-998e-3962bcf87753"
}
]
}