Forum

How to "project" on only nearest face of DX11 geometry?

ConstantProjection (DX11.Effect) “projects” on both the front and back sides of an object. There is a DX9 version, ProjectedTexture (EX9.Effect) that has a front face-only input pin to toggle this behavior.

Seems like I figured this out in the dim past, but maybe I’m just thinking of the DX9 version. Is there a way to do this in DX11? I looked at the code in the DX9 shader, which is a very simple conditional:

    //show only if projection comes from the front
	if (FrontOnly)
    	if(input.angle.x < 0) 
			col = BorderColor;

but no idea how to do something similar in the DX11 ConstantProjection code. Athankew!

Not sure I get you right, maybe you’re looking for SV_IsFrontFace?

The issue is not the side of a face that it is projecting on, it’s that it puts the image on the side of an object opposite the “projector” as well as the side closest to it. If you run the help patch for ProjectedTexture (EX9.Effect) and toggle the “front project only” toggle you’'ll see what I mean (you’ll need to rotate the view to see it, such as on the back of the handle).

ConstantProjection (DX11.Effect) does not have this toggle, and always projects on the side opposite the projector. I just don’t know how to do the same thing in DX11 as in that DX9 code snippet above, such as how to get that angle to test.

I think there might be a test with z w components after the projection is applied.
I’m not sure but it is possible that if projected point’s z component less then 1 means that it’s oposite direction from camera, but i can be wrong… The second option also, on PointeditorCS i remeber i had this problem with selection, that you had vertices behind your camera selected also, maybe there is some fix in the selecting shader.

Hmmm I thought about this a bit more, and realized that angle test really just eliminates faces away from the projector, but does not do what one would really want which is to use only the first or closest face to the projector. In the attached modified DX9 help patch, you can see that the handle does not cast a shadow on the pot, and in fact the spout gets the image too though it is behind the pot from the projector’s perspective.

So to realy work like one would expect, seems like this should work like a shadow-casting point light with a gobo. I expect a depth map is used in there somewhere, dunno, never looked into shadow code.

I’m trying to visualize in DX11 what a multi-projector setup will look like in a complex environment, and all this back face and no shadow business is making it a total mess. Odd this hasn’t come up more; there is an old thread about the DX9 version along these lines, but surely other folks have tried to do similar visualizations since then…

ProjectedTexture noshadow.v4p (16.8 KB)

Back in the days there was a patch by Elliot to simulate physical projectors I think. I guess with some tinkering to find out your FOV you can also use Superphysical and a spotlight to project your texture. Volumetric lights in the superphysical engine will also make it look nice in simulations.

why not visualize multi-projectors under superphysical with spotlight texture ?

[PAID AD]
@mediadog have you considered doing this in vvvv gamma instead? VL.Stride comes with a node called ProjectorLight that should be very convenient to do exactly that. for an example see the “Project a texture” howto in the helpbrowser.

@ggml and @joreg thanks for the suggestions, and yes Superphysical can do it, but those are both pretty high-impact solutions, not something that can be easily slid into existing applications.

flashback friday! i have a fairly lightweight solution using vanilla DX11 that might fit your requirements: ProjectorCoverage (DX11).zip (10.2 KB)

1 Like

Poifect! And the projectors even add on common faces. Thanks a ton!

Hmm. well turns out it’s only half-perfect. Using the OpenVR plugin with this, I only get the projections in the left eye; the right eye has the scene but no projections on anything. This is a major bummer as I am doing this mainly in VR. Any idea what is happening? This is the first case of this I have seen with any shader.

Also, I found that when there are objects behind objects, and they both have projections one them (via a spread of projectors and textures), things look fine from a distance, but as I get closer to the front object the projections on the objects behind it become visible well before I go “through” the front object. In fact projections on multiple objects stacked in depth show up as if they were all transparent just by getting close to the front one.

I poked around in the plugin, and found that in the ProjectorCoverage patch, if I set the DepthStencil node Depth Bias input pin to 0 (it was -11) then this problem disappears. I can see no side-effect; why was it -11? Is there a downside to it being 0 that I have not seen yet?

About the Depth Bias being -11, I don’t remember why I set it to this value … probably messing around to make it work better in the specific use case I had … feel free to do the same ;)

Edit: Guess, it was at -11 to remove some artifacts caused by certain view angles and DepthStencil > Comparison = Less. Setting that to LessEqual solves those.

About the OpenVR plugin problem: I have not worked with that myself, but after a quick download it seems it is feeding two viewports to the renderer.

In ProjectorCoverage (DX11) > Projection.fx > VS there is a viewport related check.

Replacing

//transform position, if not in viewport, then resize mesh subset to zero
if (asuint(Index)%asuint(ViewCount) == asuint(ViewIndex)) {
	Out.Pos = mul(input.PosO, tWVP);
}
else {
	Out.Pos = 0;
}    

with

Out.Pos = mul(input.PosO, tWVP);

gave the expected result in both Viewports.

The check was a feature in the shader I based the module on, but was not used anyway, so there should be no problem with removing it this way.

Thanks, that fixed the VR problem. And yes, setting the Depth Bias to zero and Comparison to LessEqual works great.

While testing it in VR, I found some artifacts whenever I am directly facing a plane that is being projected on - it’s the kind of banding you see when two planes are in exactly the same location with different textures/colors. I checked in a normal Renderer, and can see it there, it’s just much harder to look perfectly perpendicular to the plane:

I poked around on the various setting and could not make this go away. Not a big deal, it’s very useful as it is, but happens surprisingly often in VR and is somewhat jarring. Any ideas on it? Thanks @mxmi!

The bias usually used to offset projected object by a little to remove artefacts when objects overlapping, I think the proper value is 0.01

What antokhio said.

Due to the hacky nature of the solution and its original use for distant-view visualisation of projection setups it invariably falls apart if you go close but you can try the following settings:

ProjectorCoverage > WorldPosTolerance = 0.0001

ProjectorCoverage > Rasterizer > Depth Bias = -1 (only accepts Int)
ProjectorCoverage > Rasterizer > Depth Bias Clamp = -0.0001
ProjectorCoverage > Rasterizer > Slope Scaled Depth Bias = -0.1

ProjectorCoverage > DepthStencil > Comparison = LessEqual