hecomi / uRaymarching

Raymarching Shader Generator in Unity
http://tips.hecomi.com/entry/2019/01/27/233137
MIT License
1.35k stars 131 forks source link

Fix "cutout" effect on full screen #24

Open Phylliida opened 3 years ago

Phylliida commented 3 years ago

Setting to full screen makes it only render on the inner half of the screen, you can fix this by changing

#ifdef FULL_SCREEN
    o.pos = v.vertex;
#else

To

#ifdef FULL_SCREEN
    o.pos = UnityObjectToClipPos(v.vertex);
#else

In whatever shader your generated code imports, for example at the bottom mine had

...
    ZWrite [_ZWrite]

    CGPROGRAM
    #include "Assets\uRaymarching\Shaders\Include\Legacy/ForwardBaseStandard.cginc"
    #pragma target 3.0
    #pragma vertex Vert
    #pragma fragment Frag
    #pragma multi_compile_instancing
    #pragma multi_compile_fog
    #pragma multi_compile_fwdbase
    ENDCG
...

So I needed to modify that line in

#include "Assets\uRaymarching\Shaders\Include\Legacy/ForwardBaseStandard.cginc"
hecomi commented 3 years ago

Are you using the generated material with the RaymarchingRenderer component? The line o.pos = v.vertex means that the rectangle generated by that component at runtime will be rendered to (-1, -1) ~(+1, +1) in screen space without any MVP matrix multiplication. So we don't expect to use UnityObjectToClipPos() here. What settings (Unity version, rendering pipeline, scene settings) are you using?

Phylliida commented 3 years ago

Yes, the generated material. This "cutout" effect is happening in the unity editor for me (editor camera and game camera), using legacy pipeline DX11, tweaking distance function of hexagon example and only changing it so Full Screen is On and Camera Inside Object True, made scale of Cube transform larger (30x30x30), Unity 2020.3.7f1.

hecomi commented 3 years ago

If you just change the checkbox, the result will look like this:

image

If you want to see it in full screen, please use the RaymarchingRenderer component as instructed in the documentation.

If you are already using it, please give me a screenshot of your settings and results so that I can better identify the problem.

Phylliida commented 3 years ago

Ah, nice I had missed that, thank you :) Your screenshot is showing the issue I was having, I will switch to using using the quad