Cocoa アプリ内からいくつかの PNG ファイルのサイズを変更しています。ファイルは最終的に別のアプリによって OpenGL テクスチャとして読み込まれ、適切に記述されていないシェーダーが適用されます。このシェーダーは、ある時点で次のことを行います。
texColor = mix(constant,vec4(texColor.rgb/texColor.a,texColor.a),texColor.a);
アルファで除算するのは悪い考えです。解決策は、そのステップで texColor の RGB コンポーネントが 1 を超えないようにすることです。しかし! 好奇心のために:
元の PNG (GIMP で作成) は驚くほど正常に動作し、GIMP で作成されたサイズ変更されたバージョンも正常に動作します。ただし、以下のコードを使用してファイルのサイズを変更すると、透過ピクセルの近くでテクスチャがギザギザになりpercent
ます1.0
。これらの画像を無意識のうちに変更していて、突然シェーダーのバグが発生する原因が何か分かりますか?
NSImage* originalImage = [[NSImage alloc] initWithData:[currentFile regularFileContents]];
NSSize newSize = NSMakeSize([originalImage size].width * percent, [originalImage size].height * percent);
NSImage* resizedImage = [[NSImage alloc] initWithSize:newSize];
[resizedImage lockFocus];
[originalImage drawInRect:NSMakeRect(0,0,newSize.width,newSize.height)
fromRect:NSMakeRect(0,0,[originalImage size].width, [originalImage size].height)
operation:NSCompositeCopy fraction:1.0];
[resizedImage unlockFocus];
NSBitmapImageRep* bits = [[[NSBitmapImageRep alloc] initWithCGImage:[resizedImage CGImageForProposedRect:nil context:nil hints:nil]] autorelease];
NSData* data = [bits representationUsingType:NSPNGFileType properties:nil];
NSFileWrapper* newFile = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
[newFile setPreferredFilename:currentFilename];
[folder removeFileWrapper:currentFile];
[folder addFileWrapper:newFile];
[originalImage release];
[resizedImage release];