Jump to content

[SOLVED] Custom Deformation


photo

Recommended Posts

I'd like to deform an object using a custom algorithm. ObjectMeshDynamic seemed like a good point to start but calculating the deformation on CPU was too slow and when using a Compute Shader the transmission of the data was too slow since I'm not able to set the vertex buffer directly using a structured buffer.

So then I tried creating my own material. I copied the mesh_base material and core/shaders/mesh/opacity/deferred.shader. Let's call them deform_object.basemat and deform.vert. I replaced every vertex shader in deform_object.basemat with deform.vert. I modified deform.vert so it takes care of the deformation. Everything works so far apart from shadows when the deferred pass is used. If the object uses the ambient pass the shadows work fine. Is there anything I'm missing or do custom vertex shaders not work for shadows using the deferred pass? As input for the deformation I'm using two textures: control_points and weights. I've attached the material and the shader. I'm asigning my deformed position to in_d.position, so that the output struct will be set correctly. 

Is there an easier way to use a custom vertex shader for the mesh_base material? If not, did I make a mistake in my material so that deferred shadows do not work or is it simply not possible?

deform.vert

 

deform_object.basemat

Edited by Grimkin
Link to comment

Hi, Grimkin.

I assume you used 2.12 version of the SDK?

The shader you gave had a warning that prevented it from compiling.

image.png

after replacing line 96 with

in_d.position	= getDeformedPosition( ATTRIBUTE_POSITION.xyz );

Everything starts to work fine
image.png

If it still won't work for you, please specify SDK version, as well as the console output and textures that you are using.

image.png

Link to comment

Hi sweetluna,

Thanks for your response. I simplified the shader for posting it here so I it seems I made a mistake here and yes I'm using Unigine 2.12.

I simplified the shader now even more and just move the object by {1,-1,0} in line 77 so the problem can be easily seen. As you can see in the in the attached image the shadow does not match. I'm using a LightWorld for lighting but I have the same problem with LightOmni and LightProj.

DeferredShadow.jpg

deform.vert

Link to comment

Hi, sorry for the late response.
You have to disable static_shadow state whenever you want to add displacement for your mesh.

For example:

	<state name="static_shadow"	vegetation="0"	parallax="0"	custom_state_for_correct_shadow="0"	geometry_inflation="0"	defines="name"	internal="1"/>
	
	<state name="custom_state_for_correct_shadow">1</state>


I hope it helps!

image.png

 

Link to comment
  • silent changed the title to [SOLVED] Custom Deformation
×
×
  • Create New...