-
-
Notifications
You must be signed in to change notification settings - Fork 938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][Rendering] Blendshapes (on behalf of Noa7/Noah7071) #2136
base: master
Are you sure you want to change the base?
Changes from 11 commits
ed0e939
a3f044a
8a3c13f
a679906
afe10c0
0a516fd
6649b09
6ed75b6
5db94d9
c04c84d
e66c0c8
36c3daf
06c130b
1751b13
af97e33
96f878d
58ead58
f13c8f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
shader TransformationBlendShape : TransformationBase, PositionStream4, Transformation | ||
Eideren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
||
cbuffer PerDraw | ||
{ | ||
stage float4x4 BSHAPEDATA[MAX_MORPH_TARGETS*MAX_VERTICES]; | ||
} | ||
|
||
|
||
stage stream uint VertexID : SV_VertexID; | ||
|
||
float4 ApplyBlendshapes(int vID, float4 originalPosition) | ||
{ | ||
float4 blendedPosition=originalPosition; | ||
for(int i=0;i<MAX_MORPH_TARGETS;i++) | ||
{ | ||
float4 morphImact=(BSHAPEDATA[i* MAX_VERTICES+ vID][0] -originalPosition)*(BSHAPEDATA[i* MAX_VERTICES+ vID][0][3]); | ||
blendedPosition= blendedPosition+float4(morphImact[0],morphImact[1], morphImact[2] , 0); | ||
} | ||
return blendedPosition; | ||
} | ||
|
||
|
||
override stage void PreTransformPosition() | ||
{ | ||
base.PreTransformPosition(); | ||
streams.PositionWS=ApplyBlendshapes(streams.VertexID, streams.PositionWS); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// <auto-generated> | ||
// Do not edit this file yourself! | ||
// | ||
// This code was generated by Stride Shader Mixin Code Generator. | ||
// To generate it yourself, please install Stride.VisualStudio.Package .vsix | ||
// and re-save the associated .sdfx. | ||
// </auto-generated> | ||
|
||
using System; | ||
using Stride.Core; | ||
using Stride.Rendering; | ||
using Stride.Graphics; | ||
using Stride.Shaders; | ||
using Stride.Core.Mathematics; | ||
using Buffer = Stride.Graphics.Buffer; | ||
namespace Stride.Rendering | ||
{ | ||
public static partial class TransformationBlendShape | ||
{ | ||
public static readonly ValueParameterKey<Matrix> BSHAPEDATA = ParameterKeys.NewValue<Matrix>(); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) | ||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Silk.NET.SDL; | ||
using Stride.Core; | ||
using Stride.Core.Diagnostics; | ||
using Stride.Core.Mathematics; | ||
using Stride.Core.Threading; | ||
using Stride.Rendering.Materials; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Collections; | ||
|
||
namespace Stride.Rendering | ||
{ | ||
/// <summary> | ||
/// Computes and uploads skinning info. | ||
/// </summary> | ||
public class BlendShapeRenderFeature : SubRenderFeature | ||
{ | ||
private StaticObjectPropertyKey<RenderEffect> renderEffectKey; | ||
|
||
private ObjectPropertyKey<Matrix[]> renderModelObjectInfoKey; | ||
|
||
private ConstantBufferOffsetReference BshpDataOffssetRef; | ||
|
||
/// <inheritdoc/> | ||
protected override void InitializeCore() | ||
{ | ||
renderEffectKey = ((RootEffectRenderFeature)RootRenderFeature).RenderEffectKey; | ||
renderModelObjectInfoKey = RootRenderFeature.RenderData.CreateObjectKey<Matrix[]>(); | ||
BshpDataOffssetRef = ((RootEffectRenderFeature)RootRenderFeature).CreateDrawCBufferOffsetSlot(TransformationBlendShape.BSHAPEDATA.Name); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void PrepareEffectPermutations(RenderDrawContext context) | ||
{ | ||
var renderEffects = RootRenderFeature.RenderData.GetData(renderEffectKey); | ||
int effectSlotCount = ((RootEffectRenderFeature)RootRenderFeature).EffectPermutationSlotCount; | ||
|
||
|
||
Dispatcher.ForEach(((RootEffectRenderFeature)RootRenderFeature).ObjectNodeReferences, objectNodeReference => | ||
{ | ||
var objectNode = RootRenderFeature.GetObjectNode(objectNodeReference); | ||
var renderMesh = (RenderMesh)objectNode.RenderObject; | ||
var staticObjectNode = renderMesh.StaticObjectNode; | ||
|
||
for (int i = 0; i < effectSlotCount; ++i) | ||
{ | ||
var staticEffectObjectNode = staticObjectNode * effectSlotCount + i; | ||
var renderEffect = renderEffects[staticEffectObjectNode]; | ||
if (renderEffect == null) { continue; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our coding style prefers single line without |
||
if (renderMesh.HasBlendShapes) | ||
{ | ||
|
||
renderEffect.EffectValidator.ValidateParameter(MaterialKeys.HasBlendShape, renderMesh.HasBlendShapes); | ||
renderEffect.EffectValidator.ValidateParameter(MaterialKeys.MAX_VERTICES, renderMesh.VerticesCount); | ||
renderEffect.EffectValidator.ValidateParameter(MaterialKeys.MAX_MORPH_TARGETS, renderMesh.BlendShapesCount); | ||
|
||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public override void Extract() | ||
{ | ||
var renderModelObjectInfo4 = RootRenderFeature.RenderData.GetData(renderModelObjectInfoKey); | ||
Dispatcher.ForEach(RootRenderFeature.ObjectNodeReferences, objectNodeReference => | ||
{ | ||
var objectNode = RootRenderFeature.GetObjectNode(objectNodeReference); | ||
var renderMesh = (RenderMesh)objectNode.RenderObject; | ||
renderModelObjectInfo4[objectNodeReference] = renderMesh.MATBSHAPE; | ||
}); | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public override unsafe void Prepare(RenderDrawContext context) | ||
{ | ||
var renderModelObjectInfoData = RootRenderFeature.RenderData.GetData(renderModelObjectInfoKey); | ||
|
||
Dispatcher.ForEach(((RootEffectRenderFeature)RootRenderFeature).RenderNodes, (ref RenderNode renderNode) => | ||
{ | ||
var renderMesh = (RenderMesh)renderNode.RenderObject; | ||
|
||
if (!renderMesh.HasBlendShapes) { return; } | ||
|
||
var perDrawLayout = renderNode.RenderEffect.Reflection?.PerDrawLayout; | ||
if (perDrawLayout == null) | ||
return; | ||
|
||
var bdataVerticesOffset= perDrawLayout.GetConstantBufferOffset(BshpDataOffssetRef); | ||
if(bdataVerticesOffset==-1) | ||
{ | ||
return; | ||
} | ||
|
||
var renderModelObjectInfo = renderModelObjectInfoData[renderNode.RenderObject.ObjectNode]; | ||
if(renderModelObjectInfo == null) | ||
{ | ||
return; | ||
} | ||
|
||
|
||
unsafe | ||
{ | ||
|
||
var mappedCB = (byte*)renderNode.Resources.ConstantBuffer.Data + bdataVerticesOffset; | ||
fixed (Matrix* matPtr = renderModelObjectInfo) | ||
{ | ||
Unsafe.CopyBlockUnaligned(mappedCB, matPtr, (uint)(renderMesh.VerticesCount*renderMesh.BlendShapesCount) * (uint)sizeof(Matrix)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,10 @@ private Effect CreateEffect(string effectName, EffectBytecodeCompilerResult effe | |
} | ||
} | ||
if (filePath != null) | ||
if(filePath.ToUpper().Contains("BLENDSHAPE")) | ||
{ | ||
|
||
} | ||
Comment on lines
+232
to
+235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused ? |
||
directoryWatcher.Track(filePath); | ||
} | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ public class MaterialKeys | |
public static readonly PermutationParameterKey<ShaderSource> VertexStageSurfaceShaders = ParameterKeys.NewPermutation<ShaderSource>(); | ||
public static readonly PermutationParameterKey<ShaderSource> DomainStageSurfaceShaders = ParameterKeys.NewPermutation<ShaderSource>(); | ||
public static readonly PermutationParameterKey<ShaderSource> PixelStageSurfaceShaders = ParameterKeys.NewPermutation<ShaderSource>(); | ||
|
||
public static readonly PermutationParameterKey<ShaderSource> VertexStageStreamInitializer = ParameterKeys.NewPermutation<ShaderSource>(); | ||
public static readonly PermutationParameterKey<ShaderSource> DomainStageStreamInitializer = ParameterKeys.NewPermutation<ShaderSource>(); | ||
public static readonly PermutationParameterKey<ShaderSource> PixelStageStreamInitializer = ParameterKeys.NewPermutation<ShaderSource>(); | ||
|
@@ -50,7 +50,7 @@ public class MaterialKeys | |
public static readonly ObjectParameterKey<Texture> SpecularMap = ParameterKeys.NewObject<Texture>(); | ||
public static readonly ValueParameterKey<Color3> SpecularValue = ParameterKeys.NewValue<Color3>(); | ||
public static readonly ValueParameterKey<float> SpecularIntensityValue = ParameterKeys.NewValue<float>(); | ||
|
||
public static readonly ObjectParameterKey<Texture> GlossinessMap = ParameterKeys.NewObject<Texture>(); | ||
public static readonly ValueParameterKey<float> GlossinessValue = ParameterKeys.NewValue<float>(); | ||
|
||
|
@@ -125,11 +125,20 @@ public class MaterialKeys | |
public static readonly PermutationParameterKey<bool> HasSkinningTangent = ParameterKeys.NewPermutation<bool>(); | ||
|
||
public static readonly PermutationParameterKey<int> SkinningMaxBones = ParameterKeys.NewPermutation<int>(56); | ||
|
||
|
||
public static readonly PermutationParameterKey<int> MAX_VERTICES = ParameterKeys.NewPermutation<int>(1); | ||
|
||
public static readonly PermutationParameterKey<int> MAX_MORPH_TARGETS = ParameterKeys.NewPermutation<int>(1); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Match the naming style of the other fields |
||
public static readonly PermutationParameterKey<bool> UsePixelShaderWithDepthPass = ParameterKeys.NewPermutation<bool>(); | ||
|
||
public static readonly PermutationParameterKey<bool> UseDitheredShadows = ParameterKeys.NewPermutation<bool>(); | ||
|
||
|
||
public static readonly PermutationParameterKey<bool> HasBlendShape = ParameterKeys.NewPermutation<bool>(); | ||
|
||
|
||
static MaterialKeys() | ||
{ | ||
//SpecularPowerScaled = ParameterKeys.NewDynamic(ParameterDynamicValue.New<float, float>(SpecularPower, ScaleSpecularPower)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best to roll this change back, afaict it is not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually correct but since it isn't related to the changes of this PR, let's revert it indeed. Otherwise it might conflict later with changes on the editor.