ユーザ用ツール

サイト用ツール


opengl:glsl_hlsl

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)
GLSL HLSL Metal
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]]
GLSL HLSL Metal
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 )
GLSL HLSL Metal
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
shader GLSL HLSL Metal
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)]];

Blend

OpenGL id Direct3D 11
GL_ZERO 1 D3D11_BLEND_ZERO
GL_ONE 2 D3D11_BLEND_ONE
GL_SRC_COLOR 3 D3D11_BLEND_SRC_COLOR
GL_ONE_MINUS_SRC_COLOR 4 D3D11_BLEND_INV_SRC_COLOR
GL_SRC_ALPHA 5 D3D11_BLEND_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA 6 D3D11_BLEND_INV_SRC_ALPHA
GL_DST_ALPHA 7 D3D11_BLEND_DEST_ALPHA
GL_ONE_MINUS_DST_ALPHA 8 D3D11_BLEND_INV_DEST_ALPHA
GL_DST_COLOR 9 D3D11_BLEND_DEST_COLOR
GL_ONE_MINUS_DST_COLOR 10 D3D11_BLEND_INV_DEST_COLOR
GL_SRC_ALPHA_SATURATE 11 D3D11_BLEND_SRC_ALPHA_SAT
GL_CONSTANT_COLOR 14 D3D11_BLEND_BLEND_FACTOR
GL_ONE_MINUS_CONSTANT_COLOR 15 D3D11_BLEND_INV_BLEND_FACTOR
GL_SRC1_COLOR 16 D3D11_BLEND_SRC1_COLOR
GL_ONE_MINUS_SRC1_COLOR 17 D3D11_BLEND_INV_SRC1_COLOR
GL_SRC1_ALPHA 18 D3D11_BLEND_SRC1_ALPHA
GL_ONE_MINUS_SRC1_ALPHA 19 D3D11_BLEND_INV_SRC1_ALPHA
OpenGL id Direct3D 11
GL_FUNC_ADD 1 D3D11_BLEND_OP_ADD
GL_FUNC_SUBTRACT 2 D3D11_BLEND_OP_SUBTRACT
GL_FUNC_REVERSE_SUBTRACT 3 D3D11_BLEND_OP_REV_SUBTRACT
GL_MIN 4 D3D11_BLEND_OP_MIN
GL_MAX 5 D3D11_BLEND_OP_MAX

Buffer

OpenGL Direct3D
GL_ARRAY_BUFFER D3D11_BIND_VERTEX_BUFFER VertexBuffer
GL_ELEMENT_ARRAY_BUFFER D3D11_BIND_INDEX_BUFFER IndexBuffer
GL_UNIFORM_BUFFER D3D11_BIND_CONSTANT_BUFFER ConstantBuffer
GL_TRANSFORM_FEEDBACK_BUFFER D3D11_BIND_STREAM_OUTPUT
GL_VERTEX_ARRAY_BINDING D3D11InputLayout
OpenGL Direct3D
GL_STATIC_DRAW D3D11_USAGE_IMMUTABLE
GL_STREAM_DRAW D3D11_USAGE_DYNAMIC
GL_DYNAMIC_COPY? D3D11_USAGE_DEFAULT
GL_*_READ D3D11_USAGE_STAGING

Texture

OpenGL Direct3D
S3TC/DXT1 DXT1/BC1
S3TC/DXT3 DXT3/BC2
S3TC/DXT5 DXT5/BC3
RGTC 3DC/BC4/BC5
BPTC BC6H/BC7
OpenGL Direct3D9 Direct3D11
min + mip mag min mag mip
GL_NEAREST GL_NEAREST D3DTEXF_POINT D3DTEXF_POINT D3DTEXF_NONE
GL_LINEAR GL_NEAREST D3DTEXF_LINEAR D3DTEXF_POINT D3DTEXF_NONE
GL_NEAREST GL_LINEAR D3DTEXF_POINT D3DTEXF_LINEAR D3DTEXF_NONE
GL_LINEAR GL_LINEAR D3DTEXF_LINEAR D3DTEXF_LINEAR D3DTEXF_NONE
GL_NEAREST_MIPMAP_NEAREST GL_NEAREST D3DTEXF_POINT D3DTEXF_POINT D3DTEXF_POINT D3D11_FILTER_MIN_MAG_MIP_POINT
GL_LINEAR_MIPMAP_NEAREST GL_NEAREST D3DTEXF_LINEAR D3DTEXF_POINT D3DTEXF_POINT D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT
GL_NEAREST_MIPMAP_NEAREST GL_LINEAR D3DTEXF_POINT D3DTEXF_LINEAR D3DTEXF_POINT D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT
GL_LINEAR_MIPMAP_NEAREST GL_LINEAR D3DTEXF_LINEAR D3DTEXF_LINEAR D3DTEXF_POINT D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT
GL_NEAREST_MIPMAP_LINEAR GL_NEAREST D3DTEXF_POINT D3DTEXF_POINT D3DTEXF_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
GL_LINEAR_MIPMAP_LINEAR GL_NEAREST D3DTEXF_LINEAR D3DTEXF_POINT D3DTEXF_LINEAR D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR
GL_NEAREST_MIPMAP_LINEAR GL_LINEAR D3DTEXF_POINT D3DTEXF_LINEAR D3DTEXF_LINEAR D3D11_FILTER_MIN_POINT_MAG_MAIP_LINEAR
GL_LINEAR_MIPMAP_LINEAR GL_LINEAR D3DTEXF_LINEAR D3DTEXF_LINEAR D3DTEXF_LINEAR D3D11_FILTER_MIN_MAG_MIP_LINEAR
D3DTEXF_ANISOTROPIC D3DTEXF_ANISOTROPIC D3D11_FILTER_ANISOTROPIC
  • Mip Linear = Tri Linear Filter
OpenGL Direct3D
GL_REPEAT D3D11_TEXTURE_ADDRESS_WRAP
GL_MIRRORED_REPEAT D3D11_TEXTURE_ADDRESS_MIRROR
GL_CLAMP_TO_EDGE D3D11_TEXTURE_ADDRESS_CLAMP
GL_CLAMP_TO_BORDER D3D11_TEXTURE_ADDRESS_BORDER
D3D11_TEXTURE_ADDRESS_MIRROR_ONCE
opengl/glsl_hlsl.txt · 最終更新: 2016/09/12 14:53 by oga

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki