Advertisement Jump to content
  • Advertisement

h3ro

Member
  • Content Count

    191
  • Joined

  • Last visited

Community Reputation

161 Neutral

1 Follower

About h3ro

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I am having some problems with calculating my viewing angle for stepping into the height map when doing relief mapping. The relief mapping is working, at least kind of. Currently it is only displays the correct result in the positive Z axis (up). float3 viewDir = fragment.fragmentWorldPos.xyz - cameraPosition; float3 viewDirNormal = normalize(viewDir); float rayX = dot(worldNormTangent.xyz, -viewDirNormal); float rayY = dot(worldNormBinormal.xyz, viewDirNormal); float rayZ = dot(worldNormNormal.xyz, viewDirNormal); float3 rayDir = float3(rayX,rayY,rayZ); rayDir *= depthScale / rayDir.z; float2 textureOffsetDirection = rayDir.xy; Any help would be greatly appreciated
  2. h3ro

    Extraction

    Extraction is a university group project where we wanted to create and addictive 3D top down shooter. <br /><br />We are all graduating this year and looking for full time roles within the industry.<br /><br />Programming:<br /><br />Ole Kristian Homelien <br />Michael Mackie - www.michaelmackie.co.uk<br />Alex Laurent <br />Ryan Sullivan<br /> <br />Art:<br /><br />Carl Button - carlbutton.carbonmade.com<br />Matt Oakley - schoolshoes.carbonmade.com <br />Tom Wilkinson<br />Ian Price<br /><br />Animation:<br /><br />Adrian Hartill
  3. I had the solid sphere working, but was struggling with the hollow sphere. I found the code for it on "http://www.realtimerendering.com/intersections.html". From what I can understand that approach is a bit different from yours, I would be interested to hear which one you think is the most efficient one.
  4. Some help would be greatly appreciated. Im trying to write a function for creating a sparse octree voxel mesh from a sphere and I just cant seem to get it right.
  5. Hallo, I am trying to find out if a sphere intersects a AABB, but in my case the sphere does not have a volume. Im only interested in intersections if the sphere edges intersects the AABB. Is there any known algorithms for this? Thanks,
  6. Hallo, I am trying to build a program that allows you do modify a voxel mesh using the mouse as a brush. Currently I am trying to figure out which voxels should be updates as the user moves the mouse around. My best idea so far is to use a sphere and whenever the user presses the draw button I remove all the voxels inside of the sphere and add new voxels around the edge of the sphere. The problem with this is that you would end up with a layer of voxels on the inside of the mesh (the back of the sphere) and you would no longer have a sparse octree. Is there any well defined methods for solving this?
  7. Hallo, I am working on a game where there is a post processing filter that runs on the final frame of the game. The strength of this filter is controlled by a seperate render target, so for every pixel I compute the filter value and lerp it with the original value based on the value found in the other rendering target. This works fine, but xna (directx 9) does not support MSAA when using multiple rendering targets so I am looking for a way of getting around the need for having that second render target. Is there any way I can pack some of the data in the main render target or is there any texture formats with an 'extraData' attribute I can use? I was toying with the idea of using half the bits in the alpha for the original render target as the filter value, but that would mess up the alpha blending in the game. Any ideas?
  8. I have had a look at them, but they dont seem to be very efficent for actually updating data on the fly?
  9. Hallo, I am looking for a good acceleration structure that allows me to move data around at run time without extremely high cost. I am working on a voxel render and I need to be able to modify any part of the data set at any time. The voxel data set will not have any transparency and only a small subset of the data will be edited at any time. Any ideas on what I should look into? Thanks
  10. Thats it! Cant belive i didnt think of trying that. Thanks!
  11. Hallo, Im trying to add some more data to my vertex data structure. Im trying to add a vector2 for each instance of a model, but I cant get it to work and was wondering if anyone could give me a nudge in the right direction. The objects render, but the data in textcoord5 is random. Thanks The initialize stage, where I create the extra vertex element to pass to the shader // Create the extra data VertexElement[] extraElements = new VertexElement[5]; // 4 * vector4 (matrix) + 2 * float (vector2) for (int i = 0; i < extraElements.Length-1; i++) { short matrixOffset = (short)(sizeof(float) * 4 * i); extraElements = new VertexElement(1, matrixOffset, VertexElementFormat.Vector4, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, (byte)(i+1)); } short extraOffset = (short)(sizeof(float) * 4 * 4); extraElements[4] = new VertexElement(2, extraOffset, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 5); // Put it in there VertexElement[] oldVertexDeclaration = m_vertexDeclaration.GetVertexElements(); VertexElement[] elements = new VertexElement[oldVertexDeclaration.Length + extraElements.Length]; oldVertexDeclaration.CopyTo(elements, 0); extraElements.CopyTo(elements, oldVertexDeclaration.Length); // Repalce the vertex declaration m_vertexDeclaration.Dispose(); m_vertexDeclaration = new VertexDeclaration(device, elements); The render stage, currently the data it passes is not very usefull, its only for testing. public void Draw(GraphicsDevice device, Effect effect, Matrix[] instanceTransforms) { // Temp! Vector2[] otherData = new Vector2[instanceTransforms.Length]; for (int i = 0; i < instanceTransforms.Length; i++) { float t = (float)i / (float)instanceTransforms.Length; otherData = new Vector2(t, 0); } device.VertexDeclaration = m_vertexDeclaration; device.Vertices[0].SetSource(m_vertexBuffer, 0, m_vertexStride); device.Indices = m_indexBuffer; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); // make sure there is enough space in out buffer to pass the instance data, recalculate it if needed. // not the best way of doing it, but I think it should be fine int matrixDataSize = sizeof(float) * 16 * instanceTransforms.Length; int extraDataSize = sizeof(float) * 2 * otherData.Length; // Matrix data if ((m_instanceMatrixStream == null) || (m_instanceMatrixStream.SizeInBytes < matrixDataSize)) { if (m_instanceMatrixStream != null) m_instanceMatrixStream.Dispose(); m_instanceMatrixStream = new DynamicVertexBuffer(device, matrixDataSize, BufferUsage.WriteOnly); } m_instanceMatrixStream.SetData(instanceTransforms, 0, instanceTransforms.Length, SetDataOptions.Discard); // Extra data if ((m_instanceExtraDataStream == null) || (m_instanceExtraDataStream.SizeInBytes < extraDataSize)) { if (m_instanceExtraDataStream != null) m_instanceExtraDataStream.Dispose(); m_instanceExtraDataStream = new DynamicVertexBuffer(device, extraDataSize, BufferUsage.WriteOnly); } m_instanceExtraDataStream.SetData(otherData, 0, otherData.Length, SetDataOptions.Discard); // Set the current draw process to use the data VertexStreamCollection vertices = device.Vertices; vertices[0].SetFrequencyOfIndexData(instanceTransforms.Length); vertices[1].SetSource(m_instanceMatrixStream, 0, sizeof(float) * 16); vertices[1].SetFrequencyOfInstanceData(1); vertices[2].SetSource(m_instanceExtraDataStream, 0, sizeof(float) * 2); vertices[2].SetFrequencyOfInstanceData(1); // Draw the model device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_vertexCount, 0, m_indexCount / 3); // Reset the streams to make sure they are not used later vertices[0].SetSource(null, 0, 0); vertices[1].SetSource(null, 0, 0); vertices[2].SetSource(null, 0, 0); pass.End(); } effect.End(); } The vertex shader VertexShaderOutput InstancingVertexShader(VertexShaderInput input, float4x4 instanceTransform : TEXCOORD1, float2 extraData : TEXCOORD5) { return VertexShader(input, transpose(instanceTransform), extraData); }
  12. Hallo, I am trying to create a shadowm map for a directional light, but im running into some problems. For some reason it looks like only object very close to the camera appears on the shadow map. Its the first time im attempting this and would be greatfull for some pointers. Xna: // Find the world position of the 8 corners of the view frustum // then find the center of it, this is the point that we will aim // our light to BoundingFrustum frustum = new BoundingFrustum(renderCameraViewProjection); Vector3[] cameraFrustumCornersWorld = frustum.GetCorners(); Vector3 cameraFrustumCenterPos = Vector3.Zero; for (int i = 0; i < 8; i++) cameraFrustumCenterPos += cameraFrustumCornersWorld; cameraFrustumCenterPos /= 8.0f; // Create a lookat matrix for the light, looking at the center of // the view view frustum float distance = Math.Abs(frustum.Near.D) + Math.Abs(frustum.Far.D); Vector3 cameraPos = cameraFrustumCenterPos + (lightDir * distance); Matrix lightViewMatrix = Matrix.CreateLookAt(cameraPos, cameraFrustumCenterPos, Vector3.Left); // Find the world position of the 8 corners of the light frustum so // we can use it to create a orthographic project matrix Vector3[] frustumCornersLightSpace = new Vector3[8]; for (int i = 0; i < 8; i++) frustumCornersLightSpace = Vector3.Transform(cameraFrustumCornersWorld, lightViewMatrix); // Create a bounding box and use the vertexes as the verts for the view frustum BoundingBox box = BoundingBox.CreateFromPoints(frustumCornersLightSpace); float left = box.Min.X; float right = box.Max.X; float bottom = box.Min.Y; float top = box.Max.Y; float zNear = -box.Max.Z; float zFar = -box.Min.Z; Matrix lightProjectionMatrix = Matrix.CreateOrthographicOffCenter(left, right, bottom, top, zNear, zFar); // The final projection matrix for the light lightViewProjection = lightViewMatrix * lightProjectionMatrix;
  13. Thanks a lot for you post, sometimes the internet makes me question why I need to spend lots of money to go to university. It seems like there is no perfect way of having a shader that can handle lights like I want it to. Do you know how this is handled in big games? Do they simply only allow you to use say spotlights with different parameters? I think I will go with option 1, in combination with removing directional lights and combining spotlights and point lights into one light type. I'm assuming combing the two lights type into one should not be hard as its pretty much the same calculation and data. I'm not worried about the performance loss on older hardware. It's for a university project and as long as it runs on the university computers its fine. I would love to look into option 2, but I can't really afford to at the moment. I'm very interested in how this would change if I were using directx 10 or 11. Thanks again,
  14. Actually, there is no if statments at all in my code. If the compiler is unrolling my loops like that, will it not be a very expensive shader? What im trying to do is write a shader that supports a given number of lights, but they can all be of different types. I dont want 8 point lights, 8 directional lights and 8 spotlights, but 8 lights in total. I think I might be missing something here? Here is the actuall calc code if anyone is interested // --------------------------------------------------------------------------------------------- // PointLight // --------------------------------------------------------------------------------------------- struct PointLight { float3 Position; float3 Colour; float Intensety; float MaxRange; float Falloff; }; float3 CalcPointLight(PointLight light, float3 fragmentWorldPos, float3 N, float3 dirToCamera, float3 diffuseColour, float3 specularColour, float specularPower, float specularIntensity) { // Light calculations const float3 L = normalize(light.Position - fragmentWorldPos); const float3 R = normalize(reflect(-L, N)); const float distToLight = length(light.Position - fragmentWorldPos); const float LightIntensity = pow(saturate((light.MaxRange - distToLight) / light.MaxRange), light.Falloff); // Lambert float Li = saturate(dot(L, N)); // Specular float Si = pow(saturate(dot(R, dirToCamera)), specularPower) * specularIntensity; return (Li * diffuseColour) + (Si * specularColour) * light.Intensety ; } // --------------------------------------------------------------------------------------------- // SpotLight // --------------------------------------------------------------------------------------------- struct SpotLight { float3 Position; float3 Colour; float3 Direction; float InnerAngle; float OuterAngle; float Intensety; }; float3 CalcSpotLight(SpotLight light, float3 fragmentWorldPos, float3 N, float3 dirToCamera, float3 diffuseColour, float3 specularColour, float specularPower, float specularIntensity ) { // Light calculations const float3 L = normalize(fragmentWorldPos - light.Position ); const float3 R = normalize(reflect(L, N)); // Spotlight stuff const float spotPower = dot(L, light.Direction); const float innerPower = cos(light.InnerAngle / 2.0f); const float outerPower = cos(light.OuterAngle / 2.0f); const float spotIntensity = saturate((spotPower - outerPower) / (innerPower - outerPower)); // Lambert light const float Li = saturate(dot(-L, N)); // Specular const float Si = pow(saturate(dot(R, dirToCamera)), specularPower) * specularIntensity; return ((Li * diffuseColour ) + (Si *specularColour)) * spotIntensity; } // --------------------------------------------------------------------------------------------- // DirectionalLight // --------------------------------------------------------------------------------------------- struct DirectionalLight { float3 Position; float3 Colour; float3 Direction; float Intensety; float SpecIntensety; }; float3 CalcDirectionalLight(DirectionalLight light, float3 fragmentWorldPos, float3 N, float3 dirToCamera, float3 diffuseColour, float3 specularColour, float specularPower, float specularIntensity ) { // Light calculations const float3 L = light.Direction; const float3 R = normalize(reflect(L, N)); // Lambert light float3 Li = saturate(dot(N, -L)); // Specular const float Si = pow(saturate(dot(R, dirToCamera)), specularPower) * specularIntensity; return (diffuseColour * Li) + (Si * specularColour); }
  15. Hallo, Im working on making a shader that suppports point, directional and spot lights. I have it all working, but when I try to compile the shader in release mode I get the following error: error X4550: maximum boolean register index exceeded - Try reducing number of constant branches This makes me believe that im doing stuff in a very very bad way. I would appreciate if someone could have a look at my shader code and point me in the right direction #include "LightCalculations.fx" // Transforms float4x4 world_xform; float4x4 view_xform; float4x4 projection_xform; float4x4 mvp_xform; float4x4 invView_xform; // Matrial float3 diffuseColor; float3 specularColor; float specularIntensity; float specularPower; // Lights PointLight pointLights[8]; SpotLight spotLights[8]; DirectionalLight dirLights[8]; int numPointLights; int numSpotLights; int numDirLights; struct VertexShaderOutput { float4 Position : POSITION; float2 TexCoords : TEXCOORD0; float3 WorldNormal : TEXCOORD1; float3 WorldPosition : TEXCOORD2; }; struct VertexShaderInput { float4 Position : POSITION0; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; output.Position = mul(input.Position, mvp_xform); output.WorldNormal = mul(float4(input.Normal, 0), world_xform); output.WorldPosition = mul(input.Position, world_xform); output.TexCoords = input.TexCoord; return output; } float4 PixelShaderFunction(VertexShaderOutput input) { const float4 worldCamPos = mul(float4(0,0,0,1), invView_xform); const float3 N = normalize(input.WorldNormal); const float3 dirToCam = normalize(worldCamPos - input.WorldPosition); float3 finalColour = float3(0,0,0); for(int i = 0; i < numPointLights; i++) { finalColour += CalcPointLight(pointLights, input.WorldPosition, N, dirToCam, diffuseColor, specularColor, specularPower, specularIntensity); } for(int i = 0; i < numSpotLights; i++) { finalColour += CalcSpotLight(spotLights, input.WorldPosition, N, dirToCam, diffuseColor, specularColor, specularPower, specularIntensity); } for(int i = 0; i < numDirLights; i++) { finalColour += CalcDirectionalLight(dirLights, input.WorldPosition, N, dirToCam, diffuseColor, specularColor, specularPower, specularIntensity); } return float4(finalColour, 1); } technique Technique1 { pass Pass1 { VertexShader = compile vs_3_0 VertexShaderFunction(); PixelShader = compile ps_3_0 PixelShaderFunction(); } } thanks [Edited by - h3ro on October 31, 2010 2:58:34 PM]
  • 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!