I've been trying to do a port job to metal of the imgui implementation described at viewtopic.php?t=89081.
I have the original port working and tested on opengl on linux also using the pso changes mentioned here viewtopic.php?t=93889.
My next job is going to be porting what I have to metal (macos), however I've hit a snag.
The imgui port relies on being able to send data to the shaders, for example it sends its own projection matrix to the shader like this:
Code: Select all
Ogre::Matrix4 projMatrix(2.0f / io.DisplaySize.x, 0.0f, 0.0f, -1.0f,
0.0f, -2.0f / io.DisplaySize.y, 0.0f, 1.0f,
0.0f, 0.0f, -1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
mPass->getVertexProgramParameters()->setNamedConstant("ProjectionMatrix", projMatrix);
Then looking through some of the ogre example shaders I found things like:
Code: Select all
struct Params
{
float4x4 worldViewProj;
float3x4 worldScaledMatrix;
float3 probeCameraPosScaled;
};
vertex PS_INPUT main_metal
(
VS_INPUT input [[stage_in]],
constant Params &p [[buffer(PARAMETER_SLOT)]]
)
{
}
I've been able to send things like the world view projection matrix with stuff like this:
Code: Select all
fragment_program Example_ps_metal metal
{
source example.metal
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
}
}
Code: Select all
#include <metal_stdlib>
using namespace metal;
struct PS_INPUT
{
float2 uv0;
};
fragment float4 main_metal
(
PS_INPUT inPs [[stage_in]]
)
{
if(inPs.uv0.x < 0.5){
return float4( 1.0, 1.0, 1.0, 1.0);
}else{
return float4( 1.0, 0.0, 1.0, 1.0);
}
}
What I'd like is to be able to send arbitrary types of data to the shader, like the custom projection matrix above.
Does anyone know how this is achieved with the ogre api for a metal shader?
My assumption would be that there is some way to specify values at indexes in the buffer, but I haven't been able to find anything like this in the samples or api docs.
I've noticed a few references to
constant Params &p [[buffer(PARAMETER_SLOT)]]
in the samples. Does PARAMETER_SLOT have anything to do with what I might want?
I just can't seem to find anything that sends over values from the c++.
What I have found makes me think this is some way for the hlms to send values.
I noticed there was a bit at the end of the porting manual about buffers, but this mostly went over my head.
Would I be right in thinking that this has nothing to do with what I'm trying to do?
Does setNamedConstant() even work for metal?
Whenever I tried to use it it was telling me that the constant in the shader couldn't be found.
I might have set it up wrong, but to me that approach seems very glsl, so maybe this is the case?
I feel like I'm just missing something obvious.
As a next step I'd like to be able to do something like render a triangle with a colour set as a constant from c++.
If anyone knows anything about Ogre's metal implementation I'd greatly appreciate your expertise!