バージョンアップをした際、テクスチャが正常にマージされなくなりました。
いままでは、以下の関数を実行するだけでよかったのですが、どうやら、バージョンアップの際にテクスチャの形式が自動的に変更されてしまったようで、そこで互換性が無くなってしまったものと思われます。原因が解る方いましたら助けてください。
ComputeShader shader; public Texture tex,tex2; //Margeするテクスチャー(同サイズ) public void texmarge(){ RenderTexture UnitChip = new RenderTexture(4096/2, 4096/2, 0); // UnitChip.enableRandomWrite = true; UnitChip.Create(); shader.SetFloat("w", tex.width); shader.SetFloat("h", tex.height); shader.SetTexture(shader.FindKernel("CSMarge"), "tex", tex); shader.SetTexture(shader.FindKernel("CSMarge"), "tex2", tex2); shader.SetTexture(shader.FindKernel("CSMarge"), "Debug", UnitChip); shader.Dispatch(shader.FindKernel("CSMarge"), tex.width / 8, tex.height / 8, 1); this.gameObject.GetComponent<Renderer>().material.mainTexture = UnitChip; }
#pragma kernel CSMarge float w, h; Texture2D<float4> tex, tex2; RWTexture2D<float4> Debug; [numthreads(8, 8, 1)] void CSMarge(uint3 id : SV_DispatchThreadID) { float4 col = tex[id.xy]; if (col.a ==0) col= float4(0, 0, 0, 0); float4 col2 = tex2[id.xy]; if (col2.a == 0) col2 = float4(0, 0, 0, 0); col += col2; Debug[id.xy] = col; }
「// UnitChip.enableRandomWrite = true;」のコメントアウトを解除してもだめでしょうか?私の環境で試した感じですと、Metal上ではコメントアウトしたままでもテクスチャが合成されましたが、Direct3D 11上では結果が書き込まれていませんでした。Windowsタグが付いていますのでDirect3Dかと思いますが、旧バージョンではコメントアウトしたままで動作したのでしょうか(旧バージョンでコンピュートシェーダーを使った経験がないので、どういう動作になるのか分からないのです...すみません)。
あなたの回答
tips
プレビュー