Skip to content
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

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/Stride.sln
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stride.NuGetResolver", "..\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGetResolver", "NuGetResolver", "{158087CF-AF74-44E9-AA20-A6AEB1E398A9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stride.Core.Presentation", "..\sources\presentation\Stride.Core.Presentation\Stride.Core.Presentation.csproj", "{0C63EF8B-26F9-4511-9FC5-7431DE9657D6}"
Copy link
Collaborator Author

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

Copy link
Member

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.

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stride.Core.Presentation", "..\sources\presentation\Stride.Core.Presentation\Stride.Core.Presentation.csproj", "{0C63EF8B-26F9-4511-9FC5-7431DE9657D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static GraphicsCompositor CreateDefault(bool enablePostEffects, string mo
{
new TransformRenderFeature(),
new SkinningRenderFeature(),
new BlendShapeRenderFeature(),
new MaterialRenderFeature(),
new ShadowCasterRenderFeature(),
forwardLighting,
Expand Down
28 changes: 27 additions & 1 deletion sources/engine/Stride.Engine/Rendering/ModelRenderProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 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.Collections.Generic;
using System.Linq;
using Stride.Core;
using Stride.Core.Extensions;
using Stride.Core.Mathematics;
Expand All @@ -10,6 +12,7 @@
using Stride.Graphics;
using Stride.Rendering.Materials;
using Stride.Rendering.Materials.ComputeColors;
//using Valve.VR;
Eideren marked this conversation as resolved.
Show resolved Hide resolved

namespace Stride.Rendering
{
Expand Down Expand Up @@ -77,6 +80,7 @@ public override void Draw(RenderContext context)
var modelComponent = entity.Key;
var renderModel = entity.Value;


CheckMeshes(modelComponent, renderModel);
UpdateRenderModel(modelComponent, renderModel);
});
Expand Down Expand Up @@ -113,11 +117,33 @@ private void UpdateRenderModel(ModelComponent modelComponent, RenderModel render
renderMesh.IsScalingNegative = nodeTransformations[nodeIndex].IsScalingNegative;
renderMesh.BoundingBox = new BoundingBoxExt(meshInfo.BoundingBox);
renderMesh.BlendMatrices = meshInfo.BlendMatrices;

renderMesh.HasBlendShapes = mesh.GetBlendShapesCount() > 0;
if (renderMesh.HasBlendShapes)
{
if (mesh.MATBSHAPE == null || mesh.BlendShapeProcessingNecessary)
{
mesh.ProcessBlendShapes();
}
renderMesh.MATBSHAPE = mesh.MATBSHAPE;
renderMesh.BasisKeyWeight = mesh.BasisKeyWeight;
renderMesh.BlendShapesCount=mesh.Shapes.Count;
renderMesh.VerticesCount = mesh.Draw.VertexMapping.Length;
//renderMesh.BlendShapesCount = mesh.GetBlendShapesCount();
//int verticesCount = mesh.GetBlendShapesCount() * mesh.Draw.VertexMapping.Length;
//renderMesh.VerticesCount = verticesCount;
//renderMesh.BlendShapeWeights = mesh.BlendShapeWeights;
//renderMesh.BlendShapeVertices = mesh.BlendShapeVertices;
//renderMesh.MATBSHAPE = mesh.MATBSHAPE;

Eideren marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}



private void UpdateMaterial(RenderMesh renderMesh, MaterialPass materialPass, MaterialInstance modelMaterialInstance, ModelComponent modelComponent)
{
var isShadowCaster = modelComponent.IsShadowCaster;
Expand Down Expand Up @@ -181,7 +207,7 @@ private void CheckMeshes(ModelComponent modelComponent, RenderModel renderModel)
return;
}

RegenerateMeshes:
RegenerateMeshes:
renderModel.Model = model;

// Remove old meshes
Expand Down
3 changes: 3 additions & 0 deletions sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public static unsafe void GenerateIndexBuffer(this MeshDraw meshData, VertexDecl
var indexMapping = GenerateIndexMapping(oldVertexBuffer, null);
var vertices = indexMapping.Vertices;

meshData.IndexMapping = indexMapping.Indices;
meshData.VertexMapping = indexMapping.Vertices;

// Generate vertex buffer
var vertexBufferData = new byte[declaration.VertexStride * indexMapping.Vertices.Length];
fixed (byte* oldVertexBufferDataStart = &oldVertexBuffer.Buffer.GetDataSafe()[oldVertexBuffer.Offset])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

shader TransformationBlendShape : TransformationBase, PositionStream4, Transformation
Eideren marked this conversation as resolved.
Show resolved Hide resolved
{

cbuffer PerDraw
{
//stage float2 morphWeights[MAX_MORPH_TARGETS];
//stage float3 morphTargetVertices[MAX_MORPH_TARGETS*MAX_VERTICES];
//stage float4x4 BlendMatrixArray[SkinningMaxBones];
stage float4x4 BSHAPEDATA[MAX_MORPH_TARGETS*MAX_VERTICES];
stage float BasisKeyWeight;
}


stage stream uint VertexID : SV_VertexID;

float4 ApplyBlendshapes(int vID, float4 pos)
{
float4x4 mat=BSHAPEDATA[vID];
float4 blendPos=pos*mat[1][3];

for(int i=0;i<MAX_MORPH_TARGETS;i++)
{
float4 morphedShape=BSHAPEDATA[i* MAX_VERTICES+ vID][0];
blendPos=+float4(morphedShape[0]+BasisKeyWeight,morphedShape[1], morphedShape[2] , pos[3])*morphedShape[3];
// blendPos=float4(BSHAPEDATA[0][[2],0,-1 , pos[3]);
}


//blendPos=float4(mat[vID][0], mat[vID][1],mat[vID][2],pos[3]);
return blendPos;


}


override stage void PreTransformPosition()
{


//if(streams.VertexID==0)
//{
base.PreTransformPosition();

streams.PositionWS=ApplyBlendshapes(streams.VertexID, streams.PositionWS);
//}

//uint tyh= streams.VertexID;
float xnew=streams.PositionWS.x;
float ynew=streams.PositionWS.y;

float znew=streams.PositionWS.z;
float4 blendPos = float4(xnew,ynew,znew,streams.PositionWS.w);
//float4 blendPos=ApplyBlendShape(streams.VertexID, streams.PositionWS);
streams.PositionWS = blendPos;
}


};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <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> BlendWeightArrayoxx = ParameterKeys.NewValue<Matrix>();

public static readonly ValueParameterKey<Matrix> BSHAPEDATA = ParameterKeys.NewValue<Matrix>();

public static readonly ValueParameterKey<float> BasisKeyWeight=ParameterKeys.NewValue<float>();

// public static readonly ValueParameterKey<Vector2> morphWeights = ParameterKeys.NewValue<Vector2>();

// public static readonly ValueParameterKey<Vector3> morphTargetVertices = ParameterKeys.NewValue<Vector3>();

// public static readonly ValueParameterKey<float> morphTargetVertexIndices = ParameterKeys.NewValue<float>();

// public static readonly ValueParameterKey<int> BlendIndices = ParameterKeys.NewValue<int>();
Eideren marked this conversation as resolved.
Show resolved Hide resolved


}
}
Loading