Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


mgoss

Member Since 28 Apr 2012
Offline Last Active Oct 26 2014 03:42 PM

Topics I've Started

Calculating Vertex Normals

06 June 2013 - 11:35 AM

foreach( Vertex v )
{
   Vector3 normal = Vector3.Zero;
   foreach (Face f adjacent to v )
   {
      normal += f.GetNormal();
   }
   normal.Normalize();
}

 

I found this algorithm. However, I'm not sure how to figure if a face is adjacent to a vertex. The reason I'm doing this is because I'm generating terrain and it's very blocky. I was told using vertex normals for lighting will smooth it out.  


DX11 Depth RT issue

05 August 2012 - 04:22 AM

I'm having issues writing a depth RT correctly.
float4x4 ViewProjection;
struct VertexShaderOutput
{
float4 Position   : SV_POSITION0;
float2 Depth   : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(float4 Position: POSITION)
{
VertexShaderOutput output; 
float4 position = mul(Position, ViewProjection);
output.Position = position;
output.Depth = position.zw;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET0
{
float depth = input.Depth.x / input.Depth.y;
return float4(depth, depth * depth, 0, 0);
}
technique11 Depth
{
pass p0
{
  SetVertexShader(CompileShader(vs_4_0, VertexShaderFunction()));
  SetPixelShader(CompileShader(ps_4_0, PixelShaderFunction()));
}
}


Posted Image

Reconstruct position from log depth

13 July 2012 - 01:15 AM

Here how I'm applying the logarithmic depth in the vertex shader.
output.Position.z = log(output.Position.z / 0.001) / log(FarPlane / 0.001) * output.Position.w; //log(z/zn)/log(zf/zn)

Reconstructing in pixel shader. Not sure if i'm doing this correctly.

//read depth
float depthVal = DepthMap.Sample(depthSampler, texCoord).r;

//Compute screen-space position
float4 position = float4(input.ScreenPosition.xy, depthVal, 1.0f);
position.z = exp(depthVal * log(FarPlane / 0.001)) * 0.001; //(exp(z*log(zf/zn))*zn : z = depth value

//transform to world space
position = mul(position, InvertViewProjection);
position /= position.w;

NORMALS wrong place in Collada?

10 July 2012 - 01:37 PM

Sometimes when Maya exports models, it exports them the normals in a different location.

Sometimes it puts the normals under the <vertices>


<vertices id="objgoblin_1-VERTEX">
<input semantic="POSITION" source="#objgoblin_1-POSITION"/>
<input semantic="NORMAL" source="#objgoblin_1-Normal0"/>
</vertices>
<triangles count="7820" material="_3_FBXASC045_Default">
<input semantic="VERTEX" offset="0" source="#objgoblin_1-VERTEX"/>
<input semantic="TEXCOORD" offset="1" set="0" source="#objgoblin_1-UV0"/>
</triangles>

When typically it exports them like this

<vertices id="pCylinder1-VERTEX">
<input semantic="POSITION" source="#pCylinder1-POSITION"/>
</vertices>
<triangles count="120" material="lambert2">
<input semantic="VERTEX" offset="0" source="#pCylinder1-VERTEX"/>
<input semantic="NORMAL" offset="1" source="#pCylinder1-Normal0"/>
</triangles>

What's the difference and why does it export them at two different locations? I would prefer it to always have it in the triangles node. Because I need the offset.

Stable Cascade Shadows

21 June 2012 - 12:17 AM

http://the-witness.net/news/wp-content/gallery/valient-shaderx6-figures/figure_412.png

I saw this image and I currently have CSM implemented in my SlimDx project. However, when the camera roates, you notices the shadows move slightly. I'm not talking about the jagged edges that swim. I was hoping someone could explain more of the process about using bounding spheres for stabling CSM.

Thanks in advance.

PARTNERS