@Darren wrote:
Hi,
I wanted to reply to this thread but unfortunately it’s closed
https://discuss.cocos2d-x.org/t/are-you-using-v4-metal-currently/47145/48Anw, thank you cocos2d-x team for bringing Metal support in v4.0! I have been using it and it works fine out of the box.
However, i have bump into an issue with my custom shaders. For example in this code snippet.void main() { v_fragmentColor = a_color; v_texCoord = a_texCoord; vec2 flowDir = vec2(texture2D(u_flowTexture, a_texCoord).rg); . . . vec4 pos = a_position; pos.xy -= flowDir * u_time; gl_Position = u_MVPMatrix * pos; }
After going through the glsl-optimiser, the
vec2 flowDir
is swapped with a type ofhalf4
instead offloat4
. And sincegl_Position
underwent some operation withvec4 pos
, which underwent an operation withflowDir
, this resulted in gl_Position being declared as a half4 and not float4 and this will cause the Metal shader to fail to compile because vertex shader has to return afloat4 gl_Position
.Basically, if the gl_Position is calculated from anything that derives from a variable that derives from a
half
, it will have the precision reduced to half instead offloat
. And I notice that anything that results fromtexture2D
operation always result in ahalf
.Has anybody came across this issue and found a solution for it?
I had a temporary fix for this on a leaner project, whereby I have a separate file for the Metal shader that I manually corrected the variable type. But I had to perform some edit to the engine’s renderer codes so that it takes in a separate file.
But I don’t think this is a viable solution when it comes to a big project. The ideal case is to manage just 1 file for each shader instead of having to manage different shader language versions of it.
Posts: 1
Participants: 1