Skip to content

Commit 65b5ce1

Browse files
Simpler update to use now available ByteAddressBuffer
# Conflicts: # com.unity.visualeffectgraph/Editor/Compiler/VFXShaderWriter.cs # com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionAbstract.cs # com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl
1 parent f5a3cf3 commit 65b5ce1

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

com.unity.visualeffectgraph/Editor/Compiler/VFXShaderWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private static string GetFunctionParameterType(VFXValueType type)
326326
case VFXValueType.Texture3D: return "VFXSampler3D";
327327
case VFXValueType.TextureCube: return "VFXSamplerCube";
328328
case VFXValueType.TextureCubeArray: return "VFXSamplerCubeArray";
329-
case VFXValueType.Buffer: return "StructuredBuffer<float>";
329+
case VFXValueType.Mesh: return "ByteAddressBuffer";
330330

331331
default:
332332
return VFXExpression.TypeToCode(type);

com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionAbstract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static string TypeToCode(VFXValueType type)
132132
case VFXValueType.TextureCube: return "TextureCube";
133133
case VFXValueType.TextureCubeArray: return "TextureCubeArray";
134134
case VFXValueType.Matrix4x4: return "float4x4";
135-
case VFXValueType.Buffer: return "StructuredBuffer<float>";
135+
case VFXValueType.Mesh: return "ByteAddressBuffer";
136136
case VFXValueType.Boolean: return "bool";
137137
}
138138

com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ float FixedRand(uint seed)
306306
///////////////////
307307
// Mesh sampling //
308308
///////////////////
309+
<<<<<<< HEAD
309310
#define VFX_GENERIC_BUFFER_TYPE_AS_STRUCTURE_BUFFER_FLOAT 1
310311

311312
#if VFX_GENERIC_BUFFER_TYPE_AS_STRUCTURE_BUFFER_FLOAT
@@ -414,41 +415,86 @@ float4 SampleMeshColor(VFX_GENERIC_BUFFER vertices, uint offset, uint channelFor
414415

415416
//Deprecated function for compatibility 2020.1, can be removed with 2021.1
416417
float4 SampleMeshFloat4(VFX_GENERIC_BUFFER vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
418+
=======
419+
420+
float FetchBuffer(ByteAddressBuffer buffer, int offset) { return asfloat(buffer.Load(offset << 2)); }
421+
float2 FetchBuffer2(ByteAddressBuffer buffer, int offset) { return asfloat(buffer.Load2(offset << 2)); }
422+
float3 FetchBuffer3(ByteAddressBuffer buffer, int offset) { return asfloat(buffer.Load3(offset << 2)); }
423+
float4 FetchBuffer4(ByteAddressBuffer buffer, int offset) { return asfloat(buffer.Load4(offset << 2)); }
424+
425+
float4 SampleMeshFloat4(ByteAddressBuffer vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
426+
>>>>>>> 6fb9f1a73ec... Simpler update to use now available ByteAddressBuffer
417427
{
418428
if (channelOffset == -1)
419429
return float4(0.0f, 0.0f, 0.0f, 0.0f);
420430
uint offset = vertexIndex * vertexStride + channelOffset;
431+
<<<<<<< HEAD
421432
return SampleMeshFloat4(vertices, offset, VERTEXATTRIBUTEFORMAT_FLOAT32 | (4 << 8));
422433
}
423434

424435
float3 SampleMeshFloat3(VFX_GENERIC_BUFFER vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
436+
=======
437+
return FetchBuffer4(vertices, offset);
438+
}
439+
440+
float3 SampleMeshFloat3(ByteAddressBuffer vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
441+
>>>>>>> 6fb9f1a73ec... Simpler update to use now available ByteAddressBuffer
425442
{
426443
if (channelOffset == -1)
427444
return float3(0.0f, 0.0f, 0.0f);
428445
uint offset = vertexIndex * vertexStride + channelOffset;
446+
<<<<<<< HEAD
429447
return SampleMeshFloat3(vertices, offset, VERTEXATTRIBUTEFORMAT_FLOAT32 | (3 << 8));
430448
}
431449

432450
float2 SampleMeshFloat2(VFX_GENERIC_BUFFER vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
451+
=======
452+
return FetchBuffer3(vertices, offset);
453+
}
454+
455+
float2 SampleMeshFloat2(ByteAddressBuffer vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
456+
>>>>>>> 6fb9f1a73ec... Simpler update to use now available ByteAddressBuffer
433457
{
434458
if (channelOffset == -1)
435459
return float2(0.0f, 0.0f);
436460
uint offset = vertexIndex * vertexStride + channelOffset;
461+
<<<<<<< HEAD
437462
return SampleMeshFloat2(vertices, offset, VERTEXATTRIBUTEFORMAT_FLOAT32 | (2 << 8));
438463
}
439464

440465
float SampleMeshFloat(VFX_GENERIC_BUFFER vertices, int vertexIndex, int channelOffset, int vertexStride)
466+
=======
467+
return FetchBuffer2(vertices, offset);
468+
}
469+
470+
float SampleMeshFloat(ByteAddressBuffer vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
471+
>>>>>>> 6fb9f1a73ec... Simpler update to use now available ByteAddressBuffer
441472
{
442473
if (channelOffset == -1)
443474
return 0.0f;
444475
uint offset = vertexIndex * vertexStride + channelOffset;
476+
<<<<<<< HEAD
445477
return SampleMeshFloat(vertices, offset, VERTEXATTRIBUTEFORMAT_FLOAT32 | (1 << 8));
446478
}
447479

448480
float4 SampleMeshColor(VFX_GENERIC_BUFFER vertices, int vertexIndex, int channelOffset, int vertexStride)
449481
{
450482
if (channelOffset == -1)
451483
return float4(0.0f, 0.0f, 0.0f, 0.0f);
484+
=======
485+
return FetchBuffer(vertices, offset);
486+
}
487+
488+
float4 SampleMeshColor(ByteAddressBuffer vertices, uint vertexIndex, uint channelOffset, uint vertexStride)
489+
{
490+
if (channelOffset == -1)
491+
return float4(0.0f, 0.0f, 0.0f, 0.0f);
492+
uint offset = vertexIndex * vertexStride + channelOffset;
493+
uint colorByte = asuint(FetchBuffer(vertices, offset));
494+
float4 colorSRGB = float4(uint4(colorByte, colorByte >> 8, colorByte >> 16, colorByte >> 24) & 255) / 255.0f;
495+
return float4(pow(abs(colorSRGB.rgb), 2.2f), colorSRGB.a); //Approximative SRGBToLinear
496+
}
497+
>>>>>>> 6fb9f1a73ec... Simpler update to use now available ByteAddressBuffer
452498

453499
uint offset = vertexIndex * vertexStride + channelOffset;
454500
return SampleMeshColor(vertices, offset, VERTEXATTRIBUTEFORMAT_UNORM8 | (4 << 8));

0 commit comments

Comments
 (0)