Open GutterLab opened 5 years ago
I also took a dig at this (as you can see it's a bit of a mess) and looked at implementing my own IMaterialDisplacementFeature and implement my own variant while looking at the existing ones but ran into a few issues related to shader mixing and other things which impeded things a little.. Overall the system does currently seem very baked into just dealing with normal-based displacement.
So a way to have your own little vertex shader feature would be great, though it seems like maybe it should be separate from the displacement map feature?
Still, I think having an easy way to do this kind of manipulation is quite important (and is coincidentally easily accomodated in most other engines).
see also: https://forums.xenko.com/t/adding-a-vertex-shader-to-a-material/1715/7
Not sure if it fully answers the question, but here is a small extract of how I did some displacement mapping in a test project a while ago: material
Displacement: !MaterialDisplacementMapFeature
DisplacementMap: !ComputeShaderClassScalar
MixinReference: ComputeColorWave
Generics: {}
CompositionNodes: {}
Intensity: !ComputeFloat
Value: 1.0
Stage: Vertex
ComputeColorWave.xksl
// Copyright (c) Xenko contributors (https://xenko.com) 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.
shader ComputeColorWave : ComputeColor, Texturing
{
override float4 Compute()
{
float phase = length(streams.TexCoord - 0.5);
return 0.5 + sin((phase + Global.Time * 0.1) * 2 * 3.14 * 8.5) * 0.1;
}
};
I find a way to custom vertex shader or pixel shader or both, just create a sdsl file and use the shader code below:
shader TestSS : ComputeColor, ShaderBaseStream, Transformation
{
stage stream float4 Position : POSITION;
stage void VSMain()
{
streams.ShadingPosition = mul(streams.Position, WorldViewProjection);
}
stage void PSMain()
{
streams.ColorTarget = float4(1, 0, 0, 1);
}
};
You can add it to any material attribute except "Displacement", and it will take effect.
If you set multiple vs or ps, only the first one will take effect.
I will simply explain it:
You can find "ComputeColor", "ShaderBaseStream" and "Transformation" in source code as sdsl file, and you can find more useful sdsl file with suffix "stream" that defined other params to use in source code.
I think the shader system is completed more than imagination, but it need to be orgnized more in the document.
Is your feature request related to a problem? Please describe. As of now there seems to be no way to use a vertex shader in a material. Using one in the pipeline requires a lot of code.
Describe the solution you'd like A field or property on a material that will allow you to place any number of any shader.
Describe alternatives you've considered I've considered using Tebjan's root renderer, but from looking at it, it looks as if he re-implemented creating a plane mesh in order to draw his sprite in 3d space. I've attempted to modify the displacement material to no avail.