Example #1
0
void InitializeSharedSamplerStates()
{
	Wrap_WorldGroupSettings = new FSharedSamplerState(true);
	Clamp_WorldGroupSettings = new FSharedSamplerState(false);
	BeginInitResource(Wrap_WorldGroupSettings);
	BeginInitResource(Clamp_WorldGroupSettings);
}
void FSlateRHIRenderingPolicy::InitResources()
{
	for( int32 BufferIndex = 0; BufferIndex < 2; ++BufferIndex )
	{
		BeginInitResource(&VertexBuffers[BufferIndex]);
		BeginInitResource(&IndexBuffers[BufferIndex]);
	}
}
	void InitForRender()
	{
		BeginInitResource(&VertexBuffer);
		BeginInitResource(&IndexBuffer);
		BeginInitResource(&VertexFactory);

		should_release = true;
	}
FGeometryCacheSceneProxy::FGeometryCacheSceneProxy(UGeometryCacheComponent* Component) : FPrimitiveSceneProxy(Component)
, MaterialRelevance(Component->GetMaterialRelevance(GetScene().GetFeatureLevel()))
{
	// Copy each section
	const int32 NumSections = Component->TrackSections.Num();
	Sections.AddZeroed(NumSections);
	for (int SectionIdx = 0; SectionIdx < NumSections; SectionIdx++)
	{
		FTrackRenderData& SrcSection = Component->TrackSections[SectionIdx];
		
		if (SrcSection.IndexBuffer.Num() > 0)
		{
			FGeomCacheTrackProxy* NewSection = new FGeomCacheTrackProxy();

			NewSection->WorldMatrix = SrcSection.WorldMatrix;
			FGeometryCacheMeshData* MeshData = NewSection->MeshData = SrcSection.MeshData;

			// Copy data from vertex buffer
			const int32 NumVerts = MeshData->Vertices.Num();

			// Allocate verts
			NewSection->VertexBuffer.Vertices.Empty(NumVerts);
			// Copy verts
			NewSection->VertexBuffer.Vertices.Append(MeshData->Vertices);

			// Copy index buffer
			NewSection->IndexBuffer.Indices = SrcSection.IndexBuffer;

			// Init vertex factory
			NewSection->VertexFactory.Init(&NewSection->VertexBuffer);

			// Enqueue initialization of render resource
			BeginInitResource(&NewSection->VertexBuffer);
			BeginInitResource(&NewSection->IndexBuffer);
			BeginInitResource(&NewSection->VertexFactory);

			// Grab materials
			for (FGeometryCacheMeshBatchInfo& BatchInfo : MeshData->BatchesInfo)
			{
				UMaterialInterface* Material = Component->GetMaterial(BatchInfo.MaterialIndex);
				if (Material == NULL)
				{
					Material = UMaterial::GetDefaultMaterial(MD_Surface);
				}

				NewSection->Materials.Push(Material);
			}			

			// Save ref to new section
			Sections[SectionIdx] = NewSection;
		}
	}
}
void FPaperTileMapRenderSceneProxy::FinishConstruction_GameThread()
{
	if (VertexBuffer.Vertices.Num() > 0)
	{
		// Init the vertex factory
		MyVertexFactory.Init(&VertexBuffer);

		// Enqueue initialization of render resources
		BeginInitResource(&VertexBuffer);
		BeginInitResource(&MyVertexFactory);
	}
}
Example #6
0
/**
 * Called after this UObject has been serialized
 */
void ULightComponent::PostLoad()
{
	Super::PostLoad();

	if (LightFunctionMaterial && HasStaticLighting())
	{
		// Light functions can only be used on dynamic lights
		LightFunctionMaterial = NULL;
	}

	PreviewShadowMapChannel = ShadowMapChannel;
	Intensity = FMath::Max(0.0f, Intensity);

	if (GetLinkerUE4Version() < VER_UE4_LIGHTCOMPONENT_USE_IES_TEXTURE_MULTIPLIER_ON_NON_IES_BRIGHTNESS)
	{
		if(IESTexture)
		{
			UTextureLightProfile* IESTextureObject = Cast<UTextureLightProfile>(IESTexture);

			if(IESTextureObject)
			{
				Intensity /= IESTextureObject->TextureMultiplier; // Previous version didn't apply IES texture multiplier, so cancel out
				IESBrightnessScale = FMath::Pow(IESBrightnessScale, 2.2f); // Previous version applied 2.2 gamma to brightness scale
				IESBrightnessScale /= IESTextureObject->TextureMultiplier; // Previous version didn't apply IES texture multiplier, so cancel out
			}
		}
	}

	if (HasStaticShadowing() && !HasStaticLighting())
	{
		BeginInitResource(&StaticShadowDepthMap);
	}
}
FLightSceneInfo::FLightSceneInfo(FLightSceneProxy* InProxy, bool InbVisible)
	: Proxy(InProxy)
	, DynamicInteractionOftenMovingPrimitiveList(NULL)
	, DynamicInteractionStaticPrimitiveList(NULL)
	, Id(INDEX_NONE)
	, TileIntersectionResources(NULL)
	, bPrecomputedLightingIsValid(InProxy->GetLightComponent()->bPrecomputedLightingIsValid)
	, bVisible(InbVisible)
	, bEnableLightShaftBloom(InProxy->GetLightComponent()->bEnableLightShaftBloom)
	, BloomScale(InProxy->GetLightComponent()->BloomScale)
	, BloomThreshold(InProxy->GetLightComponent()->BloomThreshold)
	, BloomTint(InProxy->GetLightComponent()->BloomTint)
	, NumUnbuiltInteractions(0)
	, bCreatePerObjectShadowsForDynamicObjects(Proxy->ShouldCreatePerObjectShadowsForDynamicObjects())
	, Scene(InProxy->GetLightComponent()->GetScene()->GetRenderScene())
{
	// Only visible lights can be added in game
	check(bVisible || GIsEditor);

	BeginInitResource(this);

	for(uint32 LightTypeIndex = 0;LightTypeIndex < LightType_MAX;++LightTypeIndex)
	{
		for(uint32 A = 0;A < 2;++A)
		{
			for(uint32 B = 0;B < 2;++B)
			{
				for(uint32 C = 0;C < 2;++C)
				{
					TranslucentInjectCachedShaderMaps[LightTypeIndex][A][B][C] = NULL;
				}
			}
		}
	}
}
FOpenGLViewport::FOpenGLViewport(FOpenGLDynamicRHI* InOpenGLRHI,void* InWindowHandle,uint32 InSizeX,uint32 InSizeY,bool bInIsFullscreen,EPixelFormat PreferredPixelFormat)
	: OpenGLRHI(InOpenGLRHI)
	, OpenGLContext(NULL)
	, SizeX(0)
	, SizeY(0)
	, bIsFullscreen(false)
	, PixelFormat(PreferredPixelFormat)
	, bIsValid(true)
	, FrameSyncEvent(InOpenGLRHI)
{
	check(OpenGLRHI);
    //@to-do spurious check for HTML5, will need to go away. 
#if !PLATFORM_HTML5
	check(InWindowHandle);
#endif 
	check(IsInGameThread());
	PlatformGlGetError();	// flush out old errors.
	OpenGLRHI->Viewports.Add(this);
	check(PlatformOpenGLCurrentContext(OpenGLRHI->PlatformDevice) == CONTEXT_Shared);
	OpenGLContext = PlatformCreateOpenGLContext(OpenGLRHI->PlatformDevice, InWindowHandle);
	Resize(InSizeX, InSizeY, bInIsFullscreen);
	check(PlatformOpenGLCurrentContext(OpenGLRHI->PlatformDevice) == CONTEXT_Shared);

	BeginInitResource(&FrameSyncEvent);
}
FSlateShaderResourceProxy* FSlateRHIResourceManager::GenerateTextureResource( const FNewTextureInfo& Info )
{
	FSlateShaderResourceProxy* NewProxy = NULL;
	const uint32 Width = Info.TextureData->GetWidth();
	const uint32 Height = Info.TextureData->GetHeight();

	if( Info.bShouldAtlas )
	{
		const FAtlasedTextureSlot* NewSlot = NULL;
		FSlateTextureAtlasRHI* Atlas = NULL;

		// See if any atlases can hold the texture
		for( int32 AtlasIndex = 0; AtlasIndex < TextureAtlases.Num() && !NewSlot; ++AtlasIndex )
		{
			Atlas = TextureAtlases[AtlasIndex];
			NewSlot = Atlas->AddTexture( Width, Height, Info.TextureData->GetRawBytes() );
		}

		if( !NewSlot )
		{
			INC_DWORD_STAT_BY(STAT_SlateNumTextureAtlases, 1);

			Atlas = new FSlateTextureAtlasRHI( AtlasSize, AtlasSize, ESlateTextureAtlasPaddingStyle::DilateBorder );
			TextureAtlases.Add( Atlas );
			NewSlot = TextureAtlases.Last()->AddTexture( Width, Height, Info.TextureData->GetRawBytes() );
		}
		
		check( Atlas && NewSlot );

		// Create a proxy to the atlased texture. The texture being used is the atlas itself with sub uvs to access the correct texture
		NewProxy = new FSlateShaderResourceProxy;
		NewProxy->Resource = Atlas->GetAtlasTexture();
		const uint32 Padding = NewSlot->Padding;
		NewProxy->StartUV = FVector2D((float)(NewSlot->X + Padding) / Atlas->GetWidth(), (float)(NewSlot->Y + Padding) / Atlas->GetHeight());
		NewProxy->SizeUV = FVector2D( (float)(NewSlot->Width-Padding*2) / Atlas->GetWidth(), (float)(NewSlot->Height-Padding*2) / Atlas->GetHeight() );
		NewProxy->ActualSize = FIntPoint( Width, Height );
	}
	else
	{
		NewProxy = new FSlateShaderResourceProxy;

		// Create a new standalone texture because we can't atlas this one
		FSlateTexture2DRHIRef* Texture = new FSlateTexture2DRHIRef( Width, Height, PF_B8G8R8A8, Info.TextureData, Info.bSrgb ? TexCreate_SRGB : TexCreate_None );
		// Add it to the list of non atlased textures that we must clean up later
		NonAtlasedTextures.Add( Texture );

		INC_DWORD_STAT_BY( STAT_SlateNumNonAtlasedTextures, 1 );

		BeginInitResource( Texture );

		// The texture proxy only contains a single texture
		NewProxy->Resource = Texture;
		NewProxy->StartUV = FVector2D(0.0f, 0.0f);
		NewProxy->SizeUV = FVector2D(1.0f, 1.0f);
		NewProxy->ActualSize = FIntPoint( Width, Height );
	}

	return NewProxy;
}
FD3D11Viewport::FD3D11Viewport(FD3D11DynamicRHI* InD3DRHI,HWND InWindowHandle,uint32 InSizeX,uint32 InSizeY,bool bInIsFullscreen, EPixelFormat InPreferredPixelFormat):
	D3DRHI(InD3DRHI),
	LastFlipTime(0),
	LastFrameComplete(0),
	LastCompleteTime(0),
	SyncCounter(0),
	bSyncedLastFrame(false),
	WindowHandle(InWindowHandle),
	MaximumFrameLatency(3),
	SizeX(InSizeX),
	SizeY(InSizeY),
	bIsFullscreen(bInIsFullscreen),
	PixelFormat(InPreferredPixelFormat),
	bIsValid(true),
	FrameSyncEvent(InD3DRHI)
{
	check(IsInGameThread());
	D3DRHI->Viewports.Add(this);

	// Ensure that the D3D device has been created.
	D3DRHI->InitD3DDevice();

	// Create a backbuffer/swapchain for each viewport
	TRefCountPtr<IDXGIDevice> DXGIDevice;
	VERIFYD3D11RESULT(D3DRHI->GetDevice()->QueryInterface( IID_IDXGIDevice, (void**)DXGIDevice.GetInitReference() ));

	// Create the swapchain.
	DXGI_SWAP_CHAIN_DESC SwapChainDesc;
	FMemory::Memzero( &SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC) );

	SwapChainDesc.BufferDesc = SetupDXGI_MODE_DESC();
	// MSAA Sample count
	SwapChainDesc.SampleDesc.Count = 1;
	SwapChainDesc.SampleDesc.Quality = 0;
	SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
	// 1:single buffering, 2:double buffering, 3:triple buffering
	SwapChainDesc.BufferCount = 1;
	SwapChainDesc.OutputWindow = WindowHandle;
	SwapChainDesc.Windowed = !bIsFullscreen;
	// DXGI_SWAP_EFFECT_DISCARD / DXGI_SWAP_EFFECT_SEQUENTIAL
	SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
	VERIFYD3D11RESULT(D3DRHI->GetFactory()->CreateSwapChain(DXGIDevice,&SwapChainDesc,SwapChain.GetInitReference()));

	// Set the DXGI message hook to not change the window behind our back.
	D3DRHI->GetFactory()->MakeWindowAssociation(WindowHandle,DXGI_MWA_NO_WINDOW_CHANGES);

	// Create a RHI surface to represent the viewport's back buffer.
	BackBuffer = GetSwapChainSurface(D3DRHI, PixelFormat, SwapChain);

	// Tell the window to redraw when they can.
	// @todo: For Slate viewports, it doesn't make sense to post WM_PAINT messages (we swallow those.)
	::PostMessage( WindowHandle, WM_PAINT, 0, 0 );

	BeginInitResource(&FrameSyncEvent);
}
FTangoPointCloudSceneProxy::FTangoPointCloudSceneProxy(const UTangoPointsComponent * InComponent) : 
	FPrimitiveSceneProxy(InComponent)
{
	//Get all the information we are going to use ready for upload to the Graphics Card.
	PointSize = 3.0;
	Color = FLinearColor(.75, .75, .75);
	DepthPriority = 1;
	//If we specify a material, use it, otherwise use default.
	Material = InComponent->Material ? InComponent->Material : UMaterial::GetDefaultMaterial(MD_Surface);
	
	//Double check we won't cause a seg fault
	if (UTangoDevice::Get().getTangoDevicePointCloudPointer()) 
	{
		FColor initColor = Color.ToFColor(true);

		TArray<FVector> & points = UTangoDevice::Get().getTangoDevicePointCloudPointer()->GetPointCloud();
		const int32 vertexCount = points.Num();
		VertexBuffer.Vertices.SetNumUninitialized(vertexCount);
		IndexBuffer.Indices.SetNumUninitialized(vertexCount);

		//Initialize the Vertex and Index buffers with their data.
		for (int index = 0; index < vertexCount; index++)
		{
			VertexBuffer.Vertices[index].Position = points[index];
			VertexBuffer.Vertices[index].Color = initColor;
			IndexBuffer.Indices[index] = index;
		}

		//Initialise the Vertex Factory with our Vertices.
		VertexFactory.Init(&VertexBuffer);

		//Tell the RHI to initialise the resources on the Graphics Card.
		BeginInitResource(&VertexBuffer);
		BeginInitResource(&IndexBuffer);
		BeginInitResource(&VertexFactory);
	}

	bWillEverBeLit = true;
	ViewRelevance.bDrawRelevance = true;
	ViewRelevance.bDynamicRelevance = true;
	// ideally the TranslucencyRelevance should be filled out by the material, here we do it conservative
	ViewRelevance.bSeparateTranslucencyRelevance = ViewRelevance.bNormalTranslucencyRelevance = true;
}
Example #12
0
FTileItemThumbnail::FTileItemThumbnail(FSlateTextureRenderTarget2DResource* InThumbnailRenderTarget, 
									   TSharedPtr<FLevelModel> InItemModel)
	: LevelModel(InItemModel)
	, ThumbnailTexture(NULL)
	, ThumbnailRenderTarget(InThumbnailRenderTarget)
{
	FIntPoint RTSize = ThumbnailRenderTarget->GetSizeXY();
	ThumbnailTexture = new FSlateTexture2DRHIRef(RTSize.X, RTSize.Y, PF_B8G8R8A8, NULL, TexCreate_Dynamic);
	BeginInitResource(ThumbnailTexture);
}
Example #13
0
FShotThumbnail::FShotThumbnail(TSharedPtr<FShotSection> InSection, const FIntPoint& InSize, TRange<float> InTimeRange)
	: OwningSection(InSection)
	, Size(InSize)
	, Texture(NULL)
	, TimeRange(InTimeRange)
	, FadeInCurve( 0.0f, ShotTrackConstants::ThumbnailFadeInDuration )
{
	Texture = new FSlateTexture2DRHIRef(GetSize().X, GetSize().Y, PF_B8G8R8A8, nullptr, TexCreate_Dynamic, true);

	BeginInitResource( Texture );

}
FShotThumbnail::FShotThumbnail(TSharedPtr<FShotSection> InSection, TRange<float> InTimeRange)
	: OwningSection(InSection)
	, Texture(NULL)
	, TimeRange(InTimeRange)
{
	ThumbnailFadeAnimation = FCurveSequence();
	ThumbnailFadeCurve = ThumbnailFadeAnimation.AddCurve(0.f, 0.25f, ECurveEaseFunction::QuadOut);

	Texture = new FSlateTexture2DRHIRef(GetSize().X, GetSize().Y, PF_B8G8R8A8, NULL, TexCreate_Dynamic, true);

	BeginInitResource( Texture );

}
Example #15
0
void FSceneViewport::UpdateViewportRHI(bool bDestroyed, uint32 NewSizeX, uint32 NewSizeY, EWindowMode::Type NewWindowMode)
{
	{
		SCOPED_SUSPEND_RENDERING_THREAD(true);

		// Update the viewport attributes.
		// This is done AFTER the command flush done by UpdateViewportRHI, to avoid disrupting rendering thread accesses to the old viewport size.
		SizeX = NewSizeX;
		SizeY = NewSizeY;
		WindowMode = NewWindowMode;

		// Release the viewport's resources.
		BeginReleaseResource(this);

		if( !bDestroyed )
		{
			BeginInitResource(this);
				
			if( !bUseSeparateRenderTarget )
			{
				// Get the viewport for this window from the renderer so we can render directly to the backbuffer
				TSharedPtr<FSlateRenderer> Renderer = FSlateApplication::Get().GetRenderer();
				FWidgetPath WidgetPath;
				void* ViewportResource = Renderer->GetViewportResource( *FSlateApplication::Get().FindWidgetWindow( ViewportWidget.Pin().ToSharedRef(), WidgetPath ) );
				if( ViewportResource )
				{
					ViewportRHI = *((FViewportRHIRef*)ViewportResource);
				}
			}

			ViewportResizedEvent.Broadcast(this, 0);
		}
		else
		{
			// Enqueue a render command to delete the handle.  It must be deleted on the render thread after the resource is released
			ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(DeleteSlateRenderTarget, TArray<FSlateRenderTargetRHI*>&, BufferedSlateHandles, BufferedSlateHandles,
																				FSlateRenderTargetRHI*&, RenderThreadSlateTexture, RenderThreadSlateTexture,
			{
				for (int32 i = 0; i < BufferedSlateHandles.Num(); ++i)
				{
					delete BufferedSlateHandles[i];
					BufferedSlateHandles[i] = nullptr;

					delete RenderThreadSlateTexture;
					RenderThreadSlateTexture = nullptr;
				}						
			});

		}
	}
// On CPU
void UAtmosphericFogComponent::InitResource()
{
    bool bNewAtmosphere = CVarAtmosphereRender.GetValueOnGameThread() != 0;

    if(!bNewAtmosphere)
    {
        return; // Don't do initialize resource when Atmosphere Render is off
    }

    if (PrecomputeCounter >= EValid)
    {
        // A little inefficient for thread-safe
        if (TransmittanceData.GetElementCount() && TransmittanceResource == NULL)
        {
            TransmittanceResource = new FAtmosphereTextureResource( PrecomputeParams, TransmittanceData, FAtmosphereTextureResource::E_Transmittance );
            BeginInitResource( TransmittanceResource );
        }

        if (IrradianceData.GetElementCount() && IrradianceResource == NULL)
        {
            IrradianceResource = new FAtmosphereTextureResource( PrecomputeParams, IrradianceData, FAtmosphereTextureResource::E_Irradiance );
            BeginInitResource( IrradianceResource );
        }

        if (InscatterData.GetElementCount() && InscatterResource == NULL)
        {
            InscatterResource = new FAtmosphereTextureResource( PrecomputeParams, InscatterData, FAtmosphereTextureResource::E_Inscatter );
            BeginInitResource( InscatterResource );
        }
    }
#if WITH_EDITOR
    else if (!PrecomputeDataHandler && !IsTemplate())
    {
        PrecomputeDataHandler = new FAtmospherePrecomputeDataHandler(this);
    }
#endif
}
Example #17
0
void UTexture::UpdateResource()
{
	// Release the existing texture resource.
	ReleaseResource();

	//Dedicated servers have no texture internals
	if( FApp::CanEverRender() && !HasAnyFlags(RF_ClassDefaultObject) )
	{
		// Create a new texture resource.
		Resource = CreateResource();
		if( Resource )
		{
			BeginInitResource(Resource);
		}
	}
}
Example #18
0
void FSceneViewport::UpdateViewportRHI(bool bDestroyed, uint32 NewSizeX, uint32 NewSizeY, EWindowMode::Type NewWindowMode)
{
	// Make sure we're not in the middle of streaming textures.
	(*GFlushStreamingFunc)();

	{
		SCOPED_SUSPEND_RENDERING_THREAD(true);

		// Update the viewport attributes.
		// This is done AFTER the command flush done by UpdateViewportRHI, to avoid disrupting rendering thread accesses to the old viewport size.
		SizeX = NewSizeX;
		SizeY = NewSizeY;
		WindowMode = NewWindowMode;

		// Release the viewport's resources.
		BeginReleaseResource(this);

		if( !bDestroyed )
		{
			BeginInitResource(this);
				
			if( !bUseSeparateRenderTarget )
			{
				// Get the viewport for this window from the renderer so we can render directly to the backbuffer
				TSharedPtr<FSlateRenderer> Renderer = FSlateApplication::Get().GetRenderer();
				FWidgetPath WidgetPath;
				void* ViewportResource = Renderer->GetViewportResource( *FSlateApplication::Get().FindWidgetWindow( ViewportWidget.Pin().ToSharedRef(), WidgetPath ) );
				if( ViewportResource )
				{
					ViewportRHI = *((FViewportRHIRef*)ViewportResource);
				}
			}

			ViewportResizedEvent.Broadcast(this, 0);
		}
		else
		{
			// Enqueue a render command to delete the handle.  It must be deleted on the render thread after the resource is released
			ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(DeleteSlateRenderTarget, FSlateRenderTargetRHI*&, SlateRenderTargetHandle, SlateRenderTargetHandle,
			{
				delete SlateRenderTargetHandle;
				SlateRenderTargetHandle = NULL;
			});

		}
	}
/** Export the data from a string, used for editor Copy&Paste. */
void FColorVertexBuffer::ImportText(const TCHAR* SourceText)
{
	check(SourceText);
	check(!VertexData);

	uint32 VertexCount;

	if (FParse::Value(SourceText, TEXT("ColorVertexData("), VertexCount))
	{
		while(*SourceText && *SourceText != TEXT(')'))
		{
			++SourceText;
		}

		while(*SourceText && *SourceText != TEXT('('))
		{
			++SourceText;
		}

		check(*SourceText == TEXT('('));
		++SourceText;

		NumVertices = VertexCount;
		AllocateData();
		VertexData->ResizeBuffer(NumVertices);
		uint8 *Dst = (uint8 *)VertexData->GetDataPointer();

		// 9 characters per color (ARGB in hex plus comma)
		for( uint32 i = 0; i < NumVertices; ++i)
		{
			// does not handle endianess or malformed input
			*Dst++ = FParse::HexDigit(SourceText[6]) * 16 + FParse::HexDigit(SourceText[7]);
			*Dst++ = FParse::HexDigit(SourceText[4]) * 16 + FParse::HexDigit(SourceText[5]);
			*Dst++ = FParse::HexDigit(SourceText[2]) * 16 + FParse::HexDigit(SourceText[3]);
			*Dst++ = FParse::HexDigit(SourceText[0]) * 16 + FParse::HexDigit(SourceText[1]);
			SourceText += 9;
		}
		check(*(SourceText - 1) == TCHAR(')'));

		// Make a copy of the vertex data pointer.
		Data = VertexData->GetDataPointer();

		BeginInitResource(this);
	}
}
FPrimitiveSceneProxy::FPrimitiveSceneProxy(const UPrimitiveComponent* InComponent, FName InResourceName)
:	WireframeColor(FLinearColor::White)
,	LevelColor(FLinearColor::White)
,	PropertyColor(FLinearColor::White)
,	DrawInGame(InComponent->bVisible && !InComponent->bHiddenInGame)
,	DrawInEditor(InComponent->bVisible)
,	bReceivesDecals(InComponent->bReceivesDecals)
,	bOnlyOwnerSee(InComponent->bOnlyOwnerSee)
,	bOwnerNoSee(InComponent->bOwnerNoSee)
,	bStatic(false)
,	bOftenMoving(false)
,	bParentSelected(InComponent->ShouldRenderSelected())
,	bIndividuallySelected(InComponent->IsComponentIndividuallySelected())
,	bHovered(false)
,	bUseViewOwnerDepthPriorityGroup(InComponent->bUseViewOwnerDepthPriorityGroup)
,	bHasMotionBlurVelocityMeshes(InComponent->bHasMotionBlurVelocityMeshes)
,	StaticDepthPriorityGroup(InComponent->GetStaticDepthPriorityGroup())
,	ViewOwnerDepthPriorityGroup(InComponent->ViewOwnerDepthPriorityGroup)
,	bStaticLighting(InComponent->HasStaticLighting())
,	bRenderInMainPass(InComponent->bRenderInMainPass)
,	bRequiresVisibleLevelToRender(false)
,	bIsComponentLevelVisible(false)
,	bCollisionEnabled(InComponent->IsCollisionEnabled())
,	bTreatAsBackgroundForOcclusion(InComponent->bTreatAsBackgroundForOcclusion)
,	bDisableStaticPath(false)
,	bNeedsUnbuiltPreviewLighting(InComponent->HasStaticLighting() && !InComponent->bHasCachedStaticLighting)
,	bHasValidSettingsForStaticLighting(InComponent->HasValidSettingsForStaticLighting())
,	bWillEverBeLit(true)
	// Disable dynamic shadow casting if the primitive only casts indirect shadows, since dynamic shadows are always shadowing direct lighting
,	bCastDynamicShadow(InComponent->bCastDynamicShadow && InComponent->CastShadow && !InComponent->GetShadowIndirectOnly())
,   bAffectDynamicIndirectLighting(InComponent->bAffectDynamicIndirectLighting)
,   bAffectDistanceFieldLighting(InComponent->bAffectDistanceFieldLighting)
,	bCastStaticShadow(InComponent->CastShadow && InComponent->bCastStaticShadow)
,	bCastVolumetricTranslucentShadow(InComponent->bCastDynamicShadow && InComponent->CastShadow && InComponent->bCastVolumetricTranslucentShadow)
,	bCastHiddenShadow(InComponent->bCastHiddenShadow)
,	bCastShadowAsTwoSided(InComponent->bCastShadowAsTwoSided)
,	bSelfShadowOnly(InComponent->bSelfShadowOnly)
,	bCastInsetShadow(InComponent->bSelfShadowOnly ? true : InComponent->bCastInsetShadow)	// Assumed to be enabled if bSelfShadowOnly is enabled.
,	bCastCinematicShadow(InComponent->bCastCinematicShadow)
,	bCastFarShadow(InComponent->bCastFarShadow)
,	bLightAsIfStatic(InComponent->bLightAsIfStatic)
,	bLightAttachmentsAsGroup(InComponent->bLightAttachmentsAsGroup)
,	bStaticElementsAlwaysUseProxyPrimitiveUniformBuffer(false)
,	bAlwaysHasVelocity(false)
,	bUseEditorDepthTest(true)
,	bSupportsDistanceFieldRepresentation(false)
,	bSupportsHeightfieldRepresentation(false)
,	bNeedsLevelAddedToWorldNotification(false)
,	bUseAsOccluder(InComponent->bUseAsOccluder)
,	bAllowApproximateOcclusion(InComponent->Mobility != EComponentMobility::Movable)
,	bSelectable(InComponent->bSelectable)
,	bHasPerInstanceHitProxies(InComponent->bHasPerInstanceHitProxies)
,	bUseEditorCompositing(InComponent->bUseEditorCompositing)
,	bRenderCustomDepth(InComponent->bRenderCustomDepth)
,	CustomDepthStencilValue((uint8)InComponent->CustomDepthStencilValue) 
,	LpvBiasMultiplier(InComponent->LpvBiasMultiplier)
,	IndirectLightingCacheQuality(InComponent->IndirectLightingCacheQuality)
,	Scene(InComponent->GetScene())
,	PrimitiveComponentId(InComponent->ComponentId)
,	PrimitiveSceneInfo(NULL)
,	OwnerName(InComponent->GetOwner() ? InComponent->GetOwner()->GetFName() : NAME_None)
,	ResourceName(InResourceName)
,	LevelName(InComponent->GetOutermost()->GetFName())
#if WITH_EDITOR
// by default we are always drawn
,	HiddenEditorViews(0)
#endif
,	TranslucencySortPriority(FMath::Clamp(InComponent->TranslucencySortPriority, SHRT_MIN, SHRT_MAX))
,	VisibilityId(InComponent->VisibilityId)
,	StatId()
,	MaxDrawDistance(InComponent->CachedMaxDrawDistance > 0 ? InComponent->CachedMaxDrawDistance : FLT_MAX)
,	MinDrawDistance(InComponent->MinDrawDistance)
,	ComponentForDebuggingOnly(InComponent)
#if WITH_EDITOR
,	NumUncachedStaticLightingInteractions(0)
,	HierarchicalLODOverride(0)
#endif
{
	check(Scene);

#if STATS
	{
		UObject const* StatObject = InComponent->AdditionalStatObject(); // prefer the additional object, this is usually the thing related to the component
		if (!StatObject)
		{
			StatObject = InComponent;
		}
		StatId = StatObject->GetStatID(true);
	}
#endif

	// Initialize the uniform buffer resource.
	BeginInitResource(&UniformBuffer);

	if (bNeedsUnbuiltPreviewLighting && !bHasValidSettingsForStaticLighting)
	{
		// Don't use unbuilt preview lighting for static components that have an invalid lightmap UV setup
		// Otherwise they would light differently in editor and in game, even after a lighting rebuild
		bNeedsUnbuiltPreviewLighting = false;
	}

	bStatic = InComponent->Mobility == EComponentMobility::Static;
	bOftenMoving = InComponent->Mobility == EComponentMobility::Movable;

	if(InComponent->GetOwner())
	{
		DrawInGame &= !(InComponent->GetOwner()->bHidden);
		#if WITH_EDITOR
			DrawInEditor &= !InComponent->GetOwner()->IsHiddenEd();
		#endif

		if(bOnlyOwnerSee || bOwnerNoSee || bUseViewOwnerDepthPriorityGroup)
		{
			// Make a list of the actors which directly or indirectly own the component.
			for(const AActor* Owner = InComponent->GetOwner();Owner;Owner = Owner->GetOwner())
			{
				Owners.Add(Owner);
			}
		}

#if WITH_EDITOR
		// cache the actor's group membership
		HiddenEditorViews = InComponent->GetOwner()->HiddenEditorViews;
#endif
	}
	
	// 
	// Flag components to render only after level will be fully added to the world
	//
	ULevel* ComponentLevel = InComponent->GetComponentLevel();
	bRequiresVisibleLevelToRender = (ComponentLevel && ComponentLevel->bRequireFullVisibilityToRender);
	bIsComponentLevelVisible = (!ComponentLevel || ComponentLevel->bIsVisible);
}
Example #21
0
void FStaticShadowDepthMap::InitializeAfterImport()
{
	INC_DWORD_STAT_BY(STAT_PrecomputedShadowDepthMapMemory, DepthSamples.GetAllocatedSize());
	BeginInitResource(this);
}
void UReflectionCaptureComponent::PostLoad()
{
	Super::PostLoad();

	// If we're loading on a platform that doesn't require cooked data, attempt to load missing data from the DDC
	if (!FPlatformProperties::RequiresCookedData())
	{
		// Only check the DDC if we don't already have it loaded
		// If we are loading cooked then FullHDRDerivedData might be setup already (FullHDRDerivedData is set in Serialize)
		if (!FullHDRDerivedData)
		{
			FullHDRDerivedData = new FReflectionCaptureFullHDRDerivedData();

			// Attempt to load the full HDR data from the DDC
			if (!GetDerivedDataCacheRef().GetSynchronous(*FReflectionCaptureFullHDRDerivedData::GetDDCKeyString(StateId), FullHDRDerivedData->CompressedCapturedData))
			{
				bDerivedDataDirty = true;
				delete FullHDRDerivedData;
				FullHDRDerivedData = NULL;

				if (!FApp::CanEverRender())
				{
					// Warn, especially when running the DDC commandlet to build a DDC for the binary version of UE4.
					UE_LOG(LogMaterial, Warning, TEXT("Reflection capture was loaded without any valid capture data and will be black.  This can happen if the DDC was not up to date during cooking.  Load the map in the editor once before cooking to fix.  %s."), *GetFullName());
				}
			}
		}

		// If we have full HDR data but not encoded HDR data, generate the encoded data now
		if (FullHDRDerivedData 
			&& !EncodedHDRDerivedData 
			&& GRHIFeatureLevel == ERHIFeatureLevel::ES2)
		{
			EncodedHDRDerivedData = FReflectionCaptureEncodedHDRDerivedData::GenerateEncodedHDRData(*FullHDRDerivedData, StateId, Brightness);
		}
	}
	
	// Initialize rendering resources for the current feature level, and toss data only needed by other feature levels
	if (FullHDRDerivedData && GRHIFeatureLevel >= ERHIFeatureLevel::SM4)
	{
		// Don't need encoded HDR data for rendering on this feature level
		INC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,FullHDRDerivedData->CompressedCapturedData.GetAllocatedSize());
		EncodedHDRDerivedData = NULL;

		if (GRHIFeatureLevel == ERHIFeatureLevel::SM4)
		{
			SM4FullHDRCubemapTexture = new FReflectionTextureCubeResource();
			SM4FullHDRCubemapTexture->SetupParameters(GReflectionCaptureSize, FMath::CeilLogTwo(GReflectionCaptureSize) + 1, PF_FloatRGBA, &FullHDRDerivedData->GetCapturedDataForSM4Load());
			BeginInitResource(SM4FullHDRCubemapTexture);
		}
	}
	else if (EncodedHDRDerivedData && GRHIFeatureLevel == ERHIFeatureLevel::ES2)
	{
		if (FPlatformProperties::RequiresCookedData())
		{
			INC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,EncodedHDRDerivedData->CapturedData.GetAllocatedSize());
		}

		// Create a cubemap texture out of the encoded HDR data
		EncodedHDRCubemapTexture = new FReflectionTextureCubeResource();
		EncodedHDRCubemapTexture->SetupParameters(GReflectionCaptureSize, FMath::CeilLogTwo(GReflectionCaptureSize) + 1, PF_B8G8R8A8, &EncodedHDRDerivedData->CapturedData);
		BeginInitResource(EncodedHDRCubemapTexture);

		// Don't need the full HDR data for rendering on this feature level
		delete FullHDRDerivedData;
		FullHDRDerivedData = NULL;
	}

	// PostLoad was called, so we can make a proper decision based on visibility of whether or not to update
	ReflectionCapturesToUpdateNewlyCreated.Remove(this);

	// Add ourselves to the global list of reflection captures that need to be uploaded to the scene or recaptured
	if (bVisible)
	{
		ReflectionCapturesToUpdateForLoad.AddUnique(this);
		bCaptureDirty = true; 
	}
}
void FSlateElementIndexBuffer::Init( int32 MinNumIndices )
{
	MinBufferSize = sizeof(SlateIndex) * FMath::Max( MinNumIndices, 200 );

	BeginInitResource(this);
}