×
Namespaces

Variants
Actions
(Difference between revisions)

Creating a Lens application that uses HLSL effects for filters

From Nokia Developer Wiki
Jump to: navigation, search
r2d2rigo (Talk | contribs)
(R2d2rigo - Article created)
 
chintandave_er (Talk | contribs)
(Chintandave er - edited ArticleMetadata, added author)
Line 1: Line 1:
 
[[Category:Draft]]
 
[[Category:Draft]]
 
{{Abstract|This article covers how to create a Lens application that applies different filters to the photos. These filters are programmed in High Level Shading Language and are executed on the GPU to take advantage of the new DirectX functionality introduced in Windows Phone 8.}}
 
{{Abstract|This article covers how to create a Lens application that applies different filters to the photos. These filters are programmed in High Level Shading Language and are executed on the GPU to take advantage of the new DirectX functionality introduced in Windows Phone 8.}}
 +
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by=<!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= <!-- Format YYYYMMDD -->
 +
|author=  [[User:r2d2rigo]]
 +
}}
  
 
== Introduction ==
 
== Introduction ==
Line 44: Line 67:
  
 
''Remove Category:Draft when the page is complete or near complete''
 
''Remove Category:Draft when the page is complete or near complete''
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|review-by=<!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|creationdate= <!-- Format YYYYMMDD -->
 
|author= <!-- Display as link [[User:username]] -->
 
}}
 

Revision as of 10:02, 19 November 2012

This article covers how to create a Lens application that applies different filters to the photos. These filters are programmed in High Level Shading Language and are executed on the GPU to take advantage of the new DirectX functionality introduced in Windows Phone 8.

WP Metro Icon Multimedia.png
WP Metro Icon UI.png
WP Metro Icon DirectX.png
WP Metro Icon WP8.png
Article Metadata
Compatibility
Platform(s):
Windows Phone 8
Article
Created: r2d2rigo (20 Nov 2012)
Last edited: chintandave_er (19 Nov 2012)

Contents

Introduction

Creating the base project

Modifying the MainPage

Open a new instance of Visual Studio and create a project based on the Windows Phone App template. We will be using a standard C#/XAML application and modify it further to accustom our requirements. Start by opening the MainPage.xaml file and deleting the Grid control named LayoutRoot and all its children elements. Now create a control of type DrawingSurfaceBackgroundGrid as the page's root and give it a name (we will be calling it DrawingSurface). This is required when your application is going to use full screen mode for advanced graphics rendering through DirectX, so you don't get any performance penalties derived from the XAML composition system. You can find more info about this control in the MSDN article Direct3D with XAML apps for Windows Phone 8.

Adding SharpDX references

Instead of using the default DirectX interoperatiblity though a separate C++ DLL, we are going to use the SharpDX library to make drawing calls from C# code. This library is a wrapper of the underlying DirectX functions that allow them to be used in any .NET language and currently supports Windows Desktop, Windows Metro and Windows Phone 8. Start by heading to the downloads section and get the package of your choice: "binary only" includes the libraries and "full package" has some sample code on how to perform common tasks with SharpDX.

Create a new directory inside your project's folder called Lib. Open it and create two child folders called x86 and ARM. Decompress the package you downloaded and from the Bin folder, copy the contents of Standard-wp8-x86 to your x86 folder and Standard-wp8-ARM to ARM. In your project, right click on References and select Add References..., and in the new window click Browse and navigate to the Lib\x86 folder to select the following assemblies:

  • SharpDX.dll
  • SharpDX.DXGI.dll
  • SharpDX.Direct3D11.dll
  • SharpDX.Toolkit.dll
  • SharpDX.Toolkit.Game.dll
  • ShaprDX.Toolkit.Graphics.dll

Since the assemblies aren't AnyCPU, and currently we only have the x86 ones referenced, we must edit our project manually so the compiler references the correct ones. Close Visual Studio and open your CSPROJ file in your favourite text editor and look for the items named Reference, like this one:

<Reference Include="SharpDX">
<HintPath>Lib\x86\SharpDX.dll</HintPath>
</Reference>

You need to change the x86 part of the path to $(Platform), so it ends like this:

<Reference Include="SharpDX">
<HintPath>Lib\$(Platform)\SharpDX.dll</HintPath>
</Reference>

What we have written is a MSBuild property that gets replaced with the current platform name when building the project, so the correct version of the assemblies is used. Repeat this step for all existing references to SharpDX. When finished, save the changes and reopen the solution in Visual Studio.

Note.pngNote: If Visual Studio can't find the SharpDX references, go to the Build > Configuration Manager... menu and change Active solution platform to x86. Remember to change it again to ARM when deploying to a Windows Phone 8 device.



Remove Category:Draft when the page is complete or near complete

516 page views in the last 30 days.