Material for photogrammetry environment? real time casted shadows over unlit material?


I´m reviving this topic because I would like to have shadows casted over a photogrammetry taken environment, with this I mean a full environment with it´s shadows on it, I don´t like to calculate all the lighting of the environment.
What I would like to do is to have that “unlit” environment, but if I place an object, it would cast shadows over the environment (I don´t care about shadows not being perfectly mixed with the environment shadows), those would be real time shadows not baked shadows, and the environment don´t have to be lit at all, just catch the shadow of the object casted by a real time light.

Can this be done? Specially now that we have forward rendering? (this is for VR)

I´m on a struggle here and I don´t know what to do.

I tried using a normal material with everything at 0 but it won´t catch shadows, I tried using the same texture for emmisive and base color but multiplied by 0.5 so I can get some shadow, but then the environment it´s also affected by light.

In short, what I need is a material that can catch shadows casted by objects but that is not affected by lights, is the only way to recreate something in photogrammetry and mix with 3d objects properly.

Help please, I´m totally lost here.

Thanks in advance!

You need to modify shaders to achieve that. Unlit does not interact with any lighting so it can’t also show any shadows.(absent of light). You probably can just mix and match default shading and unlit shading mode code.

Thanks Kalle-H

I´m a bit new to UE4, I used to work with other engines and in other languages, can you point me in the right direction on how to do this? (Where is the code I have to study and any advices in this regard)


Thanks Kalle-H

It´s a mess for me because I never completely understood shader language, but I´ll try!

Thanks for your help!!!

If anyone knows what line do I have to add to multiply the shadows with the emmissive and how to create a new shader with it, bring me a line!

Although I´ll do my best :slight_smile:

Cheer and thanks!!!

Ok, after dealing with this all day I can´t figure what do I have to modify, to multiply shadows by the emissive channel, in a normal shader, that is all I want to be able to do, I don´t need the material to be unlit, I can fake it, but I need to multiply shadows by the emissive and I don´t know how to modify that and save it as a new material type… any help is very welcome!


Go to that shader. Modify default lit shader to multiply emissive with shadows. Then output zero to basecolor and specular. End results should be unlit with shadows.

Thanks Kalle-H

That was what I was thinking, call me null but I can´t understand the file structure, is like there are A LOT of shaders there, I can do the basecolor and specular from the material editor from within UE, but I can´t find the variables I need to multiply the emissive with the shadows, but I´ll try again right now, I have to finally understand how this works because in many situations some small modification to the shaders are needed and I want to know how to do them.

Thanks for your help! again!


Ok, I tried the following but I can’t get to it:

half3 Emissive = GetMaterialEmissive(PixelMaterialInputs);
		float2 NDC = MaterialParameters.ScreenPosition.xy / MaterialParameters.ScreenPosition.w;
		float2 ScreenUV = NDC * ResolvedView.ScreenPositionScaleBias.xy + ResolvedView.ScreenPositionScaleBias.wz;
		float4 BoneDynamicShadowFactors = GetPerPixelLightAttenuation(ScreenUV);	
		Emissive *= BoneDynamicShadowFactors;

Basically I took the code that I understood as DynamicShadow code and duplicated it inside a different IF just after the Emissive declaration, and after that I multiply the Emissive for my DynamicShadowFactors, but when I compile this UE crash, if I reopen the project without deleting “Intermediate” and “Saved” folders and without commenting my lines, UE keeps crashing (I’m on UE 4.14 BTW)

Am I multiplying Emissive by the right variable?

Is there another “Shadow” variable that I should be using instead of that one?

It’s important to know that I only need Dynamic shadows, if Baked shadows are a subproduct it’s ok, but the important shadows are the Dynamic ones.

Thanks for all the help!

Ok, have some advances here!! :slight_smile: Finally!!

I removed that IF statement and renamed all that variables and now I’m getting kind of a shadow in the Emissive channel, GREAT!!!

But my shadow is Blue, not black, any idea about what is happening here?


Great!! Now I have a black shadow in my Emissive!

I have to change:

Emissive *= BoneDynamicShadowFactors;


Emissive *= BoneDynamicShadowFactors.x;

And that’s it.

Now I’m trying to add a factor in the material, a slot where I feed a float value to be able to soften the shadow strength, but I don’t know how to do this, where do I have to look to enter a new parameter in the material?


Ok, I can’t find a way, I would like to enable a Custom Data channel in the Default Lit shading model, rename it to Emissive Shadow Multiplier and use a float to multiply the strengh of the shadow, ,but I can’t find where can I do that.
If I simply multiply the shadow with the custom data:


Everything turns black, no matter what do I put in the custom data 0 or 1 channels, I assume because the shader is ignoring the custom data input and passing 0, so how can I avoid that and use that channel?


Ok, I finally managed to have my shader, the inly thing I have been unable to do is to activate and rename a Custom Data channel in the Default Lit shading model to modulate the shadow darkness, but anyways, it works and you can modify the multiplier in the code.
To have shadows over the emmisive it is actually very simple (just Dynamic Shadows), in the file BasePassPixelShader.usf, wich you can find in:

X:\\yourinstallationfolder\Epic Games\4.14\Engine\Shaders

Being X your installation drive and “yourinstallationfolder” your installation folder as you guessed, well, lets continue…

… in that file you just have to put this code after the line #952:

// Bone-Studio Photogrammetry Mod - Multiply Emissive by Shadows, reduce the shadow darkness adding a float value to it.
	float2 BoneNDC = MaterialParameters.ScreenPosition.xy / MaterialParameters.ScreenPosition.w;
	float2 BoneScreenUV = BoneNDC * ResolvedView.ScreenPositionScaleBias.xy + ResolvedView.ScreenPositionScaleBias.wz;
	float4 BoneDynamicShadowFactors = GetPerPixelLightAttenuation(BoneScreenUV);
	float BoneShadow = BoneDynamicShadowFactors.x + 0.18f;
	Emissive *= BoneShadow;

Of course change the comments and the variable names, I always name my variables that way so I can locate my modifications.

And that’s it, now you can configure a material with Standard Lit as a shading model, put a float with value 0 in “Base Color”, “Metallic”, “Specular” and “Roughness” and put a bitmap in “Emissive Color” and you will get shadows over your photogrammetry… cool!!!

Finally if you want to adjust the darkness of the shadows just modify this line:

float BoneShadow = BoneDynamicShadowFactors.x + 0.18f;

Change the 0.18f value for whatever you want, completely dark, don’t add anything, a bit more of light, add a bit more of value hehe

Thanks to everyone, specially to Kalle-H.

BTW guys if you know how can I enable and use the “Custom Data 0” channel for that value it could be very welcom!


P.S.: Epic could you add an official Photogrammetry shading model or something similar?

Bumping this because i am more or less in the same situation and i believe this will become a requested feature from several users, let’s see if there’s more interest in it.
By the way @Jungaea did you make any more progress on the shader you are working on? Seems a good step in the right direction! It would be great to have occlusion shadows as well (not self occlusion of course)… Would you be able to share your progress (if there’s any over the great info you already provided)? Not that i think i can help, being completely ignorant about shader programming, but have a colleague that might and well, we could surely make a use of it for the moment as we experiment on some photogrammetry locations we scanned. For now i’ll just try and follow your tips to get dynamic shadows in place. Thanks for sharing!

Hi irSindaco.

We haven´t modified the shadedr much more, I was not able to know how to use and enable the “Custom Data 0” channel to have a custom value for the shadow strength, but in any case the value I picked is working well :slight_smile:
In any case, to have that shader just do what I say in the previous post and you will have it working in no time, I´m no Unreal Engine expert at all, and I barely understand UE Shader language, but if you need any kind of help just tell me.


Ok thanks a lot, i’ll try right after Christmas (btw…merry xmas!), seems easy enough and mostly a matter of copy-paste…i’ll be back for help in case it’s needed. Again, thanks for you work!

Tried and works great, also really an easy copy-paste as i thought. A couple of questions:

  1. Is this modification in BasePassPixelShader.usf maybe affecting standard shaders/materials with “side-effects” i might need to take into account (not that i noticed anything going nuts atm)?
  2. Would this shader setup be exported once i finally build my project for distribution, or maybe is it just working in the editor so i should build a specific shader (i.e. [UE4] Adding a custom shading model (Part I) | FelixK development blog)?

There is no side effect that I’ve noticed apart from the emmisive receiving shadows, that is why I wanted to create a parameter to use as multiplier instead of using a hardcoded multiplier of 0.18 , but i don’t know how to do this.

Also I don’t know how to create a parallel shader that can be released as an add-on, if someone can guide me I’ll be happy to do it and release it free :slight_smile:

The shader is working perfectly in my builds BTW and the link you posted is not working :slight_smile:

Cheers and heppy new year!

…didn’t notice the side effect, it might be annoying in specific contexts. Your offer to work on this is great, hopefully someone with more specific knowledge will dive in and give a helping hand.
Sorry for the broken link! Here you go:

Thanks irSindaco.

I wrote him a comment in that post because I don´t know if the re-compilation of the full engine is needed, if that is the case I don´t think it´s worth it, I prefer to be able to upgrade my engine without having to recompile it, if it´s just a modification that can be done without making a full recompile then I´ll look into it to create a custom “Selflit Shadowed” or somethign similar.