Jump to content

  • Log In with Google      Sign In   
  • Create Account

MJP

Member Since 29 Mar 2007
Offline Last Active Today, 12:03 AM

Posts I've Made

In Topic: Direction to point for lighting purposes

26 September 2016 - 03:16 PM

That will give you a normalized direction vector pointing from the camera to the surface, in view space. You actually want a vector pointing from the surface -> light source, so you'd want to negate the vector. You would also need to make sure that the normal is converted to view space, otherwise you'll be working with vectors in two different coordinate spaces which wouldn't work. So you could do this:

 

float3 surfacePosVS = mul(float4(surfacePosWS, 1.0f), ViewMatrix);
float3 normalVS = mul(float4(normalWS, 0.0f), ViewMatrix);
float3 surfaceToLightVS = normalize(-surfacePosVS);
float lighting = saturate(dot(normalVS, surfaceToLightVS));

 

Or if you'd rather do everything in world space, you can do it like this:

 

float3 surfaceToLightWS = normalize(CameraPosWS - surfacePosWS);
float lighting = saturate(dot(normalWS, surfaceToLightWS));

 

For the second version, you just need to somehow pass your world space camera position through a constant buffer.


In Topic: Draw normal geometry and wireframe geometry in the same pass

25 September 2016 - 11:10 PM

This technique is pretty straightforward to implement, has high quality for interior edges, and can be done in a single pass. There's also a working demo with source code.


In Topic: Set vertex position in Domain Shader with Height Map texture

17 September 2016 - 05:01 PM

How the GPU interprets the texture data depends on the DXGI format used for the shader resource view. Specifically, the suffix at the end of the format (UNORM, FLOAT, etc.). You can see a full list and a description for each towards the end of this page (scroll down to "Format Modifiers"). In your case you were likely creating your texture with a UNORM format, which means that the GPU will interpret the 0-255 integer data as a 0.0-1.0 floating point value. 


In Topic: Set vertex position in Domain Shader with Height Map texture

16 September 2016 - 05:30 PM

You definitely want to do this in the domain shader, not the pixel shader. Have you tried using a debugging tool like RenderDoc to make sure that you've correctly bound the height map texture to the domain shader stage? RenderDoc also supports shader debugging (although not for tessellation shaders unfortunately), which you may find useful.


In Topic: How to calculate normals for deferred rendering + skinned mesh?

14 September 2016 - 03:20 PM

You need to apply both transforms:

 

float3 normal = input.Normal;
normal = mul(normal, (float3x3)SkinTransform);
normal = mul(normal, (float3x3)InverseTransposeWorld);
normal = normalize(normal);

PARTNERS