10.1.8000.0
This commit is contained in:
Родитель
7d1ed356b8
Коммит
8c21807f62
|
@ -0,0 +1,18 @@
|
|||
vec4 Diffuse()
|
||||
{
|
||||
vec4 diffuseColor = vec4(0);
|
||||
diffuseColor.xyzw += USERPERVERT1;
|
||||
diffuseColor.xyzw += USERPERCORN1.xyxy;
|
||||
diffuseColor.xyz += TRIINDEX14;
|
||||
|
||||
if( sg_MaterialIdFilter == 5 )
|
||||
diffuseColor = textureLod(DiffuseTexture,TEXCOORD0,4);
|
||||
|
||||
if( diffuseColor == vec4(0) && sg_MaterialIdFilter > 5 )
|
||||
diffuseColor.xyz += CUSTOM23[ sg_MaterialIdFilter ].xyz;
|
||||
|
||||
if( diffuseColor == vec4(0) )
|
||||
diffuseColor = texture(DiffuseTexture,TEXCOORD0);
|
||||
|
||||
return diffuseColor;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
// The CalculateDiffuseChannel function samples from the CastingTexturesArray, index 0, which is the diffuse map bound to this evaluation shader.
|
||||
// The function also blends the result with the color value from the CustomBuffer buffer, which is a custom field in the scene (added by the
|
||||
// scene descriptor .xml file) and which has a 20-byte struct per-material. The function uses the built-in sg_MaterialIdFilter value to do
|
||||
// the lookup into the buffer.
|
||||
|
||||
float4 CalculateDiffuseChannel()
|
||||
{
|
||||
// sample the texture from the CastingTexturesArray[0] using the bound DiffuseSampler sampler
|
||||
float4 colorValue = CastingTexturesArray[0].SampleLevel( DiffuseSampler , TexCoord , 0 ) * 0.7f;
|
||||
|
||||
// blend with the custom value from the CustomBuffer, which is of type customStruct, and is defined in "HeaderCode.hlsl"
|
||||
colorValue += CustomBuffer[sg_MaterialIdFilter].color * 0.3f;
|
||||
|
||||
// return the blended color value
|
||||
return colorValue;
|
||||
}
|
||||
|
||||
// The CalculateNormalsChannel calculates the per-texel normals of the output tangent-space normal map. It starts by sampling the input
|
||||
// tangent-space normal map of the input geometry, and transforms the normal into object-space coordinates. It then uses the generated
|
||||
// destination tangent basis vectors to transform the normal vector into the output tangent-space.
|
||||
|
||||
float4 CalculateNormalsChannel()
|
||||
{
|
||||
// sample the input tangent-space texture, and decode into [-1 -> 1] basis
|
||||
float3 tangentSpaceNormal = (CastingTexturesArray[1].SampleLevel( NormalSampler , TexCoord , 0 ).xyz * 2.0) - 1.0;
|
||||
|
||||
// transform into an object-space vector
|
||||
float3 objectSpaceNormal = tangentSpaceNormal.x * normalize(Tangent) +
|
||||
tangentSpaceNormal.y * normalize(Bitangent) +
|
||||
tangentSpaceNormal.z * normalize(Normal);
|
||||
|
||||
// transform the object-space vector into the destination tangent space
|
||||
tangentSpaceNormal.x = dot( objectSpaceNormal , normalize(sg_DestinationTangent) );
|
||||
tangentSpaceNormal.y = dot( objectSpaceNormal , normalize(sg_DestinationBitangent) );
|
||||
tangentSpaceNormal.z = dot( objectSpaceNormal , normalize(sg_DestinationNormal) );
|
||||
|
||||
// normalize, the tangent basis is not necessarily orthogonal
|
||||
tangentSpaceNormal = normalize(tangentSpaceNormal);
|
||||
|
||||
// encode into [0 -> 1] basis and return
|
||||
return float4( ((tangentSpaceNormal + 1.0)/2.0) , 1.0);
|
||||
}
|
|
@ -0,0 +1,230 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include "SimplygonLoader.h"
|
||||
|
||||
|
||||
Simplygon::spScene LoadScene(Simplygon::ISimplygon* sg, const char* path)
|
||||
{
|
||||
// Create scene importer
|
||||
Simplygon::spSceneImporter sgSceneImporter = sg->CreateSceneImporter();
|
||||
sgSceneImporter->SetImportFilePath(path);
|
||||
|
||||
// Run scene importer.
|
||||
auto importResult = sgSceneImporter->Run();
|
||||
if (Simplygon::Failed(importResult))
|
||||
{
|
||||
throw std::exception("Failed to load scene.");
|
||||
}
|
||||
Simplygon::spScene sgScene = sgSceneImporter->GetScene();
|
||||
return sgScene;
|
||||
}
|
||||
|
||||
void SaveScene(Simplygon::ISimplygon* sg, Simplygon::spScene sgScene, const char* path)
|
||||
{
|
||||
// Create scene exporter.
|
||||
Simplygon::spSceneExporter sgSceneExporter = sg->CreateSceneExporter();
|
||||
std::string outputScenePath = std::string("output\\") + std::string("ComputeCastingWithSceneDescription") + std::string("_") + std::string(path);
|
||||
sgSceneExporter->SetExportFilePath(outputScenePath.c_str());
|
||||
sgSceneExporter->SetScene(sgScene);
|
||||
|
||||
// Run scene exporter.
|
||||
auto exportResult = sgSceneExporter->Run();
|
||||
if (Simplygon::Failed(exportResult))
|
||||
{
|
||||
throw std::exception("Failed to save scene.");
|
||||
}
|
||||
}
|
||||
|
||||
void CheckLog(Simplygon::ISimplygon* sg)
|
||||
{
|
||||
// Check if any errors occurred.
|
||||
bool hasErrors = sg->ErrorOccurred();
|
||||
if (hasErrors)
|
||||
{
|
||||
Simplygon::spStringArray errors = sg->CreateStringArray();
|
||||
sg->GetErrorMessages(errors);
|
||||
auto errorCount = errors->GetItemCount();
|
||||
if (errorCount > 0)
|
||||
{
|
||||
printf("%s\n", "Errors:");
|
||||
for (auto errorIndex = 0U; errorIndex < errorCount; ++errorIndex)
|
||||
{
|
||||
Simplygon::spString errorString = errors->GetItem((int)errorIndex);
|
||||
printf("%s\n", errorString.c_str());
|
||||
}
|
||||
sg->ClearErrorMessages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", "No errors.");
|
||||
}
|
||||
|
||||
// Check if any warnings occurred.
|
||||
bool hasWarnings = sg->WarningOccurred();
|
||||
if (hasWarnings)
|
||||
{
|
||||
Simplygon::spStringArray warnings = sg->CreateStringArray();
|
||||
sg->GetWarningMessages(warnings);
|
||||
auto warningCount = warnings->GetItemCount();
|
||||
if (warningCount > 0)
|
||||
{
|
||||
printf("%s\n", "Warnings:");
|
||||
for (auto warningIndex = 0U; warningIndex < warningCount; ++warningIndex)
|
||||
{
|
||||
Simplygon::spString warningString = warnings->GetItem((int)warningIndex);
|
||||
printf("%s\n", warningString.c_str());
|
||||
}
|
||||
sg->ClearWarningMessages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", "No warnings.");
|
||||
}
|
||||
|
||||
// Error out if Simplygon has errors.
|
||||
if (hasErrors)
|
||||
{
|
||||
throw std::exception("Processing failed with an error");
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeCasting(Simplygon::ISimplygon* sg)
|
||||
{
|
||||
// Load scene to process.
|
||||
printf("%s\n", "Load scene to process.");
|
||||
Simplygon::spScene sgScene = LoadScene(sg, "../../../Assets/SimplygonMan/SimplygonMan.obj");
|
||||
|
||||
// Add tangents to the scene. Tangents are needed to cast the tangent-space normal maps, and the
|
||||
// input scene is missing tangents.
|
||||
Simplygon::spTangentCalculator sgTangentCalculator = sg->CreateTangentCalculator();
|
||||
sgTangentCalculator->CalculateTangentsOnScene(sgScene, true);
|
||||
|
||||
// Load scene material evaluation description, which will define all evaluation shaders for all
|
||||
// materials, as well as needed textures and custom buffers.
|
||||
printf("%s\n", "Load scene material evaluation description, which will define all evaluation shaders for all materials, as well as needed textures and custom buffers.");
|
||||
Simplygon::spMaterialEvaluationShaderSerializer sgMaterialEvaluationShaderSerializer = sg->CreateMaterialEvaluationShaderSerializer();
|
||||
sgMaterialEvaluationShaderSerializer->LoadSceneMaterialEvaluationShadersFromFile("SimplygonManCasting.xml", sgScene);
|
||||
|
||||
// Create the aggregation processor.
|
||||
Simplygon::spAggregationProcessor sgAggregationProcessor = sg->CreateAggregationProcessor();
|
||||
sgAggregationProcessor->SetScene( sgScene );
|
||||
Simplygon::spAggregationSettings sgAggregationSettings = sgAggregationProcessor->GetAggregationSettings();
|
||||
Simplygon::spMappingImageSettings sgMappingImageSettings = sgAggregationProcessor->GetMappingImageSettings();
|
||||
|
||||
// Merge all geometries into a single geometry.
|
||||
sgAggregationSettings->SetMergeGeometries( true );
|
||||
|
||||
// Generates a mapping image which is used after the aggregation to cast new materials to the new
|
||||
// aggregated object.
|
||||
sgMappingImageSettings->SetGenerateMappingImage( true );
|
||||
sgMappingImageSettings->SetApplyNewMaterialIds( true );
|
||||
sgMappingImageSettings->SetGenerateTangents( true );
|
||||
sgMappingImageSettings->SetUseFullRetexturing( true );
|
||||
Simplygon::spMappingImageOutputMaterialSettings sgOutputMaterialSettings = sgMappingImageSettings->GetOutputMaterialSettings(0);
|
||||
|
||||
// Setting the size of the output material for the mapping image. This will be the output size of the
|
||||
// textures when we do material casting in a later stage.
|
||||
sgOutputMaterialSettings->SetTextureWidth( 2048 );
|
||||
sgOutputMaterialSettings->SetTextureHeight( 2048 );
|
||||
|
||||
// Start the aggregation process.
|
||||
printf("%s\n", "Start the aggregation process.");
|
||||
sgAggregationProcessor->RunProcessing();
|
||||
|
||||
// Setup and run the compute caster on the diffuse channel.
|
||||
printf("%s\n", "Setup and run the compute caster on the diffuse channel.");
|
||||
Simplygon::spComputeCaster sgDiffuseCaster = sg->CreateComputeCaster();
|
||||
sgDiffuseCaster->SetMappingImage( sgAggregationProcessor->GetMappingImage() );
|
||||
sgDiffuseCaster->SetSourceMaterials( sgScene->GetMaterialTable() );
|
||||
sgDiffuseCaster->SetSourceTextures( sgScene->GetTextureTable() );
|
||||
sgDiffuseCaster->SetOutputFilePath( "DiffuseTexture" );
|
||||
|
||||
Simplygon::spComputeCasterSettings sgDiffuseCasterSettings = sgDiffuseCaster->GetComputeCasterSettings();
|
||||
sgDiffuseCasterSettings->SetMaterialChannel( "Diffuse" );
|
||||
sgDiffuseCasterSettings->SetOutputImageFileFormat( Simplygon::EImageOutputFormat::PNG );
|
||||
|
||||
sgDiffuseCaster->RunProcessing();
|
||||
std::string diffuseTextureFilePath = sgDiffuseCaster->GetOutputFilePath().c_str();
|
||||
|
||||
// Setup and run another compute shader on the normals channel.
|
||||
printf("%s\n", "Setup and run another compute shader on the normals channel.");
|
||||
Simplygon::spComputeCaster sgNormalsCaster = sg->CreateComputeCaster();
|
||||
sgNormalsCaster->SetMappingImage( sgAggregationProcessor->GetMappingImage() );
|
||||
sgNormalsCaster->SetSourceMaterials( sgScene->GetMaterialTable() );
|
||||
sgNormalsCaster->SetSourceTextures( sgScene->GetTextureTable() );
|
||||
sgNormalsCaster->SetOutputFilePath( "NormalsTexture" );
|
||||
|
||||
Simplygon::spComputeCasterSettings sgNormalsCasterSettings = sgNormalsCaster->GetComputeCasterSettings();
|
||||
sgNormalsCasterSettings->SetMaterialChannel( "Normals" );
|
||||
sgNormalsCasterSettings->SetOutputImageFileFormat( Simplygon::EImageOutputFormat::PNG );
|
||||
|
||||
sgNormalsCaster->RunProcessing();
|
||||
std::string normalsTextureFilePath = sgNormalsCaster->GetOutputFilePath().c_str();
|
||||
|
||||
// Update scene with new casted texture.
|
||||
Simplygon::spMaterialTable sgMaterialTable = sg->CreateMaterialTable();
|
||||
Simplygon::spTextureTable sgTextureTable = sg->CreateTextureTable();
|
||||
Simplygon::spMaterial sgMaterial = sg->CreateMaterial();
|
||||
Simplygon::spTexture sgDiffuseTexture = sg->CreateTexture();
|
||||
sgDiffuseTexture->SetName( "Diffuse" );
|
||||
sgDiffuseTexture->SetFilePath( diffuseTextureFilePath.c_str() );
|
||||
sgTextureTable->AddTexture( sgDiffuseTexture );
|
||||
|
||||
Simplygon::spShadingTextureNode sgDiffuseTextureShadingNode = sg->CreateShadingTextureNode();
|
||||
sgDiffuseTextureShadingNode->SetTexCoordLevel( 0 );
|
||||
sgDiffuseTextureShadingNode->SetTextureName( "Diffuse" );
|
||||
|
||||
sgMaterial->AddMaterialChannel( "Diffuse" );
|
||||
sgMaterial->SetShadingNetwork( "Diffuse", sgDiffuseTextureShadingNode );
|
||||
Simplygon::spTexture sgNormalsTexture = sg->CreateTexture();
|
||||
sgNormalsTexture->SetName( "Normals" );
|
||||
sgNormalsTexture->SetFilePath( normalsTextureFilePath.c_str() );
|
||||
sgTextureTable->AddTexture( sgNormalsTexture );
|
||||
|
||||
Simplygon::spShadingTextureNode sgNormalsTextureShadingNode = sg->CreateShadingTextureNode();
|
||||
sgNormalsTextureShadingNode->SetTexCoordLevel( 0 );
|
||||
sgNormalsTextureShadingNode->SetTextureName( "Normals" );
|
||||
|
||||
sgMaterial->AddMaterialChannel( "Normals" );
|
||||
sgMaterial->SetShadingNetwork( "Normals", sgNormalsTextureShadingNode );
|
||||
|
||||
sgMaterialTable->AddMaterial( sgMaterial );
|
||||
|
||||
sgScene->GetTextureTable()->Clear();
|
||||
sgScene->GetMaterialTable()->Clear();
|
||||
sgScene->GetTextureTable()->Copy(sgTextureTable);
|
||||
sgScene->GetMaterialTable()->Copy(sgMaterialTable);
|
||||
|
||||
// Save processed scene.
|
||||
printf("%s\n", "Save processed scene.");
|
||||
SaveScene(sg, sgScene, "Output.fbx");
|
||||
|
||||
// Check log for any warnings or errors.
|
||||
printf("%s\n", "Check log for any warnings or errors.");
|
||||
CheckLog(sg);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Simplygon::ISimplygon* sg = NULL;
|
||||
Simplygon::EErrorCodes initval = Simplygon::Initialize( &sg );
|
||||
if( initval != Simplygon::EErrorCodes::NoError )
|
||||
{
|
||||
printf( "Failed to initialize Simplygon: ErrorCode(%d)", (int)initval );
|
||||
return int(initval);
|
||||
}
|
||||
|
||||
ComputeCasting(sg);
|
||||
|
||||
Simplygon::Deinitialize(sg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{556BD124-D210-4084-905C-61DD97267C76}</ProjectGuid>
|
||||
<RootNamespace>ComputeCastingWithSceneDescription</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<OutDir>$(SolutionDir)ComputeCastingWithSceneDescription\</OutDir>
|
||||
<IntDir>$(SolutionDir)ComputeCastingWithSceneDescription\obj\</IntDir>
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<TargetExt>.exe</TargetExt>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<OutDir>$(SolutionDir)ComputeCastingWithSceneDescription\</OutDir>
|
||||
<IntDir>$(SolutionDir)ComputeCastingWithSceneDescription\obj\</IntDir>
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<TargetExt>.exe</TargetExt>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PreBuildEvent />
|
||||
<Midl>
|
||||
<TargetEnvironment>X64</TargetEnvironment>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(SIMPLYGON_10_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TargetMachine>MachineX64</TargetMachine>
|
||||
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<PostBuildEvent />
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<PreBuildEvent />
|
||||
<Midl>
|
||||
<TargetEnvironment>X64</TargetEnvironment>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(SIMPLYGON_10_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<EnablePREfast>false</EnablePREfast>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TargetMachine>MachineX64</TargetMachine>
|
||||
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<PostBuildEvent />
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(ProjectDir)ComputeCastingWithSceneDescription.cpp" />
|
||||
<ClCompile Include="$([System.Environment]::ExpandEnvironmentVariables($(SIMPLYGON_10_PATH)))\SimplygonLoader.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
// customStruct is the user-defined custom data structure which is bound to the "MaterialColorsCustomField" custom field
|
||||
// which is defined in the scene. The custom field is 160 bytes and is mapped to a StructuredBuffer of 8 entries, one
|
||||
// per material. Note that the "multiplier" value is not used in the example, and is there only to create a more complex
|
||||
// struct than a regular float4, which requires a specific struct definition in the header code.
|
||||
|
||||
struct customStruct
|
||||
{
|
||||
float4 color;
|
||||
float multiplier;
|
||||
};
|
Двоичные данные
Src/Cpp/ComputeCastingWithSceneDescription/MaterialColorsCustomField.bin
Normal file
Двоичные данные
Src/Cpp/ComputeCastingWithSceneDescription/MaterialColorsCustomField.bin
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,498 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- This is an example file which demos how you can perform a full casting on a non-textured scene, and add required buffers, textures etc in the xml file. -->
|
||||
|
||||
<Scene>
|
||||
|
||||
<!--
|
||||
The TextureTable is an easy way to add additional needed textures to the scene before running the compute caster
|
||||
There are some caveats to consider:
|
||||
- Any already existing texture with the same name will be replaced
|
||||
- Textures can only be referenced with a file path (relative or absolute)
|
||||
-->
|
||||
|
||||
<TextureTable>
|
||||
<Texture Name="0_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_arms_d.JPG"/>
|
||||
<Texture Name="1_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_armor_upper_d.JPG"/>
|
||||
<Texture Name="2_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_baselayer_d.JPG"/>
|
||||
<Texture Name="3_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_helmet_d.JPG"/>
|
||||
<Texture Name="4_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_helmet_d.JPG" />
|
||||
<Texture Name="5_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_visor_mask_d.JPG"/>
|
||||
<Texture Name="6_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_legs_logo2.0_d.JPG"/>
|
||||
<Texture Name="7_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_armor_middle_logo2_d.JPG"/>
|
||||
<Texture Name="0_Normals" FilePath="../../../Assets/SimplygonMan/dman_arms_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="1_Normals" FilePath="../../../Assets/SimplygonMan/dman_armor_upper_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="2_Normals" FilePath="../../../Assets/SimplygonMan/dman_baselayer_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="3_Normals" FilePath="../../../Assets/SimplygonMan/dman_helmet_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="4_Normals" FilePath="../../../Assets/SimplygonMan/dman_helmet_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="5_Normals" FilePath="../../../Assets/SimplygonMan/dman_visor_mask_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="6_Normals" FilePath="../../../Assets/SimplygonMan/dman_legs_logo2.0_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="7_Normals" FilePath="../../../Assets/SimplygonMan/dman_armor_middle_logo2_n.JPG" ColorSpace="Linear"/>
|
||||
</TextureTable>
|
||||
|
||||
<!--
|
||||
The CustomFields element lists any additional custom fields which should be added to the Scene (as AddCustomField).
|
||||
Note that since the user is responsible for alignment and packing, all fields are added as UnsignedCharArrays, with
|
||||
a tuple size of 1.
|
||||
|
||||
Fields can either reference external files, as shown below (MaterialColorsCustomField.bin), or be embedded in the .xml
|
||||
as a base64 encoded field.
|
||||
|
||||
In the example field below, we encode one 20 byte struct per material, so the input .bin file is 8 * 20 = 160 bytes
|
||||
-->
|
||||
|
||||
<CustomFields>
|
||||
<CustomField Name="MaterialColorsCustomField" FilePath="MaterialColorsCustomField.bin"/>
|
||||
</CustomFields>
|
||||
|
||||
<!--
|
||||
The MaterialTable specifies a MaterialEvaluationShader per Material. Note that the materials must already exist in the scene's
|
||||
material table, since the geometry material ids drive the actual material casting. However, each Material do not need to be
|
||||
represented, as each scene descriptor file adds to the current scene, so there can be one file for all materials which
|
||||
are to be cast, one file for each material, or some other combination, as long as all materials are set up before casting.
|
||||
-->
|
||||
|
||||
<MaterialTable>
|
||||
<Material Name="armsSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="0_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="0_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="body_upperSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="1_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="1_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="clothSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="2_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="2_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmetSG">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="3_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="3_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmetSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="4_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="4_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmet_visorSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="5_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="5_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="legsSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="6_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="6_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="middleSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="7_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="7_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
</MaterialTable>
|
||||
|
||||
</Scene>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
// The CalculateDiffuseChannel function samples from the CastingTexturesArray, index 0, which is the diffuse map bound to this evaluation shader.
|
||||
// The function also blends the result with the color value from the CustomBuffer buffer, which is a custom field in the scene (added by the
|
||||
// scene descriptor .xml file) and which has a 20-byte struct per-material. The function uses the built-in sg_MaterialIdFilter value to do
|
||||
// the lookup into the buffer.
|
||||
|
||||
float4 CalculateDiffuseChannel()
|
||||
{
|
||||
// sample the texture from the CastingTexturesArray[0] using the bound DiffuseSampler sampler
|
||||
float4 colorValue = CastingTexturesArray[0].SampleLevel( DiffuseSampler , TexCoord , 0 ) * 0.7f;
|
||||
|
||||
// blend with the custom value from the CustomBuffer, which is of type customStruct, and is defined in "HeaderCode.hlsl"
|
||||
colorValue += CustomBuffer[sg_MaterialIdFilter].color * 0.3f;
|
||||
|
||||
// return the blended color value
|
||||
return colorValue;
|
||||
}
|
||||
|
||||
// The CalculateNormalsChannel calculates the per-texel normals of the output tangent-space normal map. It starts by sampling the input
|
||||
// tangent-space normal map of the input geometry, and transforms the normal into object-space coordinates. It then uses the generated
|
||||
// destination tangent basis vectors to transform the normal vector into the output tangent-space.
|
||||
|
||||
float4 CalculateNormalsChannel()
|
||||
{
|
||||
// sample the input tangent-space texture, and decode into [-1 -> 1] basis
|
||||
float3 tangentSpaceNormal = (CastingTexturesArray[1].SampleLevel( NormalSampler , TexCoord , 0 ).xyz * 2.0) - 1.0;
|
||||
|
||||
// transform into an object-space vector
|
||||
float3 objectSpaceNormal = tangentSpaceNormal.x * normalize(Tangent) +
|
||||
tangentSpaceNormal.y * normalize(Bitangent) +
|
||||
tangentSpaceNormal.z * normalize(Normal);
|
||||
|
||||
// transform the object-space vector into the destination tangent space
|
||||
tangentSpaceNormal.x = dot( objectSpaceNormal , normalize(sg_DestinationTangent) );
|
||||
tangentSpaceNormal.y = dot( objectSpaceNormal , normalize(sg_DestinationBitangent) );
|
||||
tangentSpaceNormal.z = dot( objectSpaceNormal , normalize(sg_DestinationNormal) );
|
||||
|
||||
// normalize, the tangent basis is not necessarily orthogonal
|
||||
tangentSpaceNormal = normalize(tangentSpaceNormal);
|
||||
|
||||
// encode into [0 -> 1] basis and return
|
||||
return float4( ((tangentSpaceNormal + 1.0)/2.0) , 1.0);
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class Program
|
||||
{
|
||||
static Simplygon.spScene LoadScene(Simplygon.ISimplygon sg, string path)
|
||||
{
|
||||
// Create scene importer
|
||||
using Simplygon.spSceneImporter sgSceneImporter = sg.CreateSceneImporter();
|
||||
sgSceneImporter.SetImportFilePath(path);
|
||||
|
||||
// Run scene importer.
|
||||
var importResult = sgSceneImporter.Run();
|
||||
if (Simplygon.Simplygon.Failed(importResult))
|
||||
{
|
||||
throw new System.Exception("Failed to load scene.");
|
||||
}
|
||||
Simplygon.spScene sgScene = sgSceneImporter.GetScene();
|
||||
return sgScene;
|
||||
}
|
||||
|
||||
static void SaveScene(Simplygon.ISimplygon sg, Simplygon.spScene sgScene, string path)
|
||||
{
|
||||
// Create scene exporter.
|
||||
using Simplygon.spSceneExporter sgSceneExporter = sg.CreateSceneExporter();
|
||||
string outputScenePath = string.Join("", new string[] { "output\\", "ComputeCastingWithSceneDescription", "_", path });
|
||||
sgSceneExporter.SetExportFilePath(outputScenePath);
|
||||
sgSceneExporter.SetScene(sgScene);
|
||||
|
||||
// Run scene exporter.
|
||||
var exportResult = sgSceneExporter.Run();
|
||||
if (Simplygon.Simplygon.Failed(exportResult))
|
||||
{
|
||||
throw new System.Exception("Failed to save scene.");
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckLog(Simplygon.ISimplygon sg)
|
||||
{
|
||||
// Check if any errors occurred.
|
||||
bool hasErrors = sg.ErrorOccurred();
|
||||
if (hasErrors)
|
||||
{
|
||||
Simplygon.spStringArray errors = sg.CreateStringArray();
|
||||
sg.GetErrorMessages(errors);
|
||||
var errorCount = errors.GetItemCount();
|
||||
if (errorCount > 0)
|
||||
{
|
||||
Console.WriteLine("Errors:");
|
||||
for (uint errorIndex = 0; errorIndex < errorCount; ++errorIndex)
|
||||
{
|
||||
string errorString = errors.GetItem((int)errorIndex);
|
||||
Console.WriteLine(errorString);
|
||||
}
|
||||
sg.ClearErrorMessages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No errors.");
|
||||
}
|
||||
|
||||
// Check if any warnings occurred.
|
||||
bool hasWarnings = sg.WarningOccurred();
|
||||
if (hasWarnings)
|
||||
{
|
||||
Simplygon.spStringArray warnings = sg.CreateStringArray();
|
||||
sg.GetWarningMessages(warnings);
|
||||
var warningCount = warnings.GetItemCount();
|
||||
if (warningCount > 0)
|
||||
{
|
||||
Console.WriteLine("Warnings:");
|
||||
for (uint warningIndex = 0; warningIndex < warningCount; ++warningIndex)
|
||||
{
|
||||
string warningString = warnings.GetItem((int)warningIndex);
|
||||
Console.WriteLine(warningString);
|
||||
}
|
||||
sg.ClearWarningMessages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No warnings.");
|
||||
}
|
||||
|
||||
// Error out if Simplygon has errors.
|
||||
if (hasErrors)
|
||||
{
|
||||
throw new System.Exception("Processing failed with an error");
|
||||
}
|
||||
}
|
||||
|
||||
static void ComputeCasting(Simplygon.ISimplygon sg)
|
||||
{
|
||||
// Load scene to process.
|
||||
Console.WriteLine("Load scene to process.");
|
||||
Simplygon.spScene sgScene = LoadScene(sg, "../../../Assets/SimplygonMan/SimplygonMan.obj");
|
||||
|
||||
// Add tangents to the scene. Tangents are needed to cast the tangent-space normal maps, and the
|
||||
// input scene is missing tangents.
|
||||
using Simplygon.spTangentCalculator sgTangentCalculator = sg.CreateTangentCalculator();
|
||||
sgTangentCalculator.CalculateTangentsOnScene(sgScene, true);
|
||||
|
||||
// Load scene material evaluation description, which will define all evaluation shaders for all
|
||||
// materials, as well as needed textures and custom buffers.
|
||||
Console.WriteLine("Load scene material evaluation description, which will define all evaluation shaders for all materials, as well as needed textures and custom buffers.");
|
||||
using Simplygon.spMaterialEvaluationShaderSerializer sgMaterialEvaluationShaderSerializer = sg.CreateMaterialEvaluationShaderSerializer();
|
||||
sgMaterialEvaluationShaderSerializer.LoadSceneMaterialEvaluationShadersFromFile("SimplygonManCasting.xml", sgScene);
|
||||
|
||||
// Create the aggregation processor.
|
||||
using Simplygon.spAggregationProcessor sgAggregationProcessor = sg.CreateAggregationProcessor();
|
||||
sgAggregationProcessor.SetScene( sgScene );
|
||||
using Simplygon.spAggregationSettings sgAggregationSettings = sgAggregationProcessor.GetAggregationSettings();
|
||||
using Simplygon.spMappingImageSettings sgMappingImageSettings = sgAggregationProcessor.GetMappingImageSettings();
|
||||
|
||||
// Merge all geometries into a single geometry.
|
||||
sgAggregationSettings.SetMergeGeometries( true );
|
||||
|
||||
// Generates a mapping image which is used after the aggregation to cast new materials to the new
|
||||
// aggregated object.
|
||||
sgMappingImageSettings.SetGenerateMappingImage( true );
|
||||
sgMappingImageSettings.SetApplyNewMaterialIds( true );
|
||||
sgMappingImageSettings.SetGenerateTangents( true );
|
||||
sgMappingImageSettings.SetUseFullRetexturing( true );
|
||||
using Simplygon.spMappingImageOutputMaterialSettings sgOutputMaterialSettings = sgMappingImageSettings.GetOutputMaterialSettings(0);
|
||||
|
||||
// Setting the size of the output material for the mapping image. This will be the output size of the
|
||||
// textures when we do material casting in a later stage.
|
||||
sgOutputMaterialSettings.SetTextureWidth( 2048 );
|
||||
sgOutputMaterialSettings.SetTextureHeight( 2048 );
|
||||
|
||||
// Start the aggregation process.
|
||||
Console.WriteLine("Start the aggregation process.");
|
||||
sgAggregationProcessor.RunProcessing();
|
||||
|
||||
// Setup and run the compute caster on the diffuse channel.
|
||||
Console.WriteLine("Setup and run the compute caster on the diffuse channel.");
|
||||
string diffuseTextureFilePath;
|
||||
using Simplygon.spComputeCaster sgDiffuseCaster = sg.CreateComputeCaster();
|
||||
sgDiffuseCaster.SetMappingImage( sgAggregationProcessor.GetMappingImage() );
|
||||
sgDiffuseCaster.SetSourceMaterials( sgScene.GetMaterialTable() );
|
||||
sgDiffuseCaster.SetSourceTextures( sgScene.GetTextureTable() );
|
||||
sgDiffuseCaster.SetOutputFilePath( "DiffuseTexture" );
|
||||
|
||||
using Simplygon.spComputeCasterSettings sgDiffuseCasterSettings = sgDiffuseCaster.GetComputeCasterSettings();
|
||||
sgDiffuseCasterSettings.SetMaterialChannel( "Diffuse" );
|
||||
sgDiffuseCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat.PNG );
|
||||
|
||||
sgDiffuseCaster.RunProcessing();
|
||||
diffuseTextureFilePath = sgDiffuseCaster.GetOutputFilePath();
|
||||
|
||||
// Setup and run another compute shader on the normals channel.
|
||||
Console.WriteLine("Setup and run another compute shader on the normals channel.");
|
||||
string normalsTextureFilePath;
|
||||
using Simplygon.spComputeCaster sgNormalsCaster = sg.CreateComputeCaster();
|
||||
sgNormalsCaster.SetMappingImage( sgAggregationProcessor.GetMappingImage() );
|
||||
sgNormalsCaster.SetSourceMaterials( sgScene.GetMaterialTable() );
|
||||
sgNormalsCaster.SetSourceTextures( sgScene.GetTextureTable() );
|
||||
sgNormalsCaster.SetOutputFilePath( "NormalsTexture" );
|
||||
|
||||
using Simplygon.spComputeCasterSettings sgNormalsCasterSettings = sgNormalsCaster.GetComputeCasterSettings();
|
||||
sgNormalsCasterSettings.SetMaterialChannel( "Normals" );
|
||||
sgNormalsCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat.PNG );
|
||||
|
||||
sgNormalsCaster.RunProcessing();
|
||||
normalsTextureFilePath = sgNormalsCaster.GetOutputFilePath();
|
||||
|
||||
// Update scene with new casted texture.
|
||||
using Simplygon.spMaterialTable sgMaterialTable = sg.CreateMaterialTable();
|
||||
using Simplygon.spTextureTable sgTextureTable = sg.CreateTextureTable();
|
||||
using Simplygon.spMaterial sgMaterial = sg.CreateMaterial();
|
||||
using Simplygon.spTexture sgDiffuseTexture = sg.CreateTexture();
|
||||
sgDiffuseTexture.SetName( "Diffuse" );
|
||||
sgDiffuseTexture.SetFilePath( diffuseTextureFilePath );
|
||||
sgTextureTable.AddTexture( sgDiffuseTexture );
|
||||
|
||||
using Simplygon.spShadingTextureNode sgDiffuseTextureShadingNode = sg.CreateShadingTextureNode();
|
||||
sgDiffuseTextureShadingNode.SetTexCoordLevel( 0 );
|
||||
sgDiffuseTextureShadingNode.SetTextureName( "Diffuse" );
|
||||
|
||||
sgMaterial.AddMaterialChannel( "Diffuse" );
|
||||
sgMaterial.SetShadingNetwork( "Diffuse", sgDiffuseTextureShadingNode );
|
||||
using Simplygon.spTexture sgNormalsTexture = sg.CreateTexture();
|
||||
sgNormalsTexture.SetName( "Normals" );
|
||||
sgNormalsTexture.SetFilePath( normalsTextureFilePath );
|
||||
sgTextureTable.AddTexture( sgNormalsTexture );
|
||||
|
||||
using Simplygon.spShadingTextureNode sgNormalsTextureShadingNode = sg.CreateShadingTextureNode();
|
||||
sgNormalsTextureShadingNode.SetTexCoordLevel( 0 );
|
||||
sgNormalsTextureShadingNode.SetTextureName( "Normals" );
|
||||
|
||||
sgMaterial.AddMaterialChannel( "Normals" );
|
||||
sgMaterial.SetShadingNetwork( "Normals", sgNormalsTextureShadingNode );
|
||||
|
||||
sgMaterialTable.AddMaterial( sgMaterial );
|
||||
|
||||
sgScene.GetTextureTable().Clear();
|
||||
sgScene.GetMaterialTable().Clear();
|
||||
sgScene.GetTextureTable().Copy(sgTextureTable);
|
||||
sgScene.GetMaterialTable().Copy(sgMaterialTable);
|
||||
|
||||
// Save processed scene.
|
||||
Console.WriteLine("Save processed scene.");
|
||||
SaveScene(sg, sgScene, "Output.fbx");
|
||||
|
||||
// Check log for any warnings or errors.
|
||||
Console.WriteLine("Check log for any warnings or errors.");
|
||||
CheckLog(sg);
|
||||
}
|
||||
|
||||
static int Main(string[] args)
|
||||
{
|
||||
using var sg = Simplygon.Loader.InitSimplygon(out var errorCode, out var errorMessage);
|
||||
if (errorCode != Simplygon.EErrorCodes.NoError)
|
||||
{
|
||||
Console.WriteLine( $"Failed to initialize Simplygon: ErrorCode({(int)errorCode}) {errorMessage}" );
|
||||
return (int)errorCode;
|
||||
}
|
||||
ComputeCasting(sg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<OutputPath>.\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<OutputPath>.\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ProjectGuid>{556BD124-D210-4084-905C-61DD97267C76}</ProjectGuid>
|
||||
<RootNamespace>ComputeCastingWithSceneDescription</RootNamespace>
|
||||
<AssemblyName>ComputeCastingWithSceneDescription</AssemblyName>
|
||||
<TargetFrameworkVersion>4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<Platform>x64</Platform>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SimplygonDotNetWrapper">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>$([System.Environment]::ExpandEnvironmentVariables($(SIMPLYGON_10_PATH)))\SimplygonDotNetWrapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$([System.Environment]::ExpandEnvironmentVariables($(SIMPLYGON_10_PATH)))\DotNet\SimplygonLoader.cs">
|
||||
<Link>SimplygonLoader.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="ComputeCastingWithSceneDescription.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
// customStruct is the user-defined custom data structure which is bound to the "MaterialColorsCustomField" custom field
|
||||
// which is defined in the scene. The custom field is 160 bytes and is mapped to a StructuredBuffer of 8 entries, one
|
||||
// per material. Note that the "multiplier" value is not used in the example, and is there only to create a more complex
|
||||
// struct than a regular float4, which requires a specific struct definition in the header code.
|
||||
|
||||
struct customStruct
|
||||
{
|
||||
float4 color;
|
||||
float multiplier;
|
||||
};
|
Двоичный файл не отображается.
|
@ -0,0 +1,19 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("ComputeCastingWithSceneDescription")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ComputeCastingWithSceneDescription")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("556BD124-D210-4084-905C-61DD97267C76")]
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,498 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- This is an example file which demos how you can perform a full casting on a non-textured scene, and add required buffers, textures etc in the xml file. -->
|
||||
|
||||
<Scene>
|
||||
|
||||
<!--
|
||||
The TextureTable is an easy way to add additional needed textures to the scene before running the compute caster
|
||||
There are some caveats to consider:
|
||||
- Any already existing texture with the same name will be replaced
|
||||
- Textures can only be referenced with a file path (relative or absolute)
|
||||
-->
|
||||
|
||||
<TextureTable>
|
||||
<Texture Name="0_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_arms_d.JPG"/>
|
||||
<Texture Name="1_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_armor_upper_d.JPG"/>
|
||||
<Texture Name="2_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_baselayer_d.JPG"/>
|
||||
<Texture Name="3_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_helmet_d.JPG"/>
|
||||
<Texture Name="4_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_helmet_d.JPG" />
|
||||
<Texture Name="5_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_visor_mask_d.JPG"/>
|
||||
<Texture Name="6_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_legs_logo2.0_d.JPG"/>
|
||||
<Texture Name="7_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_armor_middle_logo2_d.JPG"/>
|
||||
<Texture Name="0_Normals" FilePath="../../../Assets/SimplygonMan/dman_arms_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="1_Normals" FilePath="../../../Assets/SimplygonMan/dman_armor_upper_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="2_Normals" FilePath="../../../Assets/SimplygonMan/dman_baselayer_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="3_Normals" FilePath="../../../Assets/SimplygonMan/dman_helmet_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="4_Normals" FilePath="../../../Assets/SimplygonMan/dman_helmet_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="5_Normals" FilePath="../../../Assets/SimplygonMan/dman_visor_mask_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="6_Normals" FilePath="../../../Assets/SimplygonMan/dman_legs_logo2.0_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="7_Normals" FilePath="../../../Assets/SimplygonMan/dman_armor_middle_logo2_n.JPG" ColorSpace="Linear"/>
|
||||
</TextureTable>
|
||||
|
||||
<!--
|
||||
The CustomFields element lists any additional custom fields which should be added to the Scene (as AddCustomField).
|
||||
Note that since the user is responsible for alignment and packing, all fields are added as UnsignedCharArrays, with
|
||||
a tuple size of 1.
|
||||
|
||||
Fields can either reference external files, as shown below (MaterialColorsCustomField.bin), or be embedded in the .xml
|
||||
as a base64 encoded field.
|
||||
|
||||
In the example field below, we encode one 20 byte struct per material, so the input .bin file is 8 * 20 = 160 bytes
|
||||
-->
|
||||
|
||||
<CustomFields>
|
||||
<CustomField Name="MaterialColorsCustomField" FilePath="MaterialColorsCustomField.bin"/>
|
||||
</CustomFields>
|
||||
|
||||
<!--
|
||||
The MaterialTable specifies a MaterialEvaluationShader per Material. Note that the materials must already exist in the scene's
|
||||
material table, since the geometry material ids drive the actual material casting. However, each Material do not need to be
|
||||
represented, as each scene descriptor file adds to the current scene, so there can be one file for all materials which
|
||||
are to be cast, one file for each material, or some other combination, as long as all materials are set up before casting.
|
||||
-->
|
||||
|
||||
<MaterialTable>
|
||||
<Material Name="armsSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="0_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="0_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="body_upperSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="1_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="1_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="clothSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="2_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="2_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmetSG">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="3_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="3_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmetSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="4_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="4_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmet_visorSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="5_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="5_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="legsSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="6_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="6_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="middleSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="7_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="7_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
</MaterialTable>
|
||||
|
||||
</Scene>
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
// The CalculateDiffuseChannel function samples from the CastingTexturesArray, index 0, which is the diffuse map bound to this evaluation shader.
|
||||
// The function also blends the result with the color value from the CustomBuffer buffer, which is a custom field in the scene (added by the
|
||||
// scene descriptor .xml file) and which has a 20-byte struct per-material. The function uses the built-in sg_MaterialIdFilter value to do
|
||||
// the lookup into the buffer.
|
||||
|
||||
float4 CalculateDiffuseChannel()
|
||||
{
|
||||
// sample the texture from the CastingTexturesArray[0] using the bound DiffuseSampler sampler
|
||||
float4 colorValue = CastingTexturesArray[0].SampleLevel( DiffuseSampler , TexCoord , 0 ) * 0.7f;
|
||||
|
||||
// blend with the custom value from the CustomBuffer, which is of type customStruct, and is defined in "HeaderCode.hlsl"
|
||||
colorValue += CustomBuffer[sg_MaterialIdFilter].color * 0.3f;
|
||||
|
||||
// return the blended color value
|
||||
return colorValue;
|
||||
}
|
||||
|
||||
// The CalculateNormalsChannel calculates the per-texel normals of the output tangent-space normal map. It starts by sampling the input
|
||||
// tangent-space normal map of the input geometry, and transforms the normal into object-space coordinates. It then uses the generated
|
||||
// destination tangent basis vectors to transform the normal vector into the output tangent-space.
|
||||
|
||||
float4 CalculateNormalsChannel()
|
||||
{
|
||||
// sample the input tangent-space texture, and decode into [-1 -> 1] basis
|
||||
float3 tangentSpaceNormal = (CastingTexturesArray[1].SampleLevel( NormalSampler , TexCoord , 0 ).xyz * 2.0) - 1.0;
|
||||
|
||||
// transform into an object-space vector
|
||||
float3 objectSpaceNormal = tangentSpaceNormal.x * normalize(Tangent) +
|
||||
tangentSpaceNormal.y * normalize(Bitangent) +
|
||||
tangentSpaceNormal.z * normalize(Normal);
|
||||
|
||||
// transform the object-space vector into the destination tangent space
|
||||
tangentSpaceNormal.x = dot( objectSpaceNormal , normalize(sg_DestinationTangent) );
|
||||
tangentSpaceNormal.y = dot( objectSpaceNormal , normalize(sg_DestinationBitangent) );
|
||||
tangentSpaceNormal.z = dot( objectSpaceNormal , normalize(sg_DestinationNormal) );
|
||||
|
||||
// normalize, the tangent basis is not necessarily orthogonal
|
||||
tangentSpaceNormal = normalize(tangentSpaceNormal);
|
||||
|
||||
// encode into [0 -> 1] basis and return
|
||||
return float4( ((tangentSpaceNormal + 1.0)/2.0) , 1.0);
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
import gc
|
||||
import threading
|
||||
|
||||
from pathlib import Path
|
||||
from simplygon10 import simplygon_loader
|
||||
from simplygon10 import Simplygon
|
||||
|
||||
|
||||
def LoadScene(sg: Simplygon.ISimplygon, path: str):
|
||||
# Create scene importer
|
||||
sgSceneImporter = sg.CreateSceneImporter()
|
||||
sgSceneImporter.SetImportFilePath(path)
|
||||
|
||||
# Run scene importer.
|
||||
importResult = sgSceneImporter.Run()
|
||||
if Simplygon.Failed(importResult):
|
||||
raise Exception('Failed to load scene.')
|
||||
sgScene = sgSceneImporter.GetScene()
|
||||
return sgScene
|
||||
|
||||
def SaveScene(sg: Simplygon.ISimplygon, sgScene: Simplygon.spScene, path: str):
|
||||
# Create scene exporter.
|
||||
sgSceneExporter = sg.CreateSceneExporter()
|
||||
outputScenePath = ''.join(['output\\', 'ComputeCastingWithSceneDescription', '_', path])
|
||||
sgSceneExporter.SetExportFilePath(outputScenePath)
|
||||
sgSceneExporter.SetScene(sgScene)
|
||||
|
||||
# Run scene exporter.
|
||||
exportResult = sgSceneExporter.Run()
|
||||
if Simplygon.Failed(exportResult):
|
||||
raise Exception('Failed to save scene.')
|
||||
|
||||
def CheckLog(sg: Simplygon.ISimplygon):
|
||||
# Check if any errors occurred.
|
||||
hasErrors = sg.ErrorOccurred()
|
||||
if hasErrors:
|
||||
errors = sg.CreateStringArray()
|
||||
sg.GetErrorMessages(errors)
|
||||
errorCount = errors.GetItemCount()
|
||||
if errorCount > 0:
|
||||
print('Errors:')
|
||||
for errorIndex in range(errorCount):
|
||||
errorString = errors.GetItem(errorIndex)
|
||||
print(errorString)
|
||||
sg.ClearErrorMessages()
|
||||
else:
|
||||
print('No errors.')
|
||||
|
||||
# Check if any warnings occurred.
|
||||
hasWarnings = sg.WarningOccurred()
|
||||
if hasWarnings:
|
||||
warnings = sg.CreateStringArray()
|
||||
sg.GetWarningMessages(warnings)
|
||||
warningCount = warnings.GetItemCount()
|
||||
if warningCount > 0:
|
||||
print('Warnings:')
|
||||
for warningIndex in range(warningCount):
|
||||
warningString = warnings.GetItem(warningIndex)
|
||||
print(warningString)
|
||||
sg.ClearWarningMessages()
|
||||
else:
|
||||
print('No warnings.')
|
||||
|
||||
# Error out if Simplygon has errors.
|
||||
if hasErrors:
|
||||
raise Exception('Processing failed with an error')
|
||||
|
||||
def ComputeCasting(sg: Simplygon.ISimplygon):
|
||||
# Load scene to process.
|
||||
print("Load scene to process.")
|
||||
sgScene = LoadScene(sg, '../../../Assets/SimplygonMan/SimplygonMan.obj')
|
||||
|
||||
# Add tangents to the scene. Tangents are needed to cast the tangent-space normal maps, and the
|
||||
# input scene is missing tangents.
|
||||
sgTangentCalculator = sg.CreateTangentCalculator()
|
||||
sgTangentCalculator.CalculateTangentsOnScene(sgScene, True)
|
||||
|
||||
# Load scene material evaluation description, which will define all evaluation shaders for all
|
||||
# materials, as well as needed textures and custom buffers.
|
||||
print("Load scene material evaluation description, which will define all evaluation shaders for all materials, as well as needed textures and custom buffers.")
|
||||
sgMaterialEvaluationShaderSerializer = sg.CreateMaterialEvaluationShaderSerializer()
|
||||
sgMaterialEvaluationShaderSerializer.LoadSceneMaterialEvaluationShadersFromFile('SimplygonManCasting.xml', sgScene)
|
||||
|
||||
# Create the aggregation processor.
|
||||
sgAggregationProcessor = sg.CreateAggregationProcessor()
|
||||
sgAggregationProcessor.SetScene( sgScene )
|
||||
sgAggregationSettings = sgAggregationProcessor.GetAggregationSettings()
|
||||
sgMappingImageSettings = sgAggregationProcessor.GetMappingImageSettings()
|
||||
|
||||
# Merge all geometries into a single geometry.
|
||||
sgAggregationSettings.SetMergeGeometries( True )
|
||||
|
||||
# Generates a mapping image which is used after the aggregation to cast new materials to the new
|
||||
# aggregated object.
|
||||
sgMappingImageSettings.SetGenerateMappingImage( True )
|
||||
sgMappingImageSettings.SetApplyNewMaterialIds( True )
|
||||
sgMappingImageSettings.SetGenerateTangents( True )
|
||||
sgMappingImageSettings.SetUseFullRetexturing( True )
|
||||
sgOutputMaterialSettings = sgMappingImageSettings.GetOutputMaterialSettings(0)
|
||||
|
||||
# Setting the size of the output material for the mapping image. This will be the output size of the
|
||||
# textures when we do material casting in a later stage.
|
||||
sgOutputMaterialSettings.SetTextureWidth( 2048 )
|
||||
sgOutputMaterialSettings.SetTextureHeight( 2048 )
|
||||
|
||||
# Start the aggregation process.
|
||||
print("Start the aggregation process.")
|
||||
sgAggregationProcessor.RunProcessing()
|
||||
|
||||
# Setup and run the compute caster on the diffuse channel.
|
||||
print("Setup and run the compute caster on the diffuse channel.")
|
||||
sgDiffuseCaster = sg.CreateComputeCaster()
|
||||
sgDiffuseCaster.SetMappingImage( sgAggregationProcessor.GetMappingImage() )
|
||||
sgDiffuseCaster.SetSourceMaterials( sgScene.GetMaterialTable() )
|
||||
sgDiffuseCaster.SetSourceTextures( sgScene.GetTextureTable() )
|
||||
sgDiffuseCaster.SetOutputFilePath( 'DiffuseTexture' )
|
||||
|
||||
sgDiffuseCasterSettings = sgDiffuseCaster.GetComputeCasterSettings()
|
||||
sgDiffuseCasterSettings.SetMaterialChannel( 'Diffuse' )
|
||||
sgDiffuseCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat_PNG )
|
||||
|
||||
sgDiffuseCaster.RunProcessing()
|
||||
diffuseTextureFilePath = sgDiffuseCaster.GetOutputFilePath()
|
||||
|
||||
# Setup and run another compute shader on the normals channel.
|
||||
print("Setup and run another compute shader on the normals channel.")
|
||||
sgNormalsCaster = sg.CreateComputeCaster()
|
||||
sgNormalsCaster.SetMappingImage( sgAggregationProcessor.GetMappingImage() )
|
||||
sgNormalsCaster.SetSourceMaterials( sgScene.GetMaterialTable() )
|
||||
sgNormalsCaster.SetSourceTextures( sgScene.GetTextureTable() )
|
||||
sgNormalsCaster.SetOutputFilePath( 'NormalsTexture' )
|
||||
|
||||
sgNormalsCasterSettings = sgNormalsCaster.GetComputeCasterSettings()
|
||||
sgNormalsCasterSettings.SetMaterialChannel( 'Normals' )
|
||||
sgNormalsCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat_PNG )
|
||||
|
||||
sgNormalsCaster.RunProcessing()
|
||||
normalsTextureFilePath = sgNormalsCaster.GetOutputFilePath()
|
||||
|
||||
# Update scene with new casted texture.
|
||||
sgMaterialTable = sg.CreateMaterialTable()
|
||||
sgTextureTable = sg.CreateTextureTable()
|
||||
sgMaterial = sg.CreateMaterial()
|
||||
sgDiffuseTexture = sg.CreateTexture()
|
||||
sgDiffuseTexture.SetName( 'Diffuse' )
|
||||
sgDiffuseTexture.SetFilePath( diffuseTextureFilePath )
|
||||
sgTextureTable.AddTexture( sgDiffuseTexture )
|
||||
|
||||
sgDiffuseTextureShadingNode = sg.CreateShadingTextureNode()
|
||||
sgDiffuseTextureShadingNode.SetTexCoordLevel( 0 )
|
||||
sgDiffuseTextureShadingNode.SetTextureName( 'Diffuse' )
|
||||
|
||||
sgMaterial.AddMaterialChannel( 'Diffuse' )
|
||||
sgMaterial.SetShadingNetwork( 'Diffuse', sgDiffuseTextureShadingNode )
|
||||
sgNormalsTexture = sg.CreateTexture()
|
||||
sgNormalsTexture.SetName( 'Normals' )
|
||||
sgNormalsTexture.SetFilePath( normalsTextureFilePath )
|
||||
sgTextureTable.AddTexture( sgNormalsTexture )
|
||||
|
||||
sgNormalsTextureShadingNode = sg.CreateShadingTextureNode()
|
||||
sgNormalsTextureShadingNode.SetTexCoordLevel( 0 )
|
||||
sgNormalsTextureShadingNode.SetTextureName( 'Normals' )
|
||||
|
||||
sgMaterial.AddMaterialChannel( 'Normals' )
|
||||
sgMaterial.SetShadingNetwork( 'Normals', sgNormalsTextureShadingNode )
|
||||
|
||||
sgMaterialTable.AddMaterial( sgMaterial )
|
||||
|
||||
sgScene.GetTextureTable().Clear()
|
||||
sgScene.GetMaterialTable().Clear()
|
||||
sgScene.GetTextureTable().Copy(sgTextureTable)
|
||||
sgScene.GetMaterialTable().Copy(sgMaterialTable)
|
||||
|
||||
# Save processed scene.
|
||||
print("Save processed scene.")
|
||||
SaveScene(sg, sgScene, 'Output.fbx')
|
||||
|
||||
# Check log for any warnings or errors.
|
||||
print("Check log for any warnings or errors.")
|
||||
CheckLog(sg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sg = simplygon_loader.init_simplygon()
|
||||
if sg is None:
|
||||
exit(Simplygon.GetLastInitializationError())
|
||||
|
||||
ComputeCasting(sg)
|
||||
|
||||
sg = None
|
||||
gc.collect()
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
// customStruct is the user-defined custom data structure which is bound to the "MaterialColorsCustomField" custom field
|
||||
// which is defined in the scene. The custom field is 160 bytes and is mapped to a StructuredBuffer of 8 entries, one
|
||||
// per material. Note that the "multiplier" value is not used in the example, and is there only to create a more complex
|
||||
// struct than a regular float4, which requires a specific struct definition in the header code.
|
||||
|
||||
struct customStruct
|
||||
{
|
||||
float4 color;
|
||||
float multiplier;
|
||||
};
|
Двоичные данные
Src/Python/ComputeCastingWithSceneDescription/MaterialColorsCustomField.bin
Normal file
Двоичные данные
Src/Python/ComputeCastingWithSceneDescription/MaterialColorsCustomField.bin
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,498 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- This is an example file which demos how you can perform a full casting on a non-textured scene, and add required buffers, textures etc in the xml file. -->
|
||||
|
||||
<Scene>
|
||||
|
||||
<!--
|
||||
The TextureTable is an easy way to add additional needed textures to the scene before running the compute caster
|
||||
There are some caveats to consider:
|
||||
- Any already existing texture with the same name will be replaced
|
||||
- Textures can only be referenced with a file path (relative or absolute)
|
||||
-->
|
||||
|
||||
<TextureTable>
|
||||
<Texture Name="0_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_arms_d.JPG"/>
|
||||
<Texture Name="1_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_armor_upper_d.JPG"/>
|
||||
<Texture Name="2_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_baselayer_d.JPG"/>
|
||||
<Texture Name="3_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_helmet_d.JPG"/>
|
||||
<Texture Name="4_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_helmet_d.JPG" />
|
||||
<Texture Name="5_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_visor_mask_d.JPG"/>
|
||||
<Texture Name="6_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_legs_logo2.0_d.JPG"/>
|
||||
<Texture Name="7_Diffuse" FilePath="../../../Assets/SimplygonMan/dman_armor_middle_logo2_d.JPG"/>
|
||||
<Texture Name="0_Normals" FilePath="../../../Assets/SimplygonMan/dman_arms_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="1_Normals" FilePath="../../../Assets/SimplygonMan/dman_armor_upper_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="2_Normals" FilePath="../../../Assets/SimplygonMan/dman_baselayer_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="3_Normals" FilePath="../../../Assets/SimplygonMan/dman_helmet_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="4_Normals" FilePath="../../../Assets/SimplygonMan/dman_helmet_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="5_Normals" FilePath="../../../Assets/SimplygonMan/dman_visor_mask_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="6_Normals" FilePath="../../../Assets/SimplygonMan/dman_legs_logo2.0_n.JPG" ColorSpace="Linear"/>
|
||||
<Texture Name="7_Normals" FilePath="../../../Assets/SimplygonMan/dman_armor_middle_logo2_n.JPG" ColorSpace="Linear"/>
|
||||
</TextureTable>
|
||||
|
||||
<!--
|
||||
The CustomFields element lists any additional custom fields which should be added to the Scene (as AddCustomField).
|
||||
Note that since the user is responsible for alignment and packing, all fields are added as UnsignedCharArrays, with
|
||||
a tuple size of 1.
|
||||
|
||||
Fields can either reference external files, as shown below (MaterialColorsCustomField.bin), or be embedded in the .xml
|
||||
as a base64 encoded field.
|
||||
|
||||
In the example field below, we encode one 20 byte struct per material, so the input .bin file is 8 * 20 = 160 bytes
|
||||
-->
|
||||
|
||||
<CustomFields>
|
||||
<CustomField Name="MaterialColorsCustomField" FilePath="MaterialColorsCustomField.bin"/>
|
||||
</CustomFields>
|
||||
|
||||
<!--
|
||||
The MaterialTable specifies a MaterialEvaluationShader per Material. Note that the materials must already exist in the scene's
|
||||
material table, since the geometry material ids drive the actual material casting. However, each Material do not need to be
|
||||
represented, as each scene descriptor file adds to the current scene, so there can be one file for all materials which
|
||||
are to be cast, one file for each material, or some other combination, as long as all materials are set up before casting.
|
||||
-->
|
||||
|
||||
<MaterialTable>
|
||||
<Material Name="armsSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="0_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="0_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="body_upperSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="1_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="1_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="clothSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="2_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="2_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmetSG">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="3_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="3_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmetSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="4_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="4_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="helmet_visorSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="5_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="5_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="legsSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="6_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="6_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
<Material Name="middleSG1">
|
||||
<MaterialEvaluationShader Version="0.4.0" ShaderLanguage="HLSL" HeaderFilePath="HeaderCode.hlsl" ShaderFilePath="CasterCode.hlsl">
|
||||
|
||||
<!--
|
||||
Example of using indices into TexCoord field. In this case using field with index 0
|
||||
-->
|
||||
<Attribute Name="TexCoord" FieldType="TexCoords" FieldName="0" FieldFormat="F32vec2"/>
|
||||
|
||||
<!--
|
||||
Bind input tangent space, which is needed for casting normals.
|
||||
Note that in this case, there are only one field per tangent, bitangent and normal,
|
||||
so the FieldName is not needed.
|
||||
-->
|
||||
<Attribute Name="Tangent" FieldType="Tangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Bitangent" FieldType="Bitangents" FieldFormat="F32vec3"/>
|
||||
<Attribute Name="Normal" FieldType="Normals" FieldFormat="F32vec3"/>
|
||||
|
||||
<!--
|
||||
Define evaluation functions for calculating Diffuse and Normals channels.
|
||||
You can add an evaluation function for each channel to be cast.
|
||||
-->
|
||||
<EvaluationFunction Channel="Diffuse" EntryPoint="CalculateDiffuseChannel"/>
|
||||
<EvaluationFunction Channel="Normals" EntryPoint="CalculateNormalsChannel"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "DiffuseSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="SamplerMirror2D" MinFilter="Linear" MagFilter="Linear" AddressU="MirrorRepeat" AddressV="MirrorRepeat" AddressW="MirrorRepeat" />
|
||||
<ShaderParameterSampler Name="DiffuseSampler" SamplerState="SamplerMirror2D"/>
|
||||
|
||||
<!--
|
||||
Example of creating a sampler called "NormalSampler"
|
||||
Note that the settings are contrived, and only there to examplify how using multiple sampler states are possible.
|
||||
-->
|
||||
<ShaderParameterSamplerState Name="Sampler2D" MinFilter="Linear" MagFilter="Linear" AddressU="Repeat" AddressV="Repeat" AddressW="Repeat" />
|
||||
<ShaderParameterSampler Name="NormalSampler" SamplerState="Sampler2D"/>
|
||||
|
||||
<!--
|
||||
Example of using texture array
|
||||
-->
|
||||
<ShaderParameterTextureArray Name="CastingTexturesArray" Count="2">
|
||||
<TextureSlot Index="0" TextureName="7_Diffuse"/>
|
||||
<TextureSlot Index="1" TextureName="7_Normals"/>
|
||||
</ShaderParameterTextureArray>
|
||||
|
||||
<!--
|
||||
Example of referencing a custom field in the scene.
|
||||
This is used in the shader to modify the color value of the Diffuse color
|
||||
-->
|
||||
<ShaderParameterBuffer Name="CustomBuffer" FieldName="MaterialColorsCustomField" Type="customStruct"/>
|
||||
|
||||
</MaterialEvaluationShader>
|
||||
</Material>
|
||||
|
||||
</MaterialTable>
|
||||
|
||||
</Scene>
|
Загрузка…
Ссылка в новой задаче