Jump to content

  • Log In with Google      Sign In   
  • Create Account


dxCUDA

Member Since 12 Feb 2012
Offline Last Active Jun 16 2013 03:42 PM

Topics I've Started

Per object lighting transformation error?

01 June 2012 - 01:32 PM

Another day, another issue.

Currently I am rendering a red point light in the world, but seemingly one point light is being applied independently for each object. Obviously I want one point light in the world to effect all objects (objects to share the same lighting). This issue was also apparent with my directional light.

I think it might be an issue either in my shader transforming into clip space and maybe then I need to do a new transformation

input.p = mul( input.p, World );
output.p = mul( input.p, View );  
output.p = mul( output.p, Projection );

Or the issue is in my baseObject render method, whereby I am rendering something per-object as opposed to globally, or there is a transformation I am missing to incorporate at this level

void dxBaseModel::render()
{
D3DXMatrixIdentity(&posMatrix);
D3DXMatrixIdentity(&rotMatrix);
D3DXMatrixIdentity(&meshWorld);


D3DXMatrixRotationYawPitchRoll(&rotMatrix, rotation.y, rotation.x, rotation.z);
D3DXMatrixTranslation(&posMatrix, position.x, position.y, position.z);
D3DXMatrixMultiply(&meshWorld, &rotMatrix, &posMatrix);

pViewMatrixEffectVariable->SetMatrix(viewMatrix);
pProjectionMatrixEffectVariable->SetMatrix(projectionMatrix);

myTexture.pTextureSR->SetResource( myTexture.textureSRV[0] );
myTexture.pBumSR->SetResource(myTexture.textureSRV[1]);
myTexture.pSpecSR->SetResource(myTexture.textureSRV[2]);


D3D10_TECHNIQUE_DESC TechDesc;

pBasicTechnique->GetDesc(&TechDesc);


for( UINT p = 0; p < TechDesc.Passes; p++ )
{
  WVP = meshWorld*viewMatrix*projectionMatrix;
  pWVPMatrixEffectVariable->SetMatrix((float*)&WVP);
  pWorldMatrixEffectVariable->SetMatrix((float*)&meshWorld);


  pBasicTechnique->GetPassByIndex( p )->Apply( 0 );

  pMesh->DrawSubset(0);
}
}

Here's an image of the scene to illustrate the issue at hand.

Thanks

Posted Image

OpenGL ASM Experiment

27 May 2012 - 03:08 PM

Experimenting with learning x64 asm and how code operates on a low level, and trying to work out where speed is increased in projects when ASM is appropriately used.

My project is x64 with MASM in visual studio 2010

Currently I am trying to replace the basic glClear glLoadIdentity etc with asm to understand how to interface between code and asm.

I'm following the asm examples over at NEHE, but I constantly keep getting an access violation error when I seem to introduce 'push' into the code.

This is the code asm-side:
include gl.inc
include glu.inc

.data
_45d0 equ 40468000h ;45.0
_45d1   equ 0
_01d0 equ 1069128089  
_01d1   equ -1717986918 ;0.1
_100d0 equ 1079574528
_100d1  equ 0  ;100.0
_1d0 equ 1072693248
_1d1 equ 0   ;1.0
_05 equ 1056964608  ; 0.5
_1 equ 1065353216  ; 1.0
_m1 equ -1082130432 ;-1.0
_3 equ 1077936128  ; 3.0
_m15 equ -1077936128 ;-1.5
_m6 equ -1061158912 ;-6.0

.code

ASMrender proc
display:

push   GL_COLOR_BUFFER_BIT
call glClear
call glLoadIdentity
call glEnd

push _m15
push 0
push _m6
call glTranslatef

xor eax,eax

ret

ASMrender endp
end


Over in C++ I am just doing the standard 'extern "C" void ASMrender
and then calling ASMrender() in the main render loop.

Here's a screenshot of some of the action where it all goes wrong.
Posted Image

Rotating camera around player origin

17 May 2012 - 08:24 AM

I can't quite figure out current how to Transform the lookAt and up vector by the rotation matrix so the view is rotated about the player origin.

Cheers

up.x = 0.0f;
up.y = 1.0f;
up.z = 0.0f;
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
pitch = m_rotationX * 0.0174532925f;
yaw   = m_rotationY * 0.0174532925f;
roll  = m_rotationZ * 0.0174532925f;
D3DXVECTOR3 rotation = D3DXVECTOR3(m_rotationX, m_rotationY, m_rotationZ);
  D3DXVECTOR3 camera[3] = { D3DXVECTOR3(m_fCameraX, m_fCameraY, m_fCameraZ),//Eye
				D3DXVECTOR3(m_fLookatX, m_fLookatY, m_fLookatZ),//LookAt
				up };//Up
// Create the rotation matrix from the yaw, pitch, and roll values.
D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);
//Translate in the direction of player rotation
D3DXVec3TransformCoord(&camera[0], &camera[0], &rotationMatrix);
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
D3DXVec3TransformCoord(&camera[1], &camera[1], &rotationMatrix);
D3DXVec3TransformCoord(&camera[2], &camera[2], &rotationMatrix);
camera[1] = camera[0] + camera[1];
D3DXMatrixLookAtLH(&in_viewMatrix, &camera[0], &camera[1], &camera[2]);

Normal map issue and theory

15 May 2012 - 04:33 AM

I am having a long standing issue with the computation of my normal map within the shader(HLSL) file. As you can see there are corrupt triangles on the mesh at various and sometimes, symmetric points.

I think my issue may relate to interpolating vertex attributes across each triangle, when I calculate the input texture data; I cannot be sure however.

Thanks

Posted Image

//--------------------------------------------------------------------------------------
// Lighting
//--------------------------------------------------------------------------------------
//transformation matrices
matrix World;
matrix View;
matrix Projection;
//TEXTURE VARIABLES
//--------------------------------------------------------------------------------------
//color map texture
Texture2D tex2D;
//bump map texture
Texture2D bump2D;

//texture sampler state
SamplerState linearSampler
{
	Filter = min_mag_mip_linear;
	AddressU = Wrap;
	AddressV = Wrap;
};
//LIGHTING STRUCTURES AND VARIABLES
//--------------------------------------------------------------------------------------
struct DirectionalLight
{
float4 color;
float3 dir;
};
struct Material
{
float Ka, Kd, Ks, A;
};
//lighting vars
DirectionalLight light;
Material material;
float4 ambientLight;
float3 eye;
float4x4 gTexMtx;
//RASTERIZER STATES
//--------------------------------------------------------------------------------------
RasterizerState rsSolid
{
   FillMode = Solid;
   CullMode = NONE;
   FrontCounterClockwise = false;
};
//VERTEX AND PIXEL SHADER INPUTS
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 p  : POSITION;
float2 t  : TEXCOORD;
float3 n  : NORMAL;
	float3 tangent  : TANGENT;
};

struct PS_INPUT_PP_BLINNPHONG
{
float4 p  : SV_POSITION;
float2 t  : TEXCOORD;
float3 n  : TEXCOORD1;
float3 h  : TEXCOORD2;
	float3 tangent  : TANGENT;
};
//--------------------------------------------------------------------------------------
// Blinn-Phong Lighting Reflection Model
//--------------------------------------------------------------------------------------
float4 calcBlinnPhongLighting( Material M, float4 LColor, float3 N, float3 L, float3 H )
{
float4 Ia = M.Ka * ambientLight;
float4 Id = M.Kd * saturate( dot(N,L) );
float4 Is = M.Ks * pow( saturate(dot(N,H)), M.A );

return Ia + (Id + Is) * LColor;
}
//--------------------------------------------------------------------------------------
// PER PIXEL LIGHTING
//--------------------------------------------------------------------------------------
PS_INPUT_PP_BLINNPHONG VS_PIXEL_LIGHTING_BLINNPHONG( VS_INPUT input )
{
PS_INPUT_PP_BLINNPHONG output;

//set position into clip space
input.p = mul( input.p, World );
output.p = mul( input.p, View );  
output.p = mul( output.p, Projection );
//set texture coords
output.t = input.t;  
// Output vertex attributes for interpolation across triangle.
//output.t = mul(float4(input.t, 0.0f, 1.0f), gTexMtx);
//set required lighting vectors for interpolation
float3 V = normalize( eye - (float3) input.p );
output.n = normalize( mul(float4(input.n, 0.0f ), World) );
output.h = normalize( -light.dir + V );

// Calculate the tangent vector against the world matrix only and then normalize the final value.
//output.tangent = mul(input.tangent, (float3x3)World);
output.tangent = mul(float4(input.tangent, 0.0f),  World);
output.tangent = normalize(output.tangent);
return output;
}
float4 PS_PIXEL_LIGHTING_BLINNPHONG( PS_INPUT_PP_BLINNPHONG input ) : SV_Target
{

//renormalize interpolated vectors
input.n = normalize( input.n );
input.h = normalize( input.h );

//calculate lighting
float4 I = calcBlinnPhongLighting( material, light.color, input.n, -light.dir, input.h );

//with texturing
return I * tex2D.Sample(linearSampler, input.t);
}
float4 PS_NORMAL_MAP( PS_INPUT_PP_BLINNPHONG input) : SV_Target
{
float4 textureColor;
	float4 bumpMap;
	float3 bumpNormal;
float3 bitangent;
float lightIntensity;
	float4 color;
textureColor = tex2D.Sample(linearSampler, input.t);
bumpMap	 = bump2D.Sample(linearSampler, input.t);
	
//renormalize interpolated vectors
input.h = normalize( input.h );
// Expand the range of the normal value from (0, +1) to (-1, +1).
	 bumpMap = (2.0f * bumpMap) - 1.0f;
input.n = normalize( input.n );
input.tangent = normalize(input.tangent - dot(input.tangent, input.n)*input.n);
bitangent = cross(input.n, input.tangent);
//Tex space matrix
float3x3 texSpace = float3x3(input.tangent, bitangent, input.n);
  //Convert normal from normal map to texture space and store in input.normal
  bumpNormal = normalize(mul(bumpMap, texSpace));
  input.n = normalize(mul(bumpMap, texSpace));
  //lightIntensity = saturate(dot(bumpedNormal, -light.dir));
  lightIntensity = saturate(dot(bumpNormal, -light.dir));
  //calculate lighting
float4 I = calcBlinnPhongLighting( material, light.color, input.n, -light.dir, input.h );
  //with texturing
return lightIntensity * I *  textureColor;
  //return I *  textureColor;
}
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique10 RENDER_PL_BLINNPHONG
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_4_0, VS_PIXEL_LIGHTING_BLINNPHONG() ) );
		SetGeometryShader( NULL );
	   //SetPixelShader( CompileShader( ps_4_0, PS_PIXEL_LIGHTING_BLINNPHONG() ) );
	 SetPixelShader( CompileShader( ps_4_0, PS_NORMAL_MAP() ) );
		SetRasterizerState( rsSolid );
	}

}

Directx 10 Normal Map issues

12 February 2012 - 11:59 AM

I am currently using Raster Tek's normal mapping tutorial after mine went haywire, but I am getting these strange mesh issues. I would assume that because the binormal and tangent calculations work per three vertices, the new mesh normals are being generated without regards to neighboring normals. I guess that the average of the surrounding normals must be calculated to generate a new central normal for every arbitary set of veritces. But the issue is, how do I know how many vertices attach to either vertex, there are an arbitrary, non uniform number of vertices.

I also noticed that in Frank.D.Lunas book Introduction to 3D Game Programming with Directx10, he does all his calculations for the normal map in the shader with no binormal/tangent calculation present in the code. I would preferably like to have all my calculations within the shader itself.

This is an image of the issue at hand:

Thanks
Posted Image

PARTNERS