How to precompile PBR shaders for SceneKit? - scenekit

I've noticed that if you have an empty scene and then load a 3D model in it with physically based lighting, there is a small bit of jank as the object appears. If I then add a different object in after that, that stuttering does not occur.
Looking at the profiler, it appears that the default PBR shaders are compiling during that first slow frame. Is it possible to precompile these shaders so that it doesn't happen when I go to render the model for the first time?
Similar issues have been brought up in other frameworks, like Three.js. Seems like a smart thing to prevent.

If you want to precompile a Physically Based Rendering (PBR) or any other regular SceneKit's shader you must use a SCNProgram class that is a complete Metal shader program that replaces SceneKit's rendering of a geometry or material.
Here's a page with code snippets and useful links showing you how you could work with a vertex or fragment precompiled Metal shaders.

Related

How do I prevent layers from rendering in 3d with Mapbox?

Layers are being rendered in 3d, making them difficult to click, and look bad in general.
As you can see in the image, the dots are rendered about 500 ft off the ground. I'm not aware of any configuration changes I made to enable this, and I can't figure out how to prevent it from happening, although it only seems to happen to some layers (as you can see in the screenshot)
I've tried reordering the layers in Mapbox Studio, but I don't know what else I would change, as this seems to happen regardless of any js changes.
It seems like this was an issue with react-map-gl not being able to render 3d styles correctly. Setting the map to "2d" in Mapbox Studio and using a raster source to generate the 3d terrain seems to have fixed the issue.
https://visgl.github.io/react-map-gl/examples/terrain

Setting D3DImage to Image and Rendering in WPF

I would like to render to a surface using DX12 and present it through WPF. There are claims on the web that this is possible. To me it seems simple. I can render as a traditional image(ie tga) on hard drive, or some mapped memory, and then present that image through D3DImage--or simply an image brush in wpf. I would think the most straight forward approach would be to render to a DXGI surface, and then copy that over to a IDirect3DSurface9. I don't see how I can map from the source to the destination in any scenario--whether it be presenting a tga, or passing the rendered surface from dxgi to dx9. Microsoft's solution on GitHub is broken, and the part with the passing of the image is shrouded in darkness. Previous MS examples have been deleted, and codeproject has examples from last decade. I have no code to date because I don't know what to put into the relevant section. I have no real interest in using the managed solutions that are available.
it seems i may have been a little impatient. the solution to my problem would seem to be ID3D##Device::OpenSharedResource(). when rendering, render to texture with CreateTexture() and pSharedHandle. this will allow the texture resource to be shared with d3d9. then i can consume the texture with a basic d3d9 pipeline that renders the texture to a basic rectangle in wpf through d3dimage. if i'm missing something let me know.

Need recommendations for Image Editing Library

I am trying to create a WPF based application which will allows users to edit photos and provide features like:
Increase/Decrease Brightness
Crop
Retro looks
and lot more.
I am also looking forward to provide more fancy features like : Framing an image, print to a Tshirt, but these are low on priority.
Any open source libraries for that?
P.S -> This is a POC project, even if i miss some features it will be fine.
I would suggest you to use BitmapEffects available in WPF, the BitmapEffects make use Shading language; at present very few effects available in .net Fx. But it is quite easy create your own shaders to adjust the birghtness, gamma, colour saturation, and they can be data bound too. The great thing about shaders is you apply them to videos as well.
Shazzam Tool is on of the best tool to create shadders, it lets you try the effect on your images and generate the C# or VB.Net binding code to use in WPF/Silverlight.
I guess you have to write code to do the image cropping, or quick Google search would help.
Opensource shader effects available here in codeplex.
For a low-level library that allows GDI like operations on bitmaps please see the WriteableBitmapEx library. This is open source and as a disclaimer, I have made a minor contribution to it.
WriteableBitmapEx has functions for drawing shapes, lines, ellipses, applying filters (via matrices, e.g. convolution blur etc), rotation, resize and cropping. You would have to write your own code to apply framing but this could be done by rendering to a separate bitmap and using the Blit function.
Above all its very fast and portable, to WP7 and Silverlight!
Best regards,

Is there a way to animate the edges of an image in WPF?

We have a few icons in our WPF application. We want to do an animation, pretty much like a small beacon of light going around the edges of the animation, just endlessly going around it, and following the silhouette of the icons. We found a way to do it by manually creating a path around the icons and have the beacon follow that path (which matches the silhouette), but it's too much manual work because we have a lot of different shaped icons. We're wondering if there's a way for WPF to do this automatically, so we just have to program it once, and then using on the rest of the icons.
Any suggestion very welcome.
Thanks.
Edit
Something like this.
Gee. Isn't that overkill to use wpf animation capabilities for that? Can't you just create a bunch of small animations in Photoshop or using something else and just put them in?
Like animated .GIFs. the only problem would be that: if I'm remembering it right, WPF have problems with animating .GIFs as embedded resources. So you have to load them from the disk. Or you can have them as embedded resources, but you have to extract them temporarily to the disk and then load them into your app's window.
If you are using .NET 3.5 SP1 or greater and you are requiring a code solution instead of the animated GIFs, my suggestion would be a Pixel Shader. You would need to write your own Pixel Shader that does the following:
Detect the edges. http://www.codeproject.com/KB/openGL/EdgeDetection.aspx
Takes an input parameter that can be animated with a storyboard that indicates the position of the beacon. http://www.codeproject.com/KB/dialog/WpfParentWindowShader.aspx
Highlights the edge that is indicated by the beacon position parameter and returns the original color for all other points in the image.
If you haven't worked with Pixel Shaders I would recommend downloading the Shazzam Tool, http://shazzam-tool.com/. It includes an interactive development environment to create and test your shader on simple images and also includes a decent number of Pixel Shaders with source code to help you learn about them.

WPF-DirectX Interop Problem (D3DImage)

I'm writing a Video application utilizing D3DImage. Frames are from memory and rendered as textures in native code with DirectX9, finally exposed by D3DImage to the WPF GUI. I have some Overlays on top, created with WPF's painting framework (Text, shapes etc.). Up to this point, it works like a charm.
Now, I would like encode the composited image from my underlying native C++ code. Video is 640x480 BGR, 25 FPS and has to be rendered and encoded in parallel, also on older Hardware with Windows versions down to XP/SP3.
Problem is, I cannot find any documentation describing the composition process between WPF and D3DImage. They 'blend' in some sense, but what is the meaning of this? And is it possible to get a handle to the WPF's part of the drawing or even the composited image in my native C++ code?
p.s: I'm also open to managed solutions, but didn't found much performant up to now.
There is global static method called "CompositionTarget.Rendering". Add an event to that and every time WPF renders that method will be called before WPF presents(the FPS can vary though). So just updated your renderTarget accordingly.
There might be a better way, but i'm not aware of it.
NOTE:: Also for D3DImage on WindowsXP you use a D3D9 device with a lockable renderTarget while on Vista/7 you use a D3D9Ex device with a non-lockable renderTarget. Just a note.

Resources