Jump to content
  • Advertisement

AriusMyst

Member
  • Content Count

    66
  • Joined

  • Last visited

Community Reputation

130 Neutral

About AriusMyst

  • Rank
    Member
  1. AriusMyst

    Geometry Instancing API

    I can't believe I forgot the shader. float4x4 w; //World. float4x4 v; //View. float4x4 p; //Projection. texture d; //Diffuse/Colour texture map. sampler2D ds = sampler_state { Texture = (d); MIPFILTER = LINEAR; MAGFILTER = LINEAR; MINFILTER = LINEAR; }; struct a2v { //Stream 0. Vertex information. float4 p : POSITION0; float2 uv: TEXCOORD0; float3 n : NORMAL; //Stream 1. Instance information. float4 Pos: COLOR1; }; struct v2f { float4 p : POSITION; float2 uv : TEXCOORD0; }; void vp(in a2v a2vin, out v2f v2fout) { float4 newPosition = mul(a2vin.p, w); float4 InstPosition = mul(a2vin.Pos, w); newPosition.x += InstPosition.x; newPosition.y += InstPosition.y; newPosition.z += InstPosition.z; v2fout.p = mul(newPosition, mul(v, p)); v2fout.uv = a2vin.uv; } float4 fp(in v2f v2fin): COLOR0 { float4 pixel = tex2D(ds, v2fin.uv); return pixel; } technique render { pass pass0 { //ZENABLE = TRUE; //ZWRITEENABLE = TRUE; //CULLMODE = NONE; vertexshader = compile vs_3_0 vp(); pixelshader = compile ps_3_0 fp(); } }
  2. Hello, I'm trying to draw up a comparison between constants based instancing and hardware based instancing. The middleware engine I frequently use has constants based support and I'm trying to write up a hardware based class for it's community to mull over. The engine gives me access to it's internal DirectX objects so I'm able to grab the DX device and some mesh data. I've gotten pretty far, I have it rendering stuff with a shader. The problem is that the geometry is broken and it doesn't appear to be positioning the instances correctly( it is also criminally slow, about 4fps on a 9400M with 520 instances -- constants is averaging 80fps with the same number ). I have been looking at several sources of information for the past week. I have GPU Gems 2 open on my desk with an entire chapter dedicated to instancing, I have the DirectX SDK sample and an old MDX sample from 2005. I'm not entirely sure where I'm going wrong, but using a middleware engine 99% of the time has not helped( vertex buffers and the like are fine but I'm probably getting them wrong somewhere, these are usually hidden from me ). Here is how I'm creating the vertex buffer for my instancing data. At the moment it is just one float3( positionx, positiony and positionz ). You can also see at the top of the function for the actual geometry I am grabbing the vertex and index buffers directly from a mesh( this seems to work fine if I just render them out without any of the actual instancing code ). void HardwareInstancer::BuildBuffer() { //Setup the geometry and instance buffers. //.... //Grab the mesh vertex and index buffer. geomBase->GetVertexBuffer(&VB); geomBase->GetIndexBuffer(&IB); //Create the instance buffer. m_Device->CreateVertexBuffer(iElementCount * sizeof(InstanceData), 0, 0, D3DPOOL_MANAGED, &ID, 0); InstanceData *vData = NULL; //As void. //Lock the buffer before we fill it with data. ID->Lock(0, NULL, (void**)&vData, 0); //Fill the instance data. for(int i = 0; i < iElementCount; i++) { InstanceData Data; Data.x = IData.at(i).x; Data.y = IData.at(i).y; Data.z = IData.at(i).z; *vData = Data, vData++; } //Unlock the buffer. ID->Unlock(); //------------------------------------------------------ } The vertex element declaration might be incorrect. D3DVERTEXELEMENT9 decl[] = { //Stream 0. Standard data. {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, //Stream 1. Instance data. {1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, D3DDECL_END() }; I'm rendering it out in the following fashion. I've looked over both the DX and the MDX samples and this appears to be correct?. The GPU Gems 2 chapter is weird here however, for both SetStreamSource calls it uses the same vertex buffer -- I think this is a misprint. void HardwareInstancer::RenderElements() { m_Device->SetVertexDeclaration(gdecl); //Set the stream to our geometry. m_Device->SetStreamSource(0, VB, 0, geomBase->GetNumBytesPerVertex()); m_Device->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | iElementCount); //Set the stream to instances. m_Device->SetStreamSource(1, ID, 0, sizeof(InstanceData)); m_Device->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1); m_Device->SetIndices(IB); shadeHardware->SetMatrix("v", &View); shadeHardware->SetMatrix("p", &Projection); shadeHardware->SetTexture("d", DT); shadeHardware->SetTechnique("render"); shadeHardware->Begin(0, 0); shadeHardware->BeginPass(0); m_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, geomBase->GetNumVertices(), 0, geomBase->GetNumFaces()); shadeHardware->EndPass(); shadeHardware->End(); m_Device->SetStreamSourceFreq(0, 1); m_Device->SetStreamSourceFreq(1, 1); } I've uploaded a couple screenshots so you can get a visual read on the problem. Constants: http://esoteric-float.co.uk/screenshots/bugs/constants.jpg Hardware : http://esoteric-float.co.uk/screenshots/bugs/hardware.jpg The hardware instances have the same positions as the constants ones. You can also see that in the hardware version one of the mushrooms renders in full, whereas the rest of them don't. I've been stumped on this for 4 days and I don't seem to be able to progress past it. Any help or advice is most welcome. Thanks.
  3. AriusMyst

    FBX SDK and Direct3D10

    Not sure if this belongs here or in another section. I've just posted this on the area forum but thought I'd post it here as Autodesk's forum seems a little dead. I'm hoping someone here uses the FBX SDK and can help me out. The problem is in building the vertex buffer. Here is the thread on the area forum, verbatim: //---------------------- Hello, I'm trying to get the vertex data loaded up in to D3D10. However, I must be going about this the wrong way as the resulting mesh is all messed up. I'm currently using the control point co-ords, which seems wrong as there are less control points than there are verticies. Anyway, I've taken a couple shots of a sphere. D3D10_PRIMITIVE_TOPOLOGY_POINTLIST: http://img220.imageshack.us/img220/3807/pointar1.jpg D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP: http://img230.imageshack.us/img230/5688/triig3.jpg I'm 99.9% sure I am not accessing all the data required to build the mesh correctly. For the moment I am ignoring normals and just trying to get the base mesh in. I will deal with lighting later. Here is the, rather messy, code I am using to build the vertex buffer and render it. void eecc::CreateMesh(KFbxMesh* lMesh) { Core->AddLine(L"converter:: Creating ESM."); HRESULT res; p_Errors = NULL; D3DX10CreateEffectFromFile(L"C:\\epiphany\\programs\\green.fx", NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, p_Device, NULL, NULL, &p_Effect, &p_Errors, &res&#41;; if(FAILED(res)) { if(p_Errors) { char* pCompileErrors = static_cast<char*>(p_Errors->GetBufferPointer()); std::basic_ostringstream<TCHAR> Buffer0; Buffer0 << " ERROR: " << pCompileErrors << "."; Core->AddLine(Buffer0.str().c_str()); } //return FALSE; } else { p_Technique = p_Effect->GetTechniqueByName("Render"); int iControlCount = lMesh->GetControlPointsCount(); KFbxVector4 *lControlPoints = lMesh->GetControlPoints(); //lMesh->get Count = iControlCount; ESM_BASE_VERTEX* pVertices = new ESM_BASE_VERTEX[iControlCount]; for(int i = 0; i < iControlCount; i++) { float X, Y, Z; X = lControlPoints.GetAt(0); Y = lControlPoints.GetAt(1); Z = lControlPoints.GetAt(2); if(fabs(Y) < 1e-15) { Y = 0; } pVertices.Positon = D3DXVECTOR3(X, Y, Z); } bd.Usage = D3D10_USAGE_DEFAULT; bd.ByteWidth = sizeof(ESM_BASE_VERTEX) * iControlCount; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; bd.MiscFlags = 0; InitData.pSysMem = pVertices; } } void eecc::RenderMesh() { p_ViewVariable = p_Effect->GetVariableByName("View")->AsMatrix(); p_ProjectionVariable = p_Effect->GetVariableByName("Projection")->AsMatrix(); p_WorldVariable = p_Effect->GetVariableByName("World")->AsMatrix(); D3DXMatrixRotationX(&matRotX, float(DEG2RAD(0))); D3DXMatrixRotationY(&matRotY, float(DEG2RAD(0))); D3DXMatrixRotationZ(&matRotZ, float(DEG2RAD(0))); D3DXMatrixScaling(&matScl, 1, 1, 1); D3DXMatrixTranslation(&matPos, 0, 0, -10); matWorld = ((matRotX * matRotY * matRotZ) * matScl) * matPos; D3DXMatrixLookAtLH(&matView, new D3DXVECTOR3(0, 0, 0), new D3DXVECTOR3(0, 0, -10), new D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&matProjection, (float)DEG2RAD(45), (float)1920/(float)1080, 1, 1500); p_WorldVariable->SetMatrix(matWorld); p_ViewVariable->SetMatrix(matView); p_ProjectionVariable->SetMatrix(matProjection); D3D10_INPUT_ELEMENT_DESC elementDesc[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0}, }; UINT numElements = sizeof(elementDesc)/sizeof(elementDesc[0]); ID3D10InputLayout* pVertexLayout = NULL; D3D10_PASS_DESC PassDesc; p_Technique->GetPassByIndex(0)->GetDesc(&PassDesc); if(FAILED(p_Device->CreateInputLayout(elementDesc, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &pVertexLayout))) { Core->AddLine(L"IL Failed."); } p_Device->IASetInputLayout(pVertexLayout); if(FAILED(p_Device->CreateBuffer(&bd, &InitData, &p_VertexBuffer))) { Core->AddLine(L"Vertex Buffer Failed."); } D3D10_TECHNIQUE_DESC techDesc; p_Technique->GetDesc(&techDesc); for(UINT p = 0; p < techDesc.Passes; ++p) { UINT stride = sizeof(ESM_BASE_VERTEX); UINT offset = 0; p_Device->IASetVertexBuffers(0, 1, &p_VertexBuffer, &stride, &offset); p_Device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); p_Technique->GetPassByIndex(p)->Apply(0); p_Device->Draw(Count, 0); } } Could anybody point me in the correct direction for getting all of the vertex data? I have been following the simple import example, but again with the control points. My vertex count and control point count don't match, so I am convinced I am missing something somewhere. Thanks. //---------------------- I don't normally post for help on multiple forums, but I've been at this for 4 days now and I'm honestly lost. If anybody uses this SDK and can give me some advice I'd appreciate it. Thanks.
  4. AriusMyst

    Obama or McCain?

    All I heard tonight was "You suck." - "No, you suck.". Which at least made a welcome change from 2004's "You suck." - "Well, you may have a point, but you don't need to say it so often *sob* *sob*". I don't really know much about US domestic policy, and their foriegn policy is up to them imo, so it would be wrong of me to say who I thought gave the better answers. But in truth, not sure if I could pick one out anyway. They both seemed kind of flat really. Although, I would say I found McCain's implication that Obama wants to invade Pakistan amusing - not sure anybody fell for that but it was funny to see him try.
  5. AriusMyst

    Unresolved external symbol.. ?

    That works, guess I'm going to have read up on creating .libs. Thanks deadstar. :)
  6. This is confusing me a bit. I've written up some classes whilst I am learning D3D10. I decided to make a clean project. So I moved my classes into a directory, started a new project and added the directory as an additional library path. But now whenever I call any function from the classes I get lots of errors like this: Edited due to length. I'm not sure how to fix this, I know that C++ can find the headers cause if I write click and hit on "Open Document" it opens it. There is no .lib file involved either. I think maybe it can't find the cpp file that accompanies the header file, but I'm not sure how to fix this. Could anybody help me out? Thanks. [Edited by - AriusMyst on October 5, 2008 9:54:09 PM]
  7. AriusMyst

    how much does endorphine/euphoria cost?

    http://www.naturalmotion.com/sales.php You can download free learning editions here: http://www.naturalmotion.com/downloads.htm
  8. AriusMyst

    D3D10 Semantic debug error

    Quote:Original post by Adam_42 Just spotted something else with that data. The tangent is wrapped in round brackets while the other lines are in curly ones. That will make a big mess of the tangent data as it will combine it all into one with the comma operator! Did it not produce any compiler warnings? You sir are a genius and I am a fool. I have no idea why I had () instead of {}. Compiles and runs now, thank you very much for your help. :D
  9. AriusMyst

    D3D10 Semantic debug error

    Well spotted. Unfortunately it hasn't solved my problem, nor has D3D10_APPEND_ALIGNED_ELEMENT. It works if I don't attempt to pass tangent information so I'm pretty sure the shader itself is clean, but I'll post just in case. matrix World; matrix View; matrix Projection; matrix wvp; float3 LightPos = (0, 0, 5); Texture2D Diffuse; SamplerState sampleLinear { Filter = MIN_MAG_MIP_LINEAR; AddressU = Wrap; AddressV = Wrap; }; struct HOSTtoVERTEX { float4 PosOfVertex: POSITION; float3 Normal : NORMAL; // float3 Tangent : TANGENT; float2 UV : TEXCOORD; }; struct VERTEXtoFRAGMENT { float4 PosOfVertex: SV_POSITION; float3 Norm : TEXCOORD0; float3 LV : TEXCOORD1; float2 UV : TEXCOORD2; }; void VertexProgram(in HOSTtoVERTEX IN, out VERTEXtoFRAGMENT OUT) { float4 Pos = mul(IN.PosOfVertex, World); float4 PosWorld = mul(IN.PosOfVertex, World); Pos = mul(Pos, View); OUT.PosOfVertex = mul(Pos, Projection); OUT.LV = (PosWorld - LightPos); OUT.Norm = mul(IN.Normal, World); OUT.UV = IN.UV; } float4 FragmentProgram(in VERTEXtoFRAGMENT IN): SV_Target { float3 L = normalize(IN.LV); float3 N = IN.Norm; float D = dot(N, L); float3 C = Diffuse.Sample(sampleLinear, IN.UV); return D * float4(C, 1); // return float4(N, 1); } technique10 Render { pass pass0 { SetVertexShader(CompileShader(vs_4_0, VertexProgram())); SetGeometryShader(NULL); SetPixelShader(CompileShader(ps_4_0, FragmentProgram())); } }
  10. Just as a sidenote. You will need express 2005 and not 2008( unless you use XNA3 which I beleive is still in beta ). I kind of like using XNA with my 360, my only complaint is that the internet connection must be maintained( not the network connection, but the inet link ). I understand why this is, but it can be a little tedious if you're running Vista and like me you have those weird days where it simply refuses to maintain the connection. This can make debugging highly frustrating.
  11. Hello, I've started tinkering around in D3D10 and so far am having a nice time. But I've hit a snag. I keep getting the following error: D3D10: CORRUPTION: ID3D10Device::CreateInputLayout: Semantic name cannot be NULL (or pointer is corrupt). Declaration entry [3]. [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1 ] Now this is down to me trying to get tangent information in to my shader. Everything previously has worked. I am currently using an X file exported from Max9 using kw xport, I made sure the tangent data box was checked on export. I am loading it into D3D10 using the code found here: http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=316777&reply_id=2747161 Called in the following fashion: IDirect3DDevice9 *pDevice9; ID3DXMesh *pMesh9; CreateD3D9NullRef(&pDevice9); D3DXLoadMeshFromX(Filename.c_str(), D3DXMESH_SYSTEMMEM, pDevice9, NULL, NULL, NULL, NULL, &pMesh9); ID3DXMesh *sMesh; D3DVERTEXELEMENT9 test_decl[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, {0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0}, {0, 48, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0}, D3DDECL_END() }; pMesh9->CloneMesh(D3DXMESH_MANAGED, test_decl, pDevice9, &sMesh); D3DXComputeTangent(sMesh, 0, 0, 0, 0, NULL); CreateD3DX10MeshFromD3DX9Mesh(sMesh, &geom_Mesh, p_Device); geom_Mesh->CommitToDevice(); I am setting the IA like this: D3D10_INPUT_ELEMENT_DESC layout[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0}, {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0}, ("TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 36, D3D10_INPUT_PER_VERTEX_DATA, 0) }; UINT numElements = 4; D3D10_PASS_DESC PassDesc; if(FAILED(p_Technique->GetPassByIndex(0)->GetDesc(&PassDesc))) ERR_OUT("PassDesc FAILED"); p_Device->CreateInputLayout(layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &p_VertexLayout); p_Device->IASetInputLayout(p_VertexLayout); If I don't try to send the tangent data the mesh draws correctly, so I assume the mesh conversion from 9 to 10 is successful, but I am not knowledgable enough yet to know how to check this. I've also tried not calling D3DXComputeTangent. I'm hoping it's something simple in my element description but google turns up no real results when I google the error. Anybody have any tips or advice for me on this issue? Thanks.
  12. AriusMyst

    Another SSAO thread.

    Yes, you shouldn't be texturing anything( apart from your quad ). It's post-processing shader. Here is the 4 that I have. Although, I still don't have the bias in. Depth: float4x4 World : WORLDVIEW; float4x4 wViewProj: WORLDVIEWPROJ; struct a2v { float4 Position: POSITION0; float3 Normal : NORMAL; }; struct v2f { float4 Position: POSITION0; float Test : TEXCOORD0; float3 Normal : TEXCOORD1; }; struct f2s { float4 Colour : COLOR0; }; void vp(in a2v IN, out v2f OUT) { OUT.Position = mul(IN.Position, World); OUT.Test = length(OUT.Position.xyz); OUT.Position = mul(IN.Position, wViewProj); OUT.Normal = IN.Normal; } void fp(in v2f IN, out f2s OUT) { float Deep = IN.Test; float3 N = normalize(IN.Normal); OUT.Colour = float4(N.r, N.g, N.b, Deep); } technique { pass Pass0 { VertexShader = compile vs_1_1 vp(); PixelShader = compile ps_2_0 fp(); } } SSAO: float4x4 Projection: PROJECTION; texture Deepa; texture Rand; float SampleRadius = 0.84; float DistanceScale = 3.5; float OccludeDist = 7.5; float3 Direction; sampler2D DeepSample = sampler_state { Texture = (Deepa); MIPFILTER = LINEAR; MAGFILTER = LINEAR; MINFILTER = LINEAR; }; sampler2D RandSample = sampler_state { Texture = (Rand); MIPFILTER = LINEAR; MAGFILTER = LINEAR; MINFILTER = LINEAR; }; struct app2vp { float4 Position: POSITION; float2 UV : TEXCOORD0; }; struct vp2fp { float4 Position: POSITION; float2 UV : TEXCOORD0; float3 Corner : TEXCOORD1; }; struct fp2s { float4 Colour : COLOR0; }; void vp( in app2vp IN, out vp2fp OUT ) { OUT.Position = IN.Position; OUT.UV = IN.UV; float2 ScreenPos = IN.UV; ScreenPos.y = 1.0f - ScreenPos.y; ScreenPos = ScreenPos * 2 - 1; OUT.Corner = float3(IN.Position.xy, 1.0f) * Direction; } void fp( in vp2fp IN, out fp2s OUT ) { float4 Samples[16] = { float4(0.355512, -0.709318, -0.102371, 0.0 ), float4(0.534186, 0.71511, -0.115167, 0.0 ), float4(-0.87866, 0.157139, -0.115167, 0.0 ), float4(0.140679, -0.475516, -0.0639818, 0.0 ), float4(-0.0796121, 0.158842, -0.677075, 0.0 ), float4(-0.0759516, -0.101676, -0.483625, 0.0 ), float4(0.12493, -0.0223423, -0.483625, 0.0 ), float4(-0.0720074, 0.243395, -0.967251, 0.0 ), float4(-0.207641, 0.414286, 0.187755, 0.0 ), float4(-0.277332, -0.371262, 0.187755, 0.0 ), float4(0.63864, -0.114214, 0.262857, 0.0 ), float4(-0.184051, 0.622119, 0.262857, 0.0 ), float4(0.110007, -0.219486, 0.435574, 0.0 ), float4(0.235085, 0.314707, 0.696918, 0.0 ), float4(-0.290012, 0.0518654, 0.522688, 0.0 ), float4(0.0975089, -0.329594, 0.609803, 0.0 ) }; float fColour = 0.0f; float2 nUV = IN.UV; float Deep = tex2D(DeepSample, nUV).a; float3 Norm = tex2D(RandSample, IN.UV * 200).rgb; float3 SE = (normalize(IN.Corner) * Deep); for(int i = 0; i < 16; i++) { float3 Ray = reflect(Samples.xyz, Norm) * SampleRadius; float4 Sample = float4(Ray + SE, 1); float4 SS = mul(Sample, Projection); float2 sUV = 0.5 * (SS.xy/SS.w) + float2(0.5, 0.5); sUV.y = 1-sUV.y; float sDeep = tex2D(DeepSample, sUV).a; //this check is hacky, change it when you have time. if(length(Deep - sDeep) > OccludeDist) { fColour++; } else { float Occlude = DistanceScale * max(Deep - sDeep, 0); fColour += 1 / (1 + (Occlude * Occlude) * 0.1); } } fColour = fColour/16; OUT.Colour = float4(fColour, fColour, fColour, 1); } technique null { pass Pass0 { VertexShader = compile vs_3_0 vp(); PixelShader = compile ps_3_0 fp(); } } Blur: float2 Direction = float2(1.0f/1024.0f, 0); texture Deepa; texture SSAO; sampler2D DeepSample = sampler_state { Texture = (Deepa); MIPFILTER = LINEAR; MAGFILTER = LINEAR; MINFILTER = LINEAR; }; sampler2D SSAOSample = sampler_state { Texture = (SSAO); MIPFILTER = LINEAR; MAGFILTER = LINEAR; MINFILTER = LINEAR; }; struct a2v { float4 Position: POSITION0; float2 UV : TEXCOORD0; }; struct v2f { float4 Position: POSITION0; float2 UV : TEXCOORD0; }; void vp(in a2v IN, out v2f OUT) { OUT.Position = IN.Position; OUT.UV = IN.UV; } float4 fp(in v2f IN): COLOR0 { float Deep = tex2D(DeepSample, IN.UV).r; float3 Norm = tex2D(DeepSample, IN.UV).rgb; float AO = tex2D(SSAOSample, IN.UV).r; float Num = 1; int Sam = 32; for(int i = -Sam/2; i <= Sam/2; i+=1) { float2 nUV = float2(IN.UV + i * Direction.xy); float Sample = tex2D(SSAOSample, nUV).r; float3 sNorm = tex2D(DeepSample, nUV).rgb; if(dot(Norm, sNorm) > 0.99) { Num += (Sam/2 - abs(i)); AO += Sample * (Sam/2 - abs(i)); } } return AO / Num; } Composite: texture SSAOTex; texture SceneTexture; float2 PixelOffset = float2( 0.001953125, 0.001953125 ); sampler2D ScreenSampler: TEXUNIT0 = sampler_state { Texture = (SceneTexture); }; sampler2D SSAOSampler: TEXUNIT0 = sampler_state { Texture = (SSAOTex); }; struct a2v { float4 Position: POSITION; float2 UV : TEXCOORD0; }; struct v2p { float4 Position: POSITION; float2 UV : TEXCOORD0; }; struct p2s { float4 Colour : COLOR0; }; void vp( in a2v IN, out v2p OUT ) { OUT.Position = IN.Position; OUT.UV = IN.UV; } void fp( in v2p IN, out p2s OUT ) { float4 Scene = tex2D(ScreenSampler, IN.UV); float4 SSAO = tex2D(SSAOSampler, IN.UV); float4 Grin = SSAO.r * Scene; OUT.Colour = Grin; OUT.Colour.a = 1; } technique null { pass Pass0 { VertexShader = compile vs_1_1 vp(); PixelShader = compile ps_2_0 fp(); } } Edit: Forgot to add. For these shaders, I had no need to modify the co-ords because the engine I am using for this sample does it for me. You may very well need to do this yourself. Anyway, I hope the code helps somewhat. I had a bitch of a time getting it up, it seems a twitchy technique. Good luck. :) [Edited by - AriusMyst on June 14, 2008 9:29:28 AM]
  13. AriusMyst

    Another SSAO thread.

    Well, you're doing it differently to me. But if you notice in the one I posted, I am grabbing the depth from world space - not world view projection space. Maybe there is something in that. Good luck :D.
  14. AriusMyst

    Another SSAO thread.

    Ahh yes, I understand now. I was being dense. Thanks again Agi, you've been very helpful :).
  15. AriusMyst

    Another SSAO thread.

    Actually, scrap that. The higher the resolution the worse the walls get: http://azazeldev.org/ssao/planes.jpg I'm not sure what you mean by the bias, I've tried doing this: float Deep = tex2D(DeepSample, nUV).a; float3 Bias = tex2D(DeepSample, nUV).rgb; float3 Norm = tex2D(RandSample, IN.UV * 200).rgb * Bias; I figured that was wrong, but thought I'd give it a shot anyway. I tried reading your thread here( http://www.gamedev.net/community/forums/topic.asp?topic_id=497072 ) but not sure if that is the thread you meant.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!