Jump to content

Vertex displacement shader


Jmac

Recommended Posts

I'm moving vertices in a very simple shader but for some reason the normals dont move with the vertices and I'm left with an odd effect. Any ideas what is causing this?


Vertex Shader

#include "shaders/common/torque.hlsl"

struct Appdata
{
 float3 position        : POSITION;
 float tangentW        : TEXCOORD3;
 float3 normal          : NORMAL;
 float3 T               : TANGENT;
 float2 texCoord        : TEXCOORD0;
};

struct Conn
{
 float4 hpos            : SV_Position;
 float2 texCoord  : TEXCOORD0;
};

Conn main( Appdata In,
                 uniform float4x4 modelview       : register(C0) )
{
 Conn Out;
 In.position.z += 20;
 Out.hpos = mul(modelview, float4(In.position, 1.0));
 Out.texCoord = In.texCoord;
 return Out;
}

 

Pixel Shader

#include "shaders/common/torque.hlsl"

struct Conn
{
  float4 hpos            : SV_Position;
  float2 texCoord  : TEXCOORD0;
};

struct Fragout
{
  float4 col : SV_Target0;
};

Fragout main(Conn IN)
{
  Fragout OUT;
  OUT.col = (255,255,255,1);
  return OUT;
}

 

What it looks like in game

screenshot_001-00000.png

Link to comment
Share on other sites

I am not 100% sure i am understanding the question, normals are a direction vector and don't have a position. In your shader you are not even using the normals so kinda hard to gather exactly what it is you are trying to do. Going to need more info.

Link to comment
Share on other sites

I'm trying to move the mesh vertices from the vertex shader in the z axis, I want to try to do the vertex translation on the gpu because of the amount I will need to move in a frame. The white color appears in the proper position but its somewhat transparent and there is that tan plane that appears at the original location that I'm assuming is another set of vertices with the normals for the object where. I don't exactly know why there are two planes or what they are to be honest.


For instance when I put in object between the white and tan I can see it when I shouldn't but when it's under the tan portion I can't see it so im assuming the tan plane has some lighting attributes.


Also when I view the white from an angle that the tan is not below it, it doesn't appear.

screenshot_002-00000.pngpost images


I haven't been able to find much info on torques rendering system so if anyone could point me in the right direction it would be appreciated.

Link to comment
Share on other sites

Unfortunately what you are seeing is a short coming of the t3d custom material system. In short what you want to do with the vertices can't be done how it works now. What happens is the object is rendered twice, once through the deferred bin (using a shadergen shader you can't change) and than it renders it again after the deferred pass using your custom material, this is why you see the object twice because you are obviously changing the vertex position only in that second pass.


Just a couple of small things in ya pixel shader

OUT.col = (255,255,255,1);

should read

OUT.col = float4(1.0,1.0,1.0,1.0);

 

ya firstly need the type(float4) and the shaders use a float range for the color, although 255 is a perfectly valid number with HDR i'm guessing you really meant 255 as in 0-255 unsigned byte range so the value should be 1.0


Hopefully that clears it up for you.

Link to comment
Share on other sites

Hm, I'll take an eyeball on how the current water stuff does it, because being able to permute the vert positions is definitely something that should be possible in a custom mat. So if it's choking that hard, it needs a-looking.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...