UE4 Shader code : GLSL to HLSL UE4/Tips&Ugh2021. 5. 9. 09:12
ex)
vec3 r = (1.4 + 2.0*Smoothness) * Radii - Smoothness;
-> float3 r = (1.4 + 2.0*Smoothness) * Radii - Smoothness;
GLSL/HLSL/Metal 命令対応表
- HLSL = DirectX (D3D8/D3D9/D3D10/D3D11/D3D12)
- GLSL = OpenGL 2/3/4, OpenGL ES 2/3, Vulkan, SpliteKit (watchOS)
- Metal = Metal (iOS/tvOS/macOS)
GLSLHLSLMetal
float | float | float | |
– | float1 | – | HLSLのみ single vector 可能 |
vec2/vec3/vec4 | float2/float3/float4 | float2/float3/float4 | |
mat3 | float3x3 | float3x3 | |
mat4 | float4x4 | float4x4 | |
mat3x4 | float3x4 | float3x4 | |
int | int | int | |
ivec2/ivec3/ivec4 | int2/int3/int4 | int2/int3/int4 | |
uint | uint | uint (unsigned int) | |
uvec2/uvec3/uvec4 | uint2/uint3/uint4 | uint2/uint3/uint4 | |
bool | bool | bool | |
bvec2/bvec3/bvec4 | bool2/bool3/bool4 | bool2/bool3/bool4 | |
lowp float | min10float | – | 10bit fixed 以上 |
mediump float | half (min16float) | half | 16bit fp 以上 |
highp float | float | float | 32bit fp |
double | double | – | 64bit fp |
highp int / uint | int / uint | int / uint | 32bit int |
mediump int / uint | min16int / min16uint | short / ushort | 16bit int 以上 |
lowp int / uint | min12int | – | 9bit int 以上 |
– | – | char / uchar | 8bit int |
vec3 x= vec3( a, b, c ); | float3 x= { a, b, c }; | float3 x= { a, b, c }; | |
float3 x= float3( a, b, c ); | float3 x= float3( a, b, c ); | ||
float x[3]= float[]( a, b, c ); | float x[3]= { a, b, c }; | float x[3]= { a, b, c }; | |
type( x ) | (type)x | (type)x, type(x) | cast |
matrix * matrix | mul( matrix, matrix ) | matrix * matrix | |
vector * matrix | mul( vector, matrix ) | vecotr * matrix | |
uniform | (uniform) | constant | |
in/out , varying/attribute | var : semantics | var [[qualifier]] | HLSL は in/out に function の引数と戻り値を使う。 |
builtin gl_* variables | system semantics SV_* | var [[qualifier]] |
GLSLHLSLMetal
inversesqrt( x ) | rsqrt( x ) | rsqrt( x ) | 1/sqrt( x ) |
mix( x, y, s ) | lerp( x, y, s ) | mix( x, y, s ) | |
clamp( x, min, max ) | clamp( x, min, max ) | clamp( x, min, max ) | |
clamp( x, 0.0, 1.0 ) | saturate( x ) | saturate( x ) | |
step( edge, x ) | step( edge, x ) | step( edge, x ) | x < edge ? 0.0 : 1.0 |
smoothstep( min, max, x ) | smoothstep( min, max, x ) | smoothstep( min, max, x ) | clamp( (x-min) / (max-min), 0.0, 1.0 ) |
GLSLHLSLMetal
sampler2D samplerobj | Texture2D<type> texobj | texture2d<type> texobj | sampler type |
sampler2DShadow depthobj | Texture2D<type> depthobj | depth2d<type> depthobj | sampler type |
v= texture( samplerobj, texcoord.. ); | v= texobj.Sample( texcoord.. ); | v= texobj.sample( sampler, texcoord .. ) | sampling |
v= texture2D( sampleobj, texcoord.. ); | v= tex2D( sampler, texcoord.. ); | – | legacy syntax |
v= textureGather( depthobj, texcoord.. ); | v= depthobj.SampleCmp( texcoord.. ); | v= depthobj.sample_compare( … ) | pcf shadow map |
shaderGLSLHLSLMetal
vsh | in int gl_VertexID; | uint var_name : SV_VertexID ; | uint var_name [[vertex_id]]; |
in int gl_InstanceID; | uint var_name : SV_InstanceID ; | uint var_name [[instance_id]]; | |
out vec4 gl_Position; | float4 … : SV_Position ; | float4 ... [[position]]; | |
fsh/psh | out vec4 color; (GL2: gl_FragColor) | float4 … : SV_Target ; (DX9: COLOR) | half4 ... [[color(0)]]; |
out float gl_FragDepth; | float … : SV_Depth ; (DX9: DEPTH) | float ... [[depth(less)]]; |
docs.microsoft.com/ko-kr/windows/uwp/gaming/glsl-to-hlsl-reference
HLSL 참조 - UWP applications
OpenGL ES 2.0에서 Direct3D 11로 그래픽 아키텍처를 이식할 유니버설 Windows 플랫폼 (UWP) 게임을 만들려면 그래픽 아키텍처를 Microsoft HLSL (High Level Shader Language) 코드로 이식 합니다.
docs.microsoft.com
dench.flatlib.jp/opengl/glsl_hlsl
opengl:glsl_hlsl [HYPERでんち]
opengl:glsl_hlsl HLSL = DirectX (D3D8/D3D9/D3D10/D3D11/D3D12) GLSL = OpenGL 2/3/4, OpenGL ES 2/3, Vulkan, SpliteKit (watchOS) Metal = Metal (iOS/tvOS/macOS) GLSL HLSL Metal float float float – float1 – HLSLのみ single vector 可能 vec2/vec3/vec4 flo
dench.flatlib.jp
docs.microsoft.com/en-us/windows/uwp/gaming/glsl-to-hlsl-reference
GLSL-to-HLSL reference - UWP applications
You port your OpenGL Shader Language (GLSL) code to Microsoft High Level Shader Language (HLSL) code when you port your graphics architecture from OpenGL ES 2.0 to Direct3D 11 to create a game for Universal Windows Platform (UWP).
docs.microsoft.com
'UE4 > Tips&Ugh' 카테고리의 다른 글
Custom HLSL tips (0) | 2021.08.09 |
---|---|
Custom Primitive Data (Material) (0) | 2021.05.22 |
UE4 - Particle emitter sorting problem (0) | 2017.09.20 |
Black Body Node (0) | 2017.03.29 |
issue (0) | 2017.03.10 |