Hello, I am attempting to voxelize the scene through a logical blending operation using the dx 11.1 blend ops referenced here. However, this appears to have no effect in the final render I am using the dx 11 option in the player settings, and other blend modes, such as Min, Max, etc. seem to work fine. I have attached references to compare against the effect from max blending (since I write 32 bits per channel with ARGBFloat format). Any ideas or suggestions on what might be causing the problem are greatly appreciated. Thank you! References: With Logical Blending: With Max Blending: Shader Code: Code (CSharp): Shader "Hidden/T_Voxelize" { Properties { _MainTex("Base (RGB)", 2D) = "black" {} } CGINCLUDE #include "UnityCG.cginc" struct appdata_t { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; float vdist : TEXCOORD0; }; uniform sampler2D _MainTex; v2f vert (appdata_t v) { v2f o; o.vertex = mul(UNITY_MATRIX_MV, v.vertex); o.vdist = -o.vertex.z; o.vertex = mul(UNITY_MATRIX_P, o.vertex); return o; } float4 frag (v2f i) : SV_Target { int shift = floor(i.vdist / _ProjectionParams.z * 127 + 0.5); float rshift = shift > 31 ? 0 : 1 << shift; float gshift = shift > 63 || shift < 32 ? 0 : 1 << (shift - 32); float bshift = shift > 95 || shift < 64 ? 0 : 1 << (shift - 64); float ashift = shift < 96 ? 0 : 1 << (shift - 96); return float4(rshift, gshift, bshift, ashift); } ENDCG SubShader { Pass { Fog { Mode Off } ZTest Always Cull Off ZWrite Off Blend One One BlendOp LogicalOr CGPROGRAM #pragma target 5.0 #pragma vertex vert #pragma fragment frag ENDCG } } Fallback off }
After looking at this some more, it seems that for some reason the logical blendops do not work when rendering into an ARGBFloat format render texture (any ideas as to why would be appreciated). Anyway, after modifying the shader to render into 4 ARGB32 targets I am getting the desired result for the first 3 targets; however, the last target is not being filled out and I am receiving a strange error message "count < kMaxSupportedRenderTargets" when calling Camera.RenderWithShader(). From what I have seen with multiple render targets, I should be able to render into 4 with my current hardware, so I am puzzled about this error message. Furthermore, when reducing down to 3 render targets, the message goes away. Any ideas/suggestions on what might be causing the error would be greatly appreciated. I have also added the updated shader and draw call code below. Shader: Code (CSharp): Shader "Hidden/T_Voxelize" { CGINCLUDE #include "UnityCG.cginc" struct appdata_t { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; float vdist : TEXCOORD0; }; struct f2a { float4 col0 : SV_Target0; float4 col1 : SV_Target1; float4 col2 : SV_Target2; float4 col3 : SV_Target3; }; v2f vert (appdata_t v) { v2f o; o.vertex = mul(UNITY_MATRIX_MV, v.vertex); o.vdist = -o.vertex.z; o.vertex = mul(UNITY_MATRIX_P, o.vertex); return o; } f2a frag (v2f i) { f2a o; int shift = floor(i.vdist / _ProjectionParams.z * 127 + 0.5); float r1 = shift > 7 ? 0 : 1 << shift; float g1 = shift > 15 || shift < 8 ? 0 : 1 << (shift - 8); float b1 = shift > 23 || shift < 16 ? 0 : 1 << (shift - 16); float a1 = shift > 31 || shift < 24 ? 0 : 1 << (shift - 24); float r2 = shift > 39 || shift < 32 ? 0 : 1 << (shift - 32); float g2 = shift > 47 || shift < 40 ? 0 : 1 << (shift - 40); float b2 = shift > 55 || shift < 48 ? 0 : 1 << (shift - 48); float a2 = shift > 63 || shift < 56 ? 0 : 1 << (shift - 56); float r3 = shift > 71 || shift < 64 ? 0 : 1 << (shift - 64); float g3 = shift > 79 || shift < 72 ? 0 : 1 << (shift - 72); float b3 = shift > 87 || shift < 80 ? 0 : 1 << (shift - 80); float a3 = shift > 95 || shift < 88 ? 0 : 1 << (shift - 88); float r4 = shift > 103 || shift < 96 ? 0 : 1 << (shift - 96); float g4 = shift > 111 || shift < 104 ? 0 : 1 << (shift - 104); float b4 = shift > 119 || shift < 112 ? 0 : 1 << (shift - 112); float a4 = shift < 120 ? 0 : 1 << (shift - 120); o.col0 = float4(r1, g1, b1, a1); o.col1 = float4(r2, g2, b2, a2); o.col2 = float4(r3, g3, b3, a3); o.col3 = float4(r4, g4, b4, a4); return o; } ENDCG SubShader { Pass { Fog { Mode Off } ZTest Always Cull Off ZWrite Off Blend One One BlendOp LogicalOr CGPROGRAM #pragma target 5.0 #pragma vertex vert #pragma fragment frag ENDCG } } Fallback off } C#: Code (CSharp): private void OnPreRender() { for (int i = 0; i < 4; i++) { _voxelBuffers[i] = RenderTexture.GetTemporary (128, 128, 0, RenderTextureFormat.ARGB32); _voxelBuffers[i].filterMode = FilterMode.Point; _voxelBuffers[i].wrapMode = TextureWrapMode.Clamp; _voxelBuffers[i].useMipMap = true; _voxelBuffers[i].DiscardContents (); _voxelColorBuffers[i] = _voxelBuffers[i].colorBuffer; } _voxelCam.SetTargetBuffers (_voxelColorBuffers, _voxelBuffers[0].depthBuffer); _voxelCam.RenderWithShader (_voxelizeShader, string.Empty); _giMaterial.SetTexture ("_VoxelBuffer0", _voxelBuffers[0]); _giMaterial.SetTexture ("_VoxelBuffer1", _voxelBuffers[1]); _giMaterial.SetTexture ("_VoxelBuffer2", _voxelBuffers[2]); _giMaterial.SetTexture ("_VoxelBuffer3", _voxelBuffers[3]); }