Cheapest (performance wise) fog for GLES2 mobile VR (LDR) - how?

Cheap and correct way to calculate fog is to use exp() function. It’s cheaper than pow and it’s give correct sense of depth and you don’t have to clamp it. So correct function would be: fogness = 1.0 - exp(-distance * density). To optimize this you could use depth instead of distance. Also you can use exp2 instead of exp because you can bake difference to density.

More ideas: Inigo Quilez :: computer graphics, mathematics, shaders, fractals, demoscene and more

Not quite sure what it should look like in the nodes of material function :confused:

OK, so, Kalle_H is trying to tell you how to basically make an exponential height fog in code. But that’s too many instructions for a mobile platform. You’d have to add a function to calculate the Z depth in the world, and another function to figure out the color of the interscattering, and all this needs to be done in code in the mobile shader main pass, so it will add complexity to everything you make in that project, but it will allow a more natural looking fog than the function I gave you. The function I gave you was the cheapest way to add fog, and yes, it does wash out the lighting and colors. That is what fog does, and this is the cheapest way to do it.

Don’t use power! Replace the power with a multiply node and just multiply the depth function by itself. You get the depth raised to the power of two, pushing the fog away from the camera and looking more naturalistic, and it only costs one instruction, not 5. Your level is just too dark to see anything to begin with. Brighten up your scene a little bit more and use the fog to wash out the lighting a little bit in the back. Light your level as if the fog doesn’t exist, and use the fog at the very end to add atmosphere. The picture you posted with the framerate at 64.33 FPS looks fine. If you’re doing things on mobile, then you can’t waste so much on fog. If using a power node cuts down your framerate from 64 to 56, then you really can’t afford a more natural fog without sacrificing performance. I’m not sure what hardware you’re targeting, but my method of fogging looks exactly like the fogging methods I’ve seen on mobile games.

Also, I noticed you’re using sphere reflection captures. I’m not too familiar with UE4’s mobile pass, but I’m pretty sure reflections are out of the question on mobile hardware unless you’re targeting very high-end devices and lower framerates.

fca7a613909011fdc415447a566ef22fdfde6dbe.jpeg

Your screenshots look like level has unlit material. Also, my level is not dark to the point you can’t see anything. It’s lit the way it should be lit. Also, that’s how I approached the lighting / fog situation - I lit the level first, made sure it looks as I need for it to look, and then added fog.

I am targeting Samsung Galaxy S6 and up, for Gear VR.

The fog I am after is not realistic. It’s just not quite linear. Maybe it just needs to start not at the camera but a bit away from it.

The Galaxy S6 has a 2440x1440 screen. On mobile hardware. Let me just tell you right now that shader costs will definitely hinder your performance at that resolution. I’ve experienced demos of the Gear VR, and it looks very nice, but it only looks nice because it’s just a demo. To optimize that technology well enough for a game with tons of models and entire worlds would be exhausting, especially at a resolution so high you can barely do anything with it.

I managed to optimize a version of the fog function that excludes the texture input, uses the multiply node for exponential fog, and has a start distance. This all goes into emissive, lighting up the fog as you look into the distance. Then it also performs the inverse result to darken the base texture down to 0 in the distance, preventing the image from washing out.


Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_208"
   Begin Object Class=MaterialExpressionFunctionOutput Name="MaterialExpressionFunctionOutput_3"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3791"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3792"
   End Object
   Begin Object Name="MaterialExpressionFunctionOutput_3"
      OutputName="Emissive"
      Description="Goes to Emissive"
      A=(Expression=MaterialExpressionMultiply'MaterialGraphNode_218.MaterialExpressionMultiply_8')
      bLastPreviewed=True
      Id=00C5475E456F38FBDAA53098CA37F030
      MaterialExpressionEditorX=400
      MaterialExpressionEditorY=288
      MaterialExpressionGuid=04CD4FA74FDCE3B3DDFE75842D254C12
      Material=Material'/Engine/Transient.Material_23'
      Desc="Goes to emissive"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3791"
      PinName="Input"
      PinFriendlyName=" "
      PinType=(PinCategory="required")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_218.EdGraphPin_3817'
   End Object
   Begin Object Name="EdGraphPin_3792"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
   End Object
   MaterialExpression=MaterialExpressionFunctionOutput'MaterialExpressionFunctionOutput_3'
   Pins(0)=EdGraphPin'EdGraphPin_3791'
   Pins(1)=EdGraphPin'EdGraphPin_3792'
   NodePosX=400
   NodePosY=288
   NodeComment="Goes to emissive"
   bCommentBubbleVisible=True
   NodeGuid=7827AD284898E7468E2843AA5A03C7F4
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_209"
   Begin Object Class=MaterialExpressionPixelDepth Name="MaterialExpressionPixelDepth_2"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3793"
   End Object
   Begin Object Name="MaterialExpressionPixelDepth_2"
      MaterialExpressionEditorX=-736
      MaterialExpressionEditorY=224
      MaterialExpressionGuid=DCE0DC42412C63E585A3D6B39DBE3141
      Material=Material'/Engine/Transient.Material_23'
      Desc="Depth into the world"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3793"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      PinType=(PinCategory="mask",PinSubCategory="red")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_210.EdGraphPin_3794'
   End Object
   MaterialExpression=MaterialExpressionPixelDepth'MaterialExpressionPixelDepth_2'
   Pins(0)=EdGraphPin'EdGraphPin_3793'
   NodePosX=-736
   NodePosY=224
   NodeComment="Depth into the world"
   bCommentBubbleVisible=True
   NodeGuid=ECBD972C401C85BD2D3A2993DD49F058
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_210"
   Begin Object Class=MaterialExpressionDivide Name="MaterialExpressionDivide_8"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3794"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3795"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3796"
   End Object
   Begin Object Name="MaterialExpressionDivide_8"
      A=(Expression=MaterialExpressionPixelDepth'MaterialGraphNode_209.MaterialExpressionPixelDepth_2',Mask=1,MaskR=1)
      B=(Expression=MaterialExpressionFunctionInput'MaterialGraphNode_213.MaterialExpressionFunctionInput_18')
      MaterialExpressionEditorX=-560
      MaterialExpressionEditorY=272
      MaterialExpressionGuid=800653994F5099D1C4B2419D9FA77D69
      Material=Material'/Engine/Transient.Material_23'
      Desc="Strength of Fog linear"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3794"
      PinName="A"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_209.EdGraphPin_3793'
   End Object
   Begin Object Name="EdGraphPin_3795"
      PinName="B"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_213.EdGraphPin_3804'
   End Object
   Begin Object Name="EdGraphPin_3796"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_215.EdGraphPin_3807'
      LinkedTo(1)=EdGraphPin'MaterialGraphNode_215.EdGraphPin_3808'
   End Object
   MaterialExpression=MaterialExpressionDivide'MaterialExpressionDivide_8'
   Pins(0)=EdGraphPin'EdGraphPin_3794'
   Pins(1)=EdGraphPin'EdGraphPin_3795'
   Pins(2)=EdGraphPin'EdGraphPin_3796'
   NodePosX=-560
   NodePosY=272
   NodeComment="Strength of Fog linear"
   bCommentBubbleVisible=True
   NodeGuid=76B59E8D493E8AFD9AF787BD3DAD2B66
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_211"
   Begin Object Class=MaterialExpressionClamp Name="MaterialExpressionClamp_2"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3797"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3798"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3799"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3800"
   End Object
   Begin Object Name="MaterialExpressionClamp_2"
      Input=(Expression=MaterialExpressionSubtract'MaterialGraphNode_216.MaterialExpressionSubtract_3')
      Max=(Expression=MaterialExpressionFunctionInput'MaterialGraphNode_214.MaterialExpressionFunctionInput_19')
      MaterialExpressionEditorX=-144
      MaterialExpressionEditorY=448
      MaterialExpressionGuid=176022B84C69447A88EBD7B5FB20E111
      Material=Material'/Engine/Transient.Material_23'
      Desc="clamps fog\'s influence 0-max"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3797"
      PinName="Input"
      PinFriendlyName=" "
      PinType=(PinCategory="required")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_216.EdGraphPin_3812'
   End Object
   Begin Object Name="EdGraphPin_3798"
      PinName="Min"
      PinType=(PinCategory="optional")
   End Object
   Begin Object Name="EdGraphPin_3799"
      PinName="Max"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_214.EdGraphPin_3806'
   End Object
   Begin Object Name="EdGraphPin_3800"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_218.EdGraphPin_3816'
      LinkedTo(1)=EdGraphPin'MaterialGraphNode_221.EdGraphPin_3823'
   End Object
   MaterialExpression=MaterialExpressionClamp'MaterialExpressionClamp_2'
   Pins(0)=EdGraphPin'EdGraphPin_3797'
   Pins(1)=EdGraphPin'EdGraphPin_3798'
   Pins(2)=EdGraphPin'EdGraphPin_3799'
   Pins(3)=EdGraphPin'EdGraphPin_3800'
   NodePosX=-144
   NodePosY=448
   NodeComment="clamps fog\'s influence 0-max"
   bCommentBubbleVisible=True
   NodeGuid=B5684F09403929802997939AB7869260
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_212"
   Begin Object Class=MaterialExpressionFunctionInput Name="MaterialExpressionFunctionInput_17"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3801"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3802"
   End Object
   Begin Object Name="MaterialExpressionFunctionInput_17"
      InputName="Fog Color"
      Description="Your fog color goes here"
      Id=AE96FAA845AC0719BC2EAFB189686B9D
      PreviewValue=(X=1.000000,Y=0.610000,Z=0.250000,W=1.000000)
      bUsePreviewValueAsDefault=True
      MaterialExpressionEditorX=-160
      MaterialExpressionEditorY=192
      MaterialExpressionGuid=6545C43A47B1DEEBEC4E479439505277
      Material=Material'/Engine/Transient.Material_23'
   End Object
   Begin Object Name="EdGraphPin_3801"
      PinName="Preview"
      PinType=(PinCategory="optional")
   End Object
   Begin Object Name="EdGraphPin_3802"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_218.EdGraphPin_3815'
   End Object
   MaterialExpression=MaterialExpressionFunctionInput'MaterialExpressionFunctionInput_17'
   Pins(0)=EdGraphPin'EdGraphPin_3801'
   Pins(1)=EdGraphPin'EdGraphPin_3802'
   NodePosX=-160
   NodePosY=192
   NodeGuid=FD473D9C441A33E8F085A5B21663CB00
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_213"
   Begin Object Class=MaterialExpressionFunctionInput Name="MaterialExpressionFunctionInput_18"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3803"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3804"
   End Object
   Begin Object Name="MaterialExpressionFunctionInput_18"
      InputName="Depth"
      Description="Distance to max opacity"
      Id=9D209ADA4D478B5098C987A22BD72498
      InputType=FunctionInput_Scalar
      PreviewValue=(X=2000.000000,Y=0.000000,Z=0.000000,W=0.000000)
      bUsePreviewValueAsDefault=True
      SortPriority=1
      MaterialExpressionEditorX=-752
      MaterialExpressionEditorY=384
      MaterialExpressionGuid=6545C43A47B1DEEBEC4E479439505277
      Material=Material'/Engine/Transient.Material_23'
      Desc="Distance to max opacity"
      bCommentBubbleVisible=True
      bCollapsed=True
   End Object
   Begin Object Name="EdGraphPin_3803"
      PinName="Preview"
      PinType=(PinCategory="optional")
   End Object
   Begin Object Name="EdGraphPin_3804"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_210.EdGraphPin_3795'
      LinkedTo(1)=EdGraphPin'MaterialGraphNode_219.EdGraphPin_3819'
   End Object
   MaterialExpression=MaterialExpressionFunctionInput'MaterialExpressionFunctionInput_18'
   Pins(0)=EdGraphPin'EdGraphPin_3803'
   Pins(1)=EdGraphPin'EdGraphPin_3804'
   NodePosX=-752
   NodePosY=384
   NodeComment="Distance to max opacity"
   bCommentBubbleVisible=True
   NodeGuid=20D41366478F0BB63AA787A92FF10241
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_214"
   Begin Object Class=MaterialExpressionFunctionInput Name="MaterialExpressionFunctionInput_19"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3805"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3806"
   End Object
   Begin Object Name="MaterialExpressionFunctionInput_19"
      InputName="Max Opacity"
      Description="Max opacity of the fog"
      Id=FC9837C94FC1CA02BA4560A7D5738BF8
      InputType=FunctionInput_Scalar
      PreviewValue=(X=0.800000,Y=0.000000,Z=0.000000,W=0.000000)
      bUsePreviewValueAsDefault=True
      SortPriority=3
      MaterialExpressionEditorX=-400
      MaterialExpressionEditorY=544
      MaterialExpressionGuid=6545C43A47B1DEEBEC4E479439505277
      Material=Material'/Engine/Transient.Material_23'
      bCollapsed=True
   End Object
   Begin Object Name="EdGraphPin_3805"
      PinName="Preview"
      PinType=(PinCategory="optional")
   End Object
   Begin Object Name="EdGraphPin_3806"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_211.EdGraphPin_3799'
   End Object
   MaterialExpression=MaterialExpressionFunctionInput'MaterialExpressionFunctionInput_19'
   Pins(0)=EdGraphPin'EdGraphPin_3805'
   Pins(1)=EdGraphPin'EdGraphPin_3806'
   NodePosX=-400
   NodePosY=544
   NodeGuid=597B8294453E422F66B669B3EE09CFA1
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_215"
   Begin Object Class=MaterialExpressionMultiply Name="MaterialExpressionMultiply_7"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3807"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3808"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3809"
   End Object
   Begin Object Name="MaterialExpressionMultiply_7"
      A=(Expression=MaterialExpressionDivide'MaterialGraphNode_210.MaterialExpressionDivide_8')
      B=(Expression=MaterialExpressionDivide'MaterialGraphNode_210.MaterialExpressionDivide_8')
      MaterialExpressionEditorX=-432
      MaterialExpressionEditorY=320
      MaterialExpressionGuid=766369B0432F6995A024A7B1ECD9A5BB
      Material=Material'/Engine/Transient.Material_23'
      Desc="Exponent"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3807"
      PinName="A"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_210.EdGraphPin_3796'
   End Object
   Begin Object Name="EdGraphPin_3808"
      PinName="B"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_210.EdGraphPin_3796'
   End Object
   Begin Object Name="EdGraphPin_3809"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_216.EdGraphPin_3810'
   End Object
   MaterialExpression=MaterialExpressionMultiply'MaterialExpressionMultiply_7'
   Pins(0)=EdGraphPin'EdGraphPin_3807'
   Pins(1)=EdGraphPin'EdGraphPin_3808'
   Pins(2)=EdGraphPin'EdGraphPin_3809'
   NodePosX=-432
   NodePosY=320
   NodeComment="Exponent"
   bCommentBubbleVisible=True
   NodeGuid=5E96717B459DA75F4632E1B216815A0B
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_216"
   Begin Object Class=MaterialExpressionSubtract Name="MaterialExpressionSubtract_3"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3810"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3811"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3812"
   End Object
   Begin Object Name="MaterialExpressionSubtract_3"
      A=(Expression=MaterialExpressionMultiply'MaterialGraphNode_215.MaterialExpressionMultiply_7')
      B=(Expression=MaterialExpressionDivide'MaterialGraphNode_219.MaterialExpressionDivide_9')
      MaterialExpressionEditorX=-256
      MaterialExpressionEditorY=368
      MaterialExpressionGuid=B5267A81486A7A61FD783D9C5D30E4FD
      Material=Material'/Engine/Transient.Material_23'
   End Object
   Begin Object Name="EdGraphPin_3810"
      PinName="A"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_215.EdGraphPin_3809'
   End Object
   Begin Object Name="EdGraphPin_3811"
      PinName="B"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_219.EdGraphPin_3820'
   End Object
   Begin Object Name="EdGraphPin_3812"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_211.EdGraphPin_3797'
   End Object
   MaterialExpression=MaterialExpressionSubtract'MaterialExpressionSubtract_3'
   Pins(0)=EdGraphPin'EdGraphPin_3810'
   Pins(1)=EdGraphPin'EdGraphPin_3811'
   Pins(2)=EdGraphPin'EdGraphPin_3812'
   NodePosX=-256
   NodePosY=368
   NodeGuid=A70BD2234A1254A46C7FEF95AD6D98CF
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_217"
   Begin Object Class=MaterialExpressionFunctionInput Name="MaterialExpressionFunctionInput_20"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3813"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3814"
   End Object
   Begin Object Name="MaterialExpressionFunctionInput_20"
      InputName="Start Distance"
      Description="Distance to fog start"
      Id=B35F082040966921533EA6BF0AFC87F6
      InputType=FunctionInput_Scalar
      PreviewValue=(X=500.000000,Y=0.000000,Z=0.000000,W=0.000000)
      bUsePreviewValueAsDefault=True
      SortPriority=2
      MaterialExpressionEditorX=-768
      MaterialExpressionEditorY=560
      MaterialExpressionGuid=6545C43A47B1DEEBEC4E479439505277
      Material=Material'/Engine/Transient.Material_23'
      Desc="Start distance"
      bCommentBubbleVisible=True
      bCollapsed=True
   End Object
   Begin Object Name="EdGraphPin_3813"
      PinName="Preview"
      PinType=(PinCategory="optional")
   End Object
   Begin Object Name="EdGraphPin_3814"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_219.EdGraphPin_3818'
   End Object
   MaterialExpression=MaterialExpressionFunctionInput'MaterialExpressionFunctionInput_20'
   Pins(0)=EdGraphPin'EdGraphPin_3813'
   Pins(1)=EdGraphPin'EdGraphPin_3814'
   NodePosX=-768
   NodePosY=560
   NodeComment="Start distance"
   bCommentBubbleVisible=True
   NodeGuid=2576114F4B8013B6172A44B7D40E5B38
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_218"
   Begin Object Class=MaterialExpressionMultiply Name="MaterialExpressionMultiply_8"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3815"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3816"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3817"
   End Object
   Begin Object Name="MaterialExpressionMultiply_8"
      A=(Expression=MaterialExpressionFunctionInput'MaterialGraphNode_212.MaterialExpressionFunctionInput_17')
      B=(Expression=MaterialExpressionClamp'MaterialGraphNode_211.MaterialExpressionClamp_2')
      MaterialExpressionEditorX=80
      MaterialExpressionEditorY=320
      MaterialExpressionGuid=42AD4F5E4C95F296E35AE4880F3EA781
      Material=Material'/Engine/Transient.Material_23'
   End Object
   Begin Object Name="EdGraphPin_3815"
      PinName="A"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_212.EdGraphPin_3802'
   End Object
   Begin Object Name="EdGraphPin_3816"
      PinName="B"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_211.EdGraphPin_3800'
   End Object
   Begin Object Name="EdGraphPin_3817"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_208.EdGraphPin_3791'
   End Object
   MaterialExpression=MaterialExpressionMultiply'MaterialExpressionMultiply_8'
   Pins(0)=EdGraphPin'EdGraphPin_3815'
   Pins(1)=EdGraphPin'EdGraphPin_3816'
   Pins(2)=EdGraphPin'EdGraphPin_3817'
   NodePosX=80
   NodePosY=320
   NodeGuid=C639A55943885C51C32F7C89791BEFEB
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_219"
   Begin Object Class=MaterialExpressionDivide Name="MaterialExpressionDivide_9"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3818"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3819"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3820"
   End Object
   Begin Object Name="MaterialExpressionDivide_9"
      A=(Expression=MaterialExpressionFunctionInput'MaterialGraphNode_217.MaterialExpressionFunctionInput_20')
      B=(Expression=MaterialExpressionFunctionInput'MaterialGraphNode_213.MaterialExpressionFunctionInput_18')
      MaterialExpressionEditorX=-496
      MaterialExpressionEditorY=480
      MaterialExpressionGuid=800653994F5099D1C4B2419D9FA77D69
      Material=Material'/Engine/Transient.Material_23'
      Desc="Get start distance after exponent"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3818"
      PinName="A"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_217.EdGraphPin_3814'
   End Object
   Begin Object Name="EdGraphPin_3819"
      PinName="B"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_213.EdGraphPin_3804'
   End Object
   Begin Object Name="EdGraphPin_3820"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_216.EdGraphPin_3811'
   End Object
   MaterialExpression=MaterialExpressionDivide'MaterialExpressionDivide_9'
   Pins(0)=EdGraphPin'EdGraphPin_3818'
   Pins(1)=EdGraphPin'EdGraphPin_3819'
   Pins(2)=EdGraphPin'EdGraphPin_3820'
   NodePosX=-496
   NodePosY=480
   NodeComment="Get start distance after exponent"
   bCommentBubbleVisible=True
   NodeGuid=EAD80AFD44CE9C791CA02F98543103E8
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_220"
   Begin Object Class=MaterialExpressionFunctionOutput Name="MaterialExpressionFunctionOutput_4"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3821"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3822"
   End Object
   Begin Object Name="MaterialExpressionFunctionOutput_4"
      OutputName="Base Color"
      Description="Goes to Base Color"
      A=(Expression=MaterialExpressionMultiply'MaterialGraphNode_222.MaterialExpressionMultiply_9')
      bLastPreviewed=True
      Id=1B8DC01242156EE5EF646282E934FCF4
      MaterialExpressionEditorX=400
      MaterialExpressionEditorY=16
      MaterialExpressionGuid=04CD4FA74FDCE3B3DDFE75842D254C12
      Material=Material'/Engine/Transient.Material_23'
      Desc="Goes to Base Color"
      bCommentBubbleVisible=True
   End Object
   Begin Object Name="EdGraphPin_3821"
      PinName="Input"
      PinFriendlyName=" "
      PinType=(PinCategory="required")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_222.EdGraphPin_3827'
   End Object
   Begin Object Name="EdGraphPin_3822"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
   End Object
   MaterialExpression=MaterialExpressionFunctionOutput'MaterialExpressionFunctionOutput_4'
   Pins(0)=EdGraphPin'EdGraphPin_3821'
   Pins(1)=EdGraphPin'EdGraphPin_3822'
   NodePosX=400
   NodePosY=16
   NodeComment="Goes to Base Color"
   bCommentBubbleVisible=True
   NodeGuid=77D922524ED1BAD6C6DCF3B403510195
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_221"
   Begin Object Class=MaterialExpressionOneMinus Name="MaterialExpressionOneMinus_1"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3823"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3824"
   End Object
   Begin Object Name="MaterialExpressionOneMinus_1"
      Input=(Expression=MaterialExpressionClamp'MaterialGraphNode_211.MaterialExpressionClamp_2')
      MaterialExpressionEditorX=144
      MaterialExpressionEditorY=96
      MaterialExpressionGuid=D822B8C344009AA78817658A8AB34DB2
      Material=Material'/Engine/Transient.Material_23'
   End Object
   Begin Object Name="EdGraphPin_3823"
      PinName="Input"
      PinFriendlyName=" "
      PinType=(PinCategory="required")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_211.EdGraphPin_3800'
   End Object
   Begin Object Name="EdGraphPin_3824"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_222.EdGraphPin_3826'
   End Object
   MaterialExpression=MaterialExpressionOneMinus'MaterialExpressionOneMinus_1'
   Pins(0)=EdGraphPin'EdGraphPin_3823'
   Pins(1)=EdGraphPin'EdGraphPin_3824'
   NodePosX=144
   NodePosY=96
   NodeGuid=7225D0414F42AEBC6FEC39B716FF3B43
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_222"
   Begin Object Class=MaterialExpressionMultiply Name="MaterialExpressionMultiply_9"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3825"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3826"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3827"
   End Object
   Begin Object Name="MaterialExpressionMultiply_9"
      A=(Expression=MaterialExpressionFunctionInput'MaterialGraphNode_223.MaterialExpressionFunctionInput_21')
      B=(Expression=MaterialExpressionOneMinus'MaterialGraphNode_221.MaterialExpressionOneMinus_1')
      MaterialExpressionEditorX=256
      MaterialExpressionEditorY=16
      MaterialExpressionGuid=B40A7DE24598EA75EC51FA85265C6EEF
      Material=Material'/Engine/Transient.Material_23'
   End Object
   Begin Object Name="EdGraphPin_3825"
      PinName="A"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_223.EdGraphPin_3829'
   End Object
   Begin Object Name="EdGraphPin_3826"
      PinName="B"
      PinType=(PinCategory="optional")
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_221.EdGraphPin_3824'
   End Object
   Begin Object Name="EdGraphPin_3827"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_220.EdGraphPin_3821'
   End Object
   MaterialExpression=MaterialExpressionMultiply'MaterialExpressionMultiply_9'
   Pins(0)=EdGraphPin'EdGraphPin_3825'
   Pins(1)=EdGraphPin'EdGraphPin_3826'
   Pins(2)=EdGraphPin'EdGraphPin_3827'
   NodePosX=256
   NodePosY=16
   NodeGuid=153ED59D4232BAD07474CFACF8D0B5F3
End Object
Begin Object Class=MaterialGraphNode Name="MaterialGraphNode_223"
   Begin Object Class=MaterialExpressionFunctionInput Name="MaterialExpressionFunctionInput_21"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3828"
   End Object
   Begin Object Class=EdGraphPin Name="EdGraphPin_3829"
   End Object
   Begin Object Name="MaterialExpressionFunctionInput_21"
      InputName="Base Color Input"
      Description="Your Base Color textures/material goes here"
      Id=60E0442F41358AA43C4140B5FC5587BA
      PreviewValue=(X=0.000000,Y=1.000000,Z=0.000000,W=0.000000)
      bUsePreviewValueAsDefault=True
      MaterialExpressionEditorX=-160
      MaterialExpressionEditorY=-64
      MaterialExpressionGuid=6545C43A47B1DEEBEC4E479439505277
      Material=Material'/Engine/Transient.Material_23'
   End Object
   Begin Object Name="EdGraphPin_3828"
      PinName="Preview"
      PinType=(PinCategory="optional")
   End Object
   Begin Object Name="EdGraphPin_3829"
      PinName="Output"
      PinFriendlyName=" "
      Direction=EGPD_Output
      LinkedTo(0)=EdGraphPin'MaterialGraphNode_222.EdGraphPin_3825'
   End Object
   MaterialExpression=MaterialExpressionFunctionInput'MaterialExpressionFunctionInput_21'
   Pins(0)=EdGraphPin'EdGraphPin_3828'
   Pins(1)=EdGraphPin'EdGraphPin_3829'
   NodePosX=-160
   NodePosY=-64
   NodeGuid=014F8BC0486A4FD2E8F799B86EADE169
End Object


Thanks, I’ll try that sometime today.

I’ve read somewhere recently that SoC in S6 is comparable to GeForce 970. While resolution indeed high, I figured I’d have to render in smaller scale (renderscale .75; although I am not sure if it works in UE4 - that slider in the menu of the Editor doesn’t seem to do anything).

I’ve been providing my scene to Epic and hopefully they can use it as test case to improve performance of UE4 in Gear VR.

Tested! Works fast and well (haven’t tested on brighter scene, but for mine it works). Although when I tried making fog start closer to the camera, it failed:

Any idea why?

EDIT: Tested on the device - no loss of fps / rendertime :slight_smile:

A GTX 970 requires 145 watts, and it was just released not even a couple years ago. You mean to tell me that they found some way to put that kind of power in a cellphone now? Wow! What a world we live in.

Bring down the max opacity down to 0.7, or something. Right now it looks very strong. Also, the start distance is in Unreal units, so 1 unit is the equivalent of 1 centimeter. At that point, might as well set it to 0 and save the instructions. If you want to change the exponent with a power node to pull the fog closer to the camera, you can do that. In my testing, the power node gets converted to an exponent to save instructions, so the cost depends on the value. Just know that integers are cheaper, 2 is the cheapest, and raising to a decimal or floating point value is definitely going to be more expensive. I’d recommend against having perpetual fog everywhere, but if you really want to do that, you can plug in a value to the minimum on the clamp, giving even areas up in your face some amount of fog. Again, this is not a good idea. The purpose of the start distance was to push the fog away. If you want to have a lot of fog everywhere, I’d suggest lowering the depth (so the fog ramps up quickly) and lowering the max opacity (so you can still see what’s going on). The power node can also come in handy to push or pull the fog by depth. Just replace the multiply “exponent” node with a power and an input.

Like I said, I saw someone saying that. Googling revealed it’s not true :slight_smile: However, S6 has powerful SoC and Quake-like visuals should run at 60 fps even when performing stereo rendering.

That’s the point I was making. It should begin right in front of the camera, but as you see on the screenshot, it stars too far off :confused: It’s not bad, but if it needs to start closer, I am not sure how to make that happen :confused:

Well, power node really brings down fps. With your current setup performance is the same as if I didn’t have fog, which is super awesome. If I bring depth value to let’s say 100 (from 2000), the fog will get super dense, but it won’t start any closer to the cam than it already does.

If I plug integer into clamp node’s min (which is already 0), how would that change starting distance? Do I go with negative values?

So, instead of multiplying linear strength of the fog to itself, I multiplied it by a int constant. Now I can actually changer near and far distance with visible changes.

Yeah, a GTX 970 is a pretty amazing graphics card. Getting that kind of power on mobile might not happen in my lifetime. I wouldn’t go so far as to say mobile can’t handle something better than Quake, but expecting Kite-Demo-esque graphics on it is insane. This fog is figured out by the depth, and the start distance serves as your offset. If you want to start the fog sooner, set the start distance to a negative value. Yeah, it will screw up a bit with your exponent, but like you said, it performs very well. This is definitely the best performance you can get with fog out of UE4.

I would not suggest removing the exponent and multiplying the fog by a constant. All that feeds into a clamp node anyways: all you’re doing is changing the depth distance, which you can easily change by just changing the depth itself. And I’m pretty sure decimals multiply with the same performance as integers, multiplication is basic arithmetic. It’s just exponents that suffer from some complications. The purpose of the exponent is to accumulate the fog faster as it builds in the distance, giving you clearer viewing up close while emphasizing the depth in the background.

Do you know how to set up a material parameter collection? I seriously suggest doing that, plugging the MPC values into the fog function. Then in your world, fiddle with the values in the MPC until you get the fog looking just right. If change constants and rebuild entire shaders just to see how it looks, you’re going to be spending all day trying to make the material look decent instead of setting up parameters and spending just a few seconds, minutes at the most, to get the values just right. You can manage multiple materials at once that way.

I tried negative values for start distance and that didn’t work. The result was the same as using zero value there.

No, I don’t know about MPC. I am not a technical artist unfortunately :confused: And shader recompiling every time I change values is annoying indeed, but once I figure the look, I wouldn’t really need to mess with them.

I think for Galaxy S6 gen I would settle on Quake-like complexity of assets and scenes. If Samsung will release Vulkan for S6, then perhaps Doom 3 complexity (minus real-time unified lighting/shadows concept) of assets is what we could have in mobile VR. I bring those 2 games as an example because that’s the scene I come from :slight_smile:

Use values in the thousands. The depth inputs operate in Unreal units, so 1 unit = 1 centimeter. Try negative 300 and see if that gets you the results you want.

You definitely need to learn about material parameter collections, it’s easy: first, right click in the content browser, and make the material parameter collection. Then, add a vector parameter for the fog color and 3 scalar parameters for the depth, start distance, and max opacity. Close that, then open up the material function, and from the content browser, drag the MPC into the material function graph. Each time you drag in the MPC it will come up blank, you need to go in the details panel and set which parameter corresponds with which node. Plug all the nodes in their appropriate place. Repeat until you have all the material function inputs hooked up to the MPC. Then, go in your materials and remove all the inputs you have plugged into the function. Once you do that, compile and save the project. Now if you want to change any of the values you can do it in the MPC and it will scale all the values uniformly across every material. Go ahead and mess with it until you get the exact results you want. Trust me, this is much easier than compiling any time you need to change something.

Wait, did you actually work on Quake?!

Lol, no :slight_smile: But I worked with Quake (modded) engine and released one game on Steam using such contraption. Also was working on another game using modified Doom 3 BFG engine.