Closed inequation closed 7 years ago
I take it you've seen the pre-defined __INTELLISENSE__
macro, which you can use to conditionally #define
things? If I understand correctly, you'd rather be able to do that at a project-level instead of a file-level.
I'd rather not touch the file contents without good reason (actual features), we already have a history of difficult integrations of new versions of UE4 code. ;)
That's why I've called it a feature request – it's low priority, implement it (or not) at your leisure.
Okay, understood. A related project-level setting that I've thought about would be additional #include
paths.
I'm just not sure how to do project-level settings - try to add something to the existing project configuration UI? Or add something to Tools > Options, but save the data in a simple text file in the root of the project? Or no UI at all, just a simple text file? All ideas welcome...
(Update: I notice WebEssentials stores its settings in a .json file in the root of the solution, if you have a solution open, or in your user folder, if you don't: https://github.com/madskristensen/WebEssentials2015/blob/master/EditorExtensions/Settings/SettingsStore.cs)
In all honesty, I have no idea about the APIs to add things like that to MSVS project configuration UI, or if they even exist. :) That would be the cleanest way to go, but I'll gladly take even a text file. :)
Another way to address this specific use case would be to mimic the Show Inactive Blocks feature of the C/C++ text editor (Tools > Options > Text Editor > C/C++ > View).
I have a similar problem as this, although related to include paths rather than #defines. I was thinking maybe a simple "search current folder and all parent folders" type approach, similar to how EditorConfig (http://editorconfig.org/) works, might be appropriate here? It's easy to implement, easy to understand, isn't tied to any project type or layout convention, and allows people to configure a project without modifying it (e.g. avoiding divergence in Unreal) by putting the file in a parent directory outside the repo (or just the root directory of the hard drive!)
Thoughts?
@simontaylor81 That's a good suggestion, thank you. It would definitely help, but I wonder whether we still need to add other arbitrary #include
paths?
Sorry for the slow response. I'm afraid I don't really understand the question. Would a config file not allow adding arbitrary include paths?
Ah, I misunderstood! I thought you meant the ancestor folders would be include paths themselves - but I see now you meant that they would be searched for config files, which would then point to include paths (one of which might be the directory containing the config file?).
Exactly yes, sorry that wasn't clear!
Just to add to this, in c++ projects at least, these options exist already in the project settings (Configuration Properties -> HLSL Compiler -> General). We use both the 'Additional Include Directories' and 'Preprocessor Definitions' options which both seem to be ignored. It would be nice to see these supported :) There's also the option of manually editing project files to put configs in for other types of projects, which obviously wouldn't be as nice as having a gui for them but would probably be a lot easier to start with.
Hello, About the 'Additional Include Directories' and 'Preprocessor Definitions' options. It looks to be still unsupported. (version 1.0.119) Am I missing something ? Is there another way of making that work with HlslTools ?
I was surprised by the quality of the overall features given, but I don't get why it's so complicated to solve theses 2. A good thing will be also to select build property from file name: to switch from shader type, I've to put each type in different (visual studio) projects where the build option is rightly set. (I mean if file name is "MyShader_vs.hlsl" select vertex shader, "MyShader_ps.hlsl" select pixel, but that issue looks rather to be a visual studio one) Thanks
@JSeb-92 thanks for the reminder; I haven't forgotten about this issue, but you're right, it isn't a particularly complicated feature. Just a matter of available time!
A good thing will be also to select build property from file name
Yes, that does sound like a Visual Studio issue.
This is implemented now. It will be released on the Marketplace soon. If you're feeling brave, you can try it out using the version on VSIX Gallery: http://vsixgallery.com/extension/7def6c01-a05e-42e6-953d-3fdea1891737/
There's an explanation of how it works in the readme: https://github.com/tgjones/HlslTools#custom-preprocessor-definitions-and-additional-include-directories
@inequation @simontaylor81 @sjschaff @JSeb-92 does this resolve this issue for you?
Ha! Nice, yes it does, thank you! :)
Yeah, look perfect to me to. Once it's release to the marketplace I'll give it a go at work with our crazy shaders, and let you know how it goes!
Hello, I must have misunderstood something (since it's working for others): when I put the shadertoolsconfig.json file above my hlsl that doesn't work (ever #define or #include paths)
I've uninstalled and installed your new plugin version, restarted VS 2015, still same. If I put the shadertoolsconfig.json it's also the same.
Strange thing, you've mixed list syntax in your json: sometimes with "{ }" (#define), sometimes with "[ ]" (directiories) is that normal ? With "[ ]" my VS 2015 crashed when opening hlsl files.
Thanks and sorry for the bad news...
Simon Taylor a écrit le 18/01/2017 à 22:11 :
Yeah, look perfect to me to. Once it's release to the marketplace I'll give it a go at work with our crazy shaders, and let you know how it goes!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tgjones/HlslTools/issues/8#issuecomment-273603062, or mute the thread https://github.com/notifications/unsubscribe-auth/AThjDoR_sVfLrLTAPqL8IXXfRskLlEjFks5rToAVgaJpZM4GL7OR.
{ "root": true, "hlsl.preprocessorDefinitions": { "fpart4": "float4", "DTwk_Natural_iQuality" : 1 }, "hlsl.additionalIncludeDirectories": { "." } }
when I put the shadertoolsconfig.json file above my hlsl that doesn't work (ever #define or #include paths)
Can you list the relevant bits of your directory / file tree, just so I can check it's what I expect?
Strange thing, you've mixed list syntax in your json: sometimes with "{ }" (#define), sometimes with "[ ]" (directiories) is that normal ?
That's intentional - "hlsl.preprocessorDefinitions" defines a dictionary of macro name -> macro value. "hlsl.additionalIncludeDirectories" is an array of directory names.
ok for the brakets I've changed but same bugs I've put the config in same folder
With these 2 files you may reproduce at least the issue with "fpart4" => "float4" in VS2015, I see strange errors in the display of quickinfo "Found
It looks from the code you posted, like you're including the JSON configuration at the end of the HLSL file? Or was that just an copy-and-paste artifact?
It needs to be in a separate file, shadertoolsconfig.json
, in the same folder (or ancestor folder) as your HLSL source file.
Never mind, leave this with me. I've tried your HLSL file and there are indeed some issues in HLSL Tools.
There was a bug with how "hlsl.preprocessorDefinitions" were handled, which I've fixed now. Sorry for the mess-up, @JSeb-92. Once 1.0.152 has finished building, please could you try that version?
hum,
that's better but...
The macro did work, but I delete the config file that was just next to the hlsl (to test the #include path), closed the hlsl file from VS 2015 and crash...
No I've several hlsl path I can no longer open, I'll check all my json to check who's culprit
could be great if a crashdump (of the plugin) was dumped somewhere
Tim Jones a écrit le 19/01/2017 à 14:33 :
Closed #8 https://github.com/tgjones/HlslTools/issues/8.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tgjones/HlslTools/issues/8#event-929101201, or mute the thread https://github.com/notifications/unsubscribe-auth/AThjDo4JfXC61QP0oc0RBVLsZ_ctRywwks5rT2Y0gaJpZM4GL7OR.
The file I give you is #included by many of our hlsl (cross platform things), and it make VS 2015 crash.
Please don't re-distribute that file.
Thanks
Jean-Sebastien LUCE a écrit le 19/01/2017 à 15:39 :
hum,
that's better but...
The macro did work, but I delete the config file that was just next to the hlsl (to test the #include path), closed the hlsl file from VS 2015 and crash...
No I've several hlsl path I can no longer open, I'll check all my json to check who's culprit
could be great if a crashdump (of the plugin) was dumped somewhere
Tim Jones a écrit le 19/01/2017 à 14:33 :
Closed #8 https://github.com/tgjones/HlslTools/issues/8.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tgjones/HlslTools/issues/8#event-929101201, or mute the thread https://github.com/notifications/unsubscribe-auth/AThjDo4JfXC61QP0oc0RBVLsZ_ctRywwks5rT2Y0gaJpZM4GL7OR.
// On n'utilise pas de petits indexs (comme 1) // (les compilo utilisent souvent '1' comme valeur pour les #define en ligne de commande comme DMwEditor) // le but de la division par 100 est de passer à 0 pour la pluspart des _M invalides (et donc /0 => erreur)
//////////////////////// // Warnings qui posent plus de pb qu'autre chose avec les compilos:
#pragma warning(disable : 5609) // type 'half' is currently treated as 'float' on this target
#pragma warning(disable : 5203) // parameter 'BilinearCorners' is unreferenced
#pragma warning(disable : 5206) // local variable 'y3' is unreferenced, j'ai essayé de le localiser avec (push) (pop) sans succès (inlines...)
// D3D9 / D3D11:
#pragma warning(disable : 3207) // Initializer used on a global 'const' variable. This requires setting an external constant. If a literal is desired, use 'static const' instead.
//////////////////////// // #defines to help cross compilation (Hlsl_D3D9/Hlsl_D3D11/Ps4/Cg)
#if DGbxShaderVersion<0x0300 // || _Profile.Platform==EPlugGpuPlatform_GL_CgAsm
#define _branch_
#define _flatten_
#define _unroll_
#define _loop_
#else
#define _branch_ [branch]
#define _flatten_ [flatten]
#define _unroll_ [unroll]
#define _loop_ [loop]
#endif
//////////////////////// // Variable Type modifiers:
// PS4_PSSL => D3D11_HLSL
//////////////////////// // Semantics:
// HLSL => PSSL macros:
#define cbuffer ConstantBuffer
#define Buffer DataBuffer
#define RWBuffer RW_DataBuffer
#define ByteAddressBuffer ByteBuffer
#define StructuredBuffer RegularBuffer
#define SV_Position S_POSITION
#define SV_IsFrontFace S_FRONT_FACE
#define SV_Target0 S_TARGET_OUTPUT0
#define SV_Target1 S_TARGET_OUTPUT1
#define SV_Target2 S_TARGET_OUTPUT2
#define SV_Target3 S_TARGET_OUTPUT3
#define SV_Target4 S_TARGET_OUTPUT4
#define SV_Target5 S_TARGET_OUTPUT5
#define SV_Target6 S_TARGET_OUTPUT6
#define SV_Target7 S_TARGET_OUTPUT7
#define SV_Depth S_DEPTH_OUTPUT
#define SV_Depth_GE S_DEPTH_GE_OUTPUT
#define SV_Depth_LE S_DEPTH_LE_OUTPUT
#define SV_ClipDistance0 S_CLIP_DISTANCE0
#define SV_CullDistance0 S_CULL_DISTANCE0
#define SV_Coverage S_COVERAGE
#define SV_VertexID S_VERTEX_ID
#define SV_InstanceID S_INSTANCE_ID
#define SV_PrimitiveID S_PRIMITIVE_ID
#define SV_GSInstanceID S_GSINSTANCE_ID
#define SV_SampleIndex S_SAMPLE_INDEX
#define SV_DispatchThreadID S_DISPATCH_THREAD_ID
#define SV_GroupID S_GROUP_ID
#define SV_GroupIndex S_GROUP_INDEX
#define SV_GroupThreadID S_GROUP_THREAD_ID
#define firstbitlow FirstSetBit_Lo
// Conservative depth output are supported only when >= 0x0500:
#define SV_Depth_GE SV_DepthGreaterEqual
#define SV_Depth_LE SV_DepthLessEqual
// SM4/3: Some semantics are specific optimization
// => remove the optim of the case:
#define SV_Depth_GE SV_Depth
#define SV_Depth_LE SV_Depth
///////////////////////// // fpart -> half/float // half type isn't really supported on some platforms (like PS4) // PS4 + wave compiler: // many implicit cast warning on float->half // some errors on trigo. function (/ex "sincos" expects float instead of half) // the only case of hardware for halfs is texture read // https://ps4.scedev.net/forums/thread/14647/
typedef float fpart; typedef float2 fpart2; typedef float3 fpart3; typedef float4 fpart4; typedef float3x3 fpart3x3; typedef float4x3 fpart4x3;
typedef half fpart; typedef half2 fpart2; typedef half3 fpart3; typedef half4 fpart4; typedef half3x3 fpart3x3; typedef half4x3 fpart4x3;
/////////////////////////
//////////////////////// // D3D11/PS4: on a besoin du split Texture/Sampler pour le shadow mapping !
// Enfin, le code de FXAA utilise une struct qui simplifie pas mal de truc (genre passage de param, var de struct) // à voir si les compilos supporte ça bien (et si on retrouve bien les 2 élements coté C++) // #define FxaaTex sampler2D // struct FxaaTex { SamplerState smpl; Texture2D tex; }; // les remapping passent par des méthodes avec #define dedans plutot que des #defines direct //
///////////////////// // D3D9 + bool registers: sometimes in D3D9, we've to force bool register to avoid getting float4 instead ! // (no longer needed in SM4) // when this ": register(b##__iReg)" syntax is used, a cbuffer can no longer be declared // else we get (only for D3D9 target): // X3530: cannot mix packoffset elements with nonpackoffset elements in a cbuffer // => MCBufferBegin/End allow to declare 'cbuffer' only in >=SM4:
#define MSM3_BoolRegister(__iReg)
#define MCBufferBegin(__Name) cbuffer __Name {
#define MCBufferEnd };
#define MSM3_BoolRegister(__iReg) : register(b##__iReg)
#define MCBufferBegin(__Name)
#define MCBufferEnd
///////////////////// // uint !! // D3D9 : error X3548: in ps_3_0 uints can only be used with known-positive values, use int if possible
// D3D11: warning X3556: integer modulus may be much slower, try using uints if possible.
// Ps4 : warning 9015: Div (/) and mod (%) are inefficient for 'int'. Consider using 'uint' instead
// ==>> uint sauf en D3D9, ou on fall-back en int !!
#define MSafe_uint uint
#define MSafe_uint2 uint2
#define MSafe_uint3 uint3
#define MSafe_uint4 uint4
#define MSafe_uint int
#define MSafe_uint2 int2
#define MSafe_uint3 int3
#define MSafe_uint4 int4
//////////////////// // MSafe_uint_div !! Utiliser MSafe_uintX pour déclarer les uints en entrée/sortie !! // MSafe_uint_mod !! Utiliser MSafe_uintX pour déclarer les uints en entrée/sortie !!
// >= SM4: on utilise des uint (bien supporté), c'est le type qu'on veut au final
#define MSafe_uint_div(_a, _b) ((_a)/(_b))
#define MSafe_uint_mod(_a, _b) ((_a)%(_b))
// <= SM3: uint pas supportés et int émulés via float (% très couteux)
#define MSafe_uint_div(_a, _b) (abs(_a)/(_b))
#define MSafe_uint_mod(_a, _b) (_a - _b*MSafe_uint_div(_a, _b))
// omettre 'abs' coute 11 arithm. (vec3)
// faire directement '/', '%' coute 23 arithm (vec3) !!
////////////////////
////////////////////
static const float Pi = 3.141592653f;
#define VULKAN_RM(__X)
#define inline
#define VULKAN_RM(__X) __X
// !! VULKAN only support [][] matrix indexation !! // First index is ROW, 2nd index is COLUMN
static inline float3 Matrix_GetRowX (in float2x3 m) {return m[0];} static inline float3 Matrix_GetRowY (in float2x3 m) {return m[1];}
static inline float3 Matrix_GetRowX (in float3x3 m) {return m[0];} static inline float3 Matrix_GetRowY (in float3x3 m) {return m[1];} static inline float3 Matrix_GetRowZ (in float3x3 m) {return m[2];}
static inline float3 Matrix_GetRowW (in float4x3 m) {return m[3];}
static inline float3 Matrix_GetColumnX (in float3x3 m) {return float3(m[0][0], m[1][0], m[2][0]);} static inline float4 Matrix_GetColumnX (in float4x2 m) {return float4(m[0][0], m[1][0], m[2][0], m[3][0]);} static inline float4 Matrix_GetColumnX (in float4x3 m) {return float4(m[0][0], m[1][0], m[2][0], m[3][0]);} static inline float4 Matrix_GetColumnX (in float4x4 m) {return float4(m[0][0], m[1][0], m[2][0], m[3][0]);}
static inline float3 Matrix_GetColumnY (in float3x3 m) {return float3(m[0][1], m[1][1], m[2][1]);} static inline float4 Matrix_GetColumnY (in float4x2 m) {return float4(m[0][1], m[1][1], m[2][1], m[3][1]);} static inline float4 Matrix_GetColumnY (in float4x3 m) {return float4(m[0][1], m[1][1], m[2][1], m[3][1]);} static inline float4 Matrix_GetColumnY (in float4x4 m) {return float4(m[0][1], m[1][1], m[2][1], m[3][1]);}
static inline float3 Matrix_GetColumnZ (in float3x3 m) {return float3(m[0][2], m[1][2], m[2][2]);} static inline float4 Matrix_GetColumnZ (in float4x3 m) {return float4(m[0][2], m[1][2], m[2][2], m[3][2]);} static inline float4 Matrix_GetColumnW (in float4x4 m) {return float4(m[0][3], m[1][3], m[2][3], m[3][3]);}
// Matrix Set
static inline float2x3 Matrix_SetRows (in float3 r0, in float3 r1) {float2x3 m; m[0] = r0; m[1] = r1; return m;} static inline float3x3 Matrix_SetRows (in float3 r0, in float3 r1, in float3 r2) {float3x3 m; m[0] = r0; m[1] = r1; m[2] = r2; return m;}
static inline float3x3 Matrix_SetColumns (in float3 c0, in float3 c1, in float3 c2)
{
float3x3 m;
m[0] = float3(c0[0], c1[0], c2[0]); // Row 0
m[1] = float3(c0[1], c1[1], c2[1]); // Row 1
m[2] = float3(c0[2], c1[2], c2[2]); // Row 1
return m;
}
static inline float4x2 Matrix_SetColumns (in float4 c0, in float4 c1)
{
float4x2 m;
m[0] = float2(c0[0], c1[0]); // Row 0
m[1] = float2(c0[1], c1[1]); // Row 1
m[2] = float2(c0[2], c1[2]);
m[3] = float2(c0[3], c1[3]);
return m;
}
static inline void Matrix4x4_Set (out float4x4 Dst, in float4x3 Src) { Dst[0] = float4(Src[0], 0); // Row 0 Dst[1] = float4(Src[1], 0); // Row 1 Dst[2] = float4(Src[2], 0); Dst[3] = float4(Src[3], 1); }
//////////////////// // Quaternions:
fpart3x3 QuatGetFloat3x3(in fpart4 _Quat)
{
float xs,ys,zs,wx,wy,wz,xx,xy,xz,yy,yz,zz;
xs = 2.0f _Quat.x;
ys = 2.0f _Quat.y;
zs = 2.0f _Quat.z;
wx = _Quat.w xs;
wy = _Quat.w ys;
wz = _Quat.w zs;
xx = _Quat.x xs;
xy = _Quat.x ys;
xz = _Quat.x zs;
yy = _Quat.y ys;
yz = _Quat.y zs;
zz = _Quat.z zs;
return Matrix_SetRows(
float3(1.0f - yy - zz, xy + wz, xz - wy),
float3(xy - wz, 1.0f - xx - zz, yz + wx),
float3(xz + wy, yz - wx, 1.0f - xx - yy)
);
}
fpart3 MulQuat(in fpart3 v, in fpart4 q) { fpart3 r2; r2.x = (q.yv.z - q.zv.y) + q.wv.x; r2.y = (q.zv.x - q.xv.z) + q.wv.y; r2.z = (q.xv.y - q.yv.x) + q.wv.z; fpart3 r; r.x = (r2.zq.y - r2.yq.z)2 + v.x; r.y = (r2.xq.z - r2.zq.x)2 + v.y; r.z = (r2.yq.x - r2.xq.y)2 + v.z; return r; }
@JSeb-92 thanks for the example file. You have uncovered another bug in HLSL Tools (not related to shadertoolsconfig.json
), which causes the code that looks for navigation targets (in order to populate the navigation bar) to crash.
I've fixed that crash in v1.0.154.
HLSL Tools still reports errors in your example file, but at least HLSL Tools doesn't crash now. If you think HLSL Tools is reporting false-positive errors, please could you log those as separate issues?
Hello,
I've still many crashs with your parser, here is a repro: The #include "Platform.hlsl" in the LmILightDir_AddAmbient_cs.hlsl file make the crash.
I'm sorry I did not took time to create a new issue... Thanks
/GBX\ Require_ShaderModel 5 *GBX*/
//#include "Engines\Media\Text\Platform.hlsl.inc.txt"
struct SAmbientAccum { float3 Rgb; float Padding; };
RWStructuredBuffer
cbuffer Shader : register(b0) { float Scale; };
// !! No more than 64 threads to fit in PS4/XBoxOne hardware !! // It's a pitty but only one thread is required => GPU poorly used... [numthreads(1,1,1)] void csMain(uint3 i3Texel : SV_DispatchThreadID) { uint Widht, Height; TexColorPeeled.GetDimensions(Widht, Height); float3 ColorPeeled = (float3) TexColorPeeled.Load(int3(Widht/2, Height/2, 0 /iMip/)); BufAmbientAccum[0].Rgb += ColorPeeled * Scale; BufAmbientAccum[0].Padding += Scale / 2; // normalization check purpose (should give around 0.5 since cull out on hemisphere) }
// On n'utilise pas de petits indexs (comme 1) // (les compilo utilisent souvent '1' comme valeur pour les #define en ligne de commande comme DMwEditor) // le but de la division par 100 est de passer à 0 pour la pluspart des _M invalides (et donc /0 => erreur)
//////////////////////// // Warnings qui posent plus de pb qu'autre chose avec les compilos:
#pragma warning(disable : 5609) // type 'half' is currently treated as 'float' on this target
#pragma warning(disable : 5203) // parameter 'BilinearCorners' is unreferenced
#pragma warning(disable : 5206) // local variable 'y3' is unreferenced, j'ai essayé de le localiser avec (push) (pop) sans succès (inlines...)
// D3D9 / D3D11:
#pragma warning(disable : 3207) // Initializer used on a global 'const' variable. This requires setting an external constant. If a literal is desired, use 'static const' instead.
//////////////////////// // #defines to help cross compilation (Hlsl_D3D9/Hlsl_D3D11/Ps4/Cg)
#if DGbxShaderVersion<0x0300 // || _Profile.Platform==EPlugGpuPlatform_GL_CgAsm
#define _branch_
#define _flatten_
#define _unroll_
#define _loop_
#else
#define _branch_ [branch]
#define _flatten_ [flatten]
#define _unroll_ [unroll]
#define _loop_ [loop]
#endif
//////////////////////// // Variable Type modifiers:
// PS4_PSSL => D3D11_HLSL
//////////////////////// // Semantics:
// HLSL => PSSL macros:
#define cbuffer ConstantBuffer
#define Buffer DataBuffer
#define RWBuffer RW_DataBuffer
#define ByteAddressBuffer ByteBuffer
#define StructuredBuffer RegularBuffer
#define SV_Position S_POSITION
#define SV_IsFrontFace S_FRONT_FACE
#define SV_Target0 S_TARGET_OUTPUT0
#define SV_Target1 S_TARGET_OUTPUT1
#define SV_Target2 S_TARGET_OUTPUT2
#define SV_Target3 S_TARGET_OUTPUT3
#define SV_Target4 S_TARGET_OUTPUT4
#define SV_Target5 S_TARGET_OUTPUT5
#define SV_Target6 S_TARGET_OUTPUT6
#define SV_Target7 S_TARGET_OUTPUT7
#define SV_Depth S_DEPTH_OUTPUT
#define SV_Depth_GE S_DEPTH_GE_OUTPUT
#define SV_Depth_LE S_DEPTH_LE_OUTPUT
#define SV_ClipDistance0 S_CLIP_DISTANCE0
#define SV_CullDistance0 S_CULL_DISTANCE0
#define SV_Coverage S_COVERAGE
#define SV_VertexID S_VERTEX_ID
#define SV_InstanceID S_INSTANCE_ID
#define SV_PrimitiveID S_PRIMITIVE_ID
#define SV_GSInstanceID S_GSINSTANCE_ID
#define SV_SampleIndex S_SAMPLE_INDEX
#define SV_DispatchThreadID S_DISPATCH_THREAD_ID
#define SV_GroupID S_GROUP_ID
#define SV_GroupIndex S_GROUP_INDEX
#define SV_GroupThreadID S_GROUP_THREAD_ID
#define firstbitlow FirstSetBit_Lo
// Conservative depth output are supported only when >= 0x0500:
#define SV_Depth_GE SV_DepthGreaterEqual
#define SV_Depth_LE SV_DepthLessEqual
// SM4/3: Some semantics are specific optimization
// => remove the optim of the case:
#define SV_Depth_GE SV_Depth
#define SV_Depth_LE SV_Depth
///////////////////////// // fpart -> half/float // half type isn't really supported on some platforms (like PS4) // PS4 + wave compiler: // many implicit cast warning on float->half // some errors on trigo. function (/ex "sincos" expects float instead of half) // the only case of hardware for halfs is texture read // https://ps4.scedev.net/forums/thread/14647/
typedef float fpart; typedef float2 fpart2; typedef float3 fpart3; typedef float4 fpart4; typedef float3x3 fpart3x3; typedef float4x3 fpart4x3;
typedef half fpart; typedef half2 fpart2; typedef half3 fpart3; typedef half4 fpart4; typedef half3x3 fpart3x3; typedef half4x3 fpart4x3;
/////////////////////////
//////////////////////// // D3D11/PS4: on a besoin du split Texture/Sampler pour le shadow mapping !
// Enfin, le code de FXAA utilise une struct qui simplifie pas mal de truc (genre passage de param, var de struct) // à voir si les compilos supporte ça bien (et si on retrouve bien les 2 élements coté C++) // #define FxaaTex sampler2D // struct FxaaTex { SamplerState smpl; Texture2D tex; }; // les remapping passent par des méthodes avec #define dedans plutot que des #defines direct //
///////////////////// // D3D9 + bool registers: sometimes in D3D9, we've to force bool register to avoid getting float4 instead ! // (no longer needed in SM4) // when this ": register(b##__iReg)" syntax is used, a cbuffer can no longer be declared // else we get (only for D3D9 target): // X3530: cannot mix packoffset elements with nonpackoffset elements in a cbuffer // => MCBufferBegin/End allow to declare 'cbuffer' only in >=SM4:
#define MSM3_BoolRegister(__iReg)
#define MCBufferBegin(__Name) cbuffer __Name {
#define MCBufferEnd };
#define MSM3_BoolRegister(__iReg) : register(b##__iReg)
#define MCBufferBegin(__Name)
#define MCBufferEnd
///////////////////// // uint !! // D3D9 : error X3548: in ps_3_0 uints can only be used with known-positive values, use int if possible
// D3D11: warning X3556: integer modulus may be much slower, try using uints if possible.
// Ps4 : warning 9015: Div (/) and mod (%) are inefficient for 'int'. Consider using 'uint' instead
// ==>> uint sauf en D3D9, ou on fall-back en int !!
#define MSafe_uint uint
#define MSafe_uint2 uint2
#define MSafe_uint3 uint3
#define MSafe_uint4 uint4
#define MSafe_uint int
#define MSafe_uint2 int2
#define MSafe_uint3 int3
#define MSafe_uint4 int4
//////////////////// // MSafe_uint_div !! Utiliser MSafe_uintX pour déclarer les uints en entrée/sortie !! // MSafe_uint_mod !! Utiliser MSafe_uintX pour déclarer les uints en entrée/sortie !!
// >= SM4: on utilise des uint (bien supporté), c'est le type qu'on veut au final
#define MSafe_uint_div(_a, _b) ((_a)/(_b))
#define MSafe_uint_mod(_a, _b) ((_a)%(_b))
// <= SM3: uint pas supportés et int émulés via float (% très couteux)
#define MSafe_uint_div(_a, _b) (abs(_a)/(_b))
#define MSafe_uint_mod(_a, _b) (_a - _b*MSafe_uint_div(_a, _b))
// omettre 'abs' coute 11 arithm. (vec3)
// faire directement '/', '%' coute 23 arithm (vec3) !!
////////////////////
////////////////////
static const float Pi = 3.141592653f;
#define VULKAN_RM(__X)
#define inline
#define VULKAN_RM(__X) __X
// !! VULKAN only support [][] matrix indexation !! // First index is ROW, 2nd index is COLUMN
static inline float3 Matrix_GetRowX (in float2x3 m) {return m[0];} static inline float3 Matrix_GetRowY (in float2x3 m) {return m[1];}
static inline float3 Matrix_GetRowX (in float3x3 m) {return m[0];} static inline float3 Matrix_GetRowY (in float3x3 m) {return m[1];} static inline float3 Matrix_GetRowZ (in float3x3 m) {return m[2];}
static inline float3 Matrix_GetRowW (in float4x3 m) {return m[3];}
static inline float3 Matrix_GetColumnX (in float3x3 m) {return float3(m[0][0], m[1][0], m[2][0]);} static inline float4 Matrix_GetColumnX (in float4x2 m) {return float4(m[0][0], m[1][0], m[2][0], m[3][0]);} static inline float4 Matrix_GetColumnX (in float4x3 m) {return float4(m[0][0], m[1][0], m[2][0], m[3][0]);} static inline float4 Matrix_GetColumnX (in float4x4 m) {return float4(m[0][0], m[1][0], m[2][0], m[3][0]);}
static inline float3 Matrix_GetColumnY (in float3x3 m) {return float3(m[0][1], m[1][1], m[2][1]);} static inline float4 Matrix_GetColumnY (in float4x2 m) {return float4(m[0][1], m[1][1], m[2][1], m[3][1]);} static inline float4 Matrix_GetColumnY (in float4x3 m) {return float4(m[0][1], m[1][1], m[2][1], m[3][1]);} static inline float4 Matrix_GetColumnY (in float4x4 m) {return float4(m[0][1], m[1][1], m[2][1], m[3][1]);}
static inline float3 Matrix_GetColumnZ (in float3x3 m) {return float3(m[0][2], m[1][2], m[2][2]);} static inline float4 Matrix_GetColumnZ (in float4x3 m) {return float4(m[0][2], m[1][2], m[2][2], m[3][2]);} static inline float4 Matrix_GetColumnW (in float4x4 m) {return float4(m[0][3], m[1][3], m[2][3], m[3][3]);}
// Matrix Set
static inline float2x3 Matrix_SetRows (in float3 r0, in float3 r1) {float2x3 m; m[0] = r0; m[1] = r1; return m;} static inline float3x3 Matrix_SetRows (in float3 r0, in float3 r1, in float3 r2) {float3x3 m; m[0] = r0; m[1] = r1; m[2] = r2; return m;}
static inline float3x3 Matrix_SetColumns (in float3 c0, in float3 c1, in float3 c2)
{
float3x3 m;
m[0] = float3(c0[0], c1[0], c2[0]); // Row 0
m[1] = float3(c0[1], c1[1], c2[1]); // Row 1
m[2] = float3(c0[2], c1[2], c2[2]); // Row 1
return m;
}
static inline float4x2 Matrix_SetColumns (in float4 c0, in float4 c1)
{
float4x2 m;
m[0] = float2(c0[0], c1[0]); // Row 0
m[1] = float2(c0[1], c1[1]); // Row 1
m[2] = float2(c0[2], c1[2]);
m[3] = float2(c0[3], c1[3]);
return m;
}
static inline void Matrix4x4_Set (out float4x4 Dst, in float4x3 Src) { Dst[0] = float4(Src[0], 0); // Row 0 Dst[1] = float4(Src[1], 0); // Row 1 Dst[2] = float4(Src[2], 0); Dst[3] = float4(Src[3], 1); }
//////////////////// // Quaternions:
fpart3x3 QuatGetFloat3x3(in fpart4 _Quat)
{
float xs,ys,zs,wx,wy,wz,xx,xy,xz,yy,yz,zz;
xs = 2.0f _Quat.x;
ys = 2.0f _Quat.y;
zs = 2.0f _Quat.z;
wx = _Quat.w xs;
wy = _Quat.w ys;
wz = _Quat.w zs;
xx = _Quat.x xs;
xy = _Quat.x ys;
xz = _Quat.x zs;
yy = _Quat.y ys;
yz = _Quat.y zs;
zz = _Quat.z zs;
return Matrix_SetRows(
float3(1.0f - yy - zz, xy + wz, xz - wy),
float3(xy - wz, 1.0f - xx - zz, yz + wx),
float3(xz + wy, yz - wx, 1.0f - xx - yy)
);
}
fpart3 MulQuat(in fpart3 v, in fpart4 q) { fpart3 r2; r2.x = (q.yv.z - q.zv.y) + q.wv.x; r2.y = (q.zv.x - q.xv.z) + q.wv.y; r2.z = (q.xv.y - q.yv.x) + q.wv.z; fpart3 r; r.x = (r2.zq.y - r2.yq.z)2 + v.x; r.y = (r2.xq.z - r2.zq.x)2 + v.y; r.z = (r2.yq.x - r2.xq.y)2 + v.z; return r; }
Unreal Engine 4 shaders are heavily
#ifdef
ed, and most of those are defined at shader compile time by CPU code. This results in large parts of code being greyed out in the VS editor due to#if
arguments evaluating to 0.Thus, it would be nice to define these from a dialog somewhere, preferably associated with the project.