# B. /

Member

38

2 Neutral

• Rank
Member

• Interests
Art
Design
Programming

## Recent Profile Visitors

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

1. ## Direction Light, Orthographic Matrix Problem

Hi ChuckNovice, thank you very much for your answer, i will check this up Greets Benjamin
2. ## DX11 Direction Light, Orthographic Matrix Problem

Hi Guys, i want to draw shadows of a direction light but the shadows always disappear, if i translate my mesh (cube) in the world to far of the bounds of my orthographic projection matrix. That my code (Based of an XNA sample i recode for my project): // Matrix with that will rotate in points the direction of the light Matrix lightRotation = Matrix.LookAtLH(Vector3.Zero, lightDir, Vector3.Up); BoundingFrustum cameraFrustum = new BoundingFrustum(Matrix.Identity); // Get the corners of the frustum Vector3[] frustumCorners = cameraFrustum.GetCorners(); // Transform the positions of the corners into the direction of the light for (int i = 0; i < frustumCorners.Length; i++) frustumCorners[i] = Vector4F.ToVector3(Vector3.Transform(frustumCorners[i], lightRotation)); // Find the smallest box around the points BoundingBox lightBox = BoundingBox.FromPoints(frustumCorners); Vector3 boxSize = lightBox.Maximum - lightBox.Minimum; Vector3 halfBoxSize = boxSize * 0.5f; // The position of the light should be in the center of the back pannel of the box. Vector3 lightPosition = lightBox.Minimum + halfBoxSize; lightPosition.Z = lightBox.Minimum.Z; // We need the position back in world coordinates so we transform // the light position by the inverse of the lights rotation lightPosition = Vector4F.ToVector3(Vector3.Transform(lightPosition, Matrix.Invert(lightRotation))); // Create the view matrix for the light this.view = Matrix.LookAtLH(lightPosition, lightPosition + lightDir, Vector3.Up); // Create the projection matrix for the light // The projection is orthographic since we are using a directional light int amount = 25; this.projection = Matrix.OrthoOffCenterLH(boxSize.X - amount, boxSize.X + amount, boxSize.Y + amount, boxSize.Y - amount, -boxSize.Z - amount, boxSize.Z + amount); I believe the bug is by cameraFrustum to set a Matrix Idetity. I also tried with a Translation Matrix of my Camera Position and also the View Matrix of my Camera, but without success Can anyone tell me, how to draw shadows of my direction light always where my camera is current in my scene? Greets Benjamin

ps. Ok, if i change the width and height (befor was 1920x1080) to smaller like 100x100 i see now Shadows, but is that the correct way?

Hi Joe, I recode my update function to orthogonal projection: public void Update(float renderTargetWidth, float renderTargetHeight, float near, float far) { this.direction = this.space.LocalLook; this.view = Matrix.LookAtLH(this.space.Translate, this.space.Translate + this.space.LocalLook, this.space.LocalUp); this.projection = Matrix.OrthoLH(renderTargetWidth, renderTargetHeight, 0.1f, 1500.0f); } But now I see no shadows anymore, just this on the image (Bias Value is 0.001f) Do I had something forget? Tried also in the ShadowMap Shader only to multiply worldpos with only LightProjection. Result was even worser, nothing see Greets Benjamin

Hi Joe, my current direction light has more the behavior of a point light in Shadow drawing, as a direction light. In the SimpleShader i calculate the shadows with the view and projection matrix of a light, that i create a the CPU on a Update Fuction in my Light Class // Space is a Class where I store Transformation Informations of the World Space Matrix and Side/Up/Look Vectors etc. of the Light // Translate is the Postion of the Light public void Update(float renderTargetWidth, float renderTargetHeight) { this.direction = this.space.LocalLook; this.view = Matrix.LookAtLH(this.space.Translate, this.space.Translate + this.space.LocalLook, this.space.LocalUp); this.projection = Matrix.PerspectiveFovLH(Math.DegreesToRadians(45.0f), renderTargetWidth / renderTargetHeight, 0.1f, 1000.0f); } But i am a totally noob in Light and Shadow Stuff. So i need to start from the beginning. In Graphics and Game Engine like Maya, Unity etc. if i create a direction light, all geometries will lighting from the direction of the light. I do this with: float3 lightFront = LightColor * saturate(dot(Nn, -Ln)); (Ln = Light Direction of my DirectionLight). But how works it with the shadows, there are must be a fix positon, where the light source looks of all geometries from far, far away, always in the right angle, i imagine? Can someone explain me it, how a direction light calculate all the shadows in the whole scene with a view and projection matrix? Greets Benjamin

OMG, you right, it works!!!!!!!!!!!!!!!! I love you Andrey, just kidding Now I see only the shadow of my cube But i think two things are still strange. The first one is: I normalize input.Normal in the VertexShader and if i don't normalize the normalized value again in the Pixel Shader by float3 Nn = normalize(input.Normal); my lighting result of all geometries will be darker. Why i need to normalize a normalized value again to get right lighting results? And the second one is: If i rotate my direction light in my scene, my light look direction vector will be rotate right, that i see on two things. my visual light arrow in the scene and the black light view space that i saw befor in the bug, both rotate in the same direction as my direction light. But not the shadow it self. There it's seems to be, only change the position/stretch angle, if i tranlate the light postion and he always looks in the center 0 0 0 of the scene? But i want that the shadow draw in the same direction as my light direction? Greets Benjamin ps. Updated Shader in the attachment SimpleShader.fx

9. ## SharpDX Direct2D1 Device (System.AccessViolationException)

ps. I saw, i miss to set the RenderTarget to the d2dDevice, but can't find a property to set it?
10. ## SharpDX Direct2D1 Device (System.AccessViolationException)

Hello ChuckNovice, thank you very much for your help I recode my function and now i get in d2dDevice.EndDraw an error: HRESULT: [0x88990001], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_WRONG_STATE/WrongState] Heres my code: (Where do i set the wrong state?) Factory factory = new Factory(); Device d3d11Device = new Device(factory.GetAdapter(0), DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport); SwapChainDescription swapChainDescription = new SwapChainDescription(); swapChainDescription.SampleDescription = new SampleDescription(1, 0); swapChainDescription.BufferCount = 1; swapChainDescription.OutputHandle = this.Handle; swapChainDescription.IsWindowed = true; swapChainDescription.Usage = Usage.RenderTargetOutput; swapChainDescription.ModeDescription = new ModeDescription(this.Width, this.Height, new Rational(75, 1), Format.B8G8R8A8_UNorm); SwapChain swapChain = new SwapChain(factory, d3d11Device, swapChainDescription); DeviceContextRenderTarget d2dDevice = new DeviceContextRenderTarget(new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded), new RenderTargetProperties(new PixelFormat(swapChain.Description.ModeDescription.Format, AlphaMode.Ignore))); TextFormat format = new TextFormat(new SharpDX.DirectWrite.Factory(), "Arial", 1.0f); Surface surface = swapChain.GetBackBuffer<Surface>(0); RenderTarget renderTarget = new RenderTarget(d2dDevice.Factory, surface, new RenderTargetProperties(d2dDevice.PixelFormat)); SolidColorBrush brush = new SolidColorBrush(renderTarget, SharpDX.Color4.Black); d2dDevice.Clear(Color4.Black); d2dDevice.BeginDraw(); d2dDevice.DrawText("Hello World", format, new SharpDX.RectangleF(0, 0, 100, 100), brush); d2dDevice.EndDraw(); Greets Benjamin
11. ## 2D SharpDX Direct2D1 Device (System.AccessViolationException)

Hello Guys, I have a problem, i want to draw a Text with Direct2D1 in SharpDX and everytime i create a DeviceContext with my 2Ddevice, i get a System.AccessViolationException Heres my code: (this.Handle = Handle of my Form) Device d2dDevice = new Device(this.Handle); DeviceContext d2dContext = new DeviceContext(d2dDevice, DeviceContextOptions.None); Can someone explain me wehre my mistake is? Greets Benjamin
12. ## GPU Skinning Problem

I know it's a little bit late, but better late as never I figure out for a couple of weeks how to handle my problem For a correct Animation play you need to send the Shader the InverseSourceSpace you load from the COLLADA FILE * the and the calculate world target space as bone matrices. You calculate bone world space from all the local space of the bone hierarchy and if you have animations on a bone you take the aniamtion matrix instead of the local matrix of the bone And in the shader you need to multipy the vertex 1. with the bindposematrix, 2. with the skin transform matrix and 3. with the world matrix and everything works correct I post this description to say thank you to the gamedev community and especially to JoeJ and turanszkij that you helped me with my problem and bring me in the right direction for the solution Greets Benjamin
13. ## GPU Skinning Problem

So the next problem is i saw. That i need the world space joint matrices from the controller lib, because they are the world space matrices of the bind pose of the mesh. For a sample, i start a animation not from the bind pose, than first i need first to set the vertices in the right space and that i only can do, if i have the source space of the bind pose. And the visual lib has only the local matrices of the first animation space. So i calculate the animation m_ws from the visual lib m_ls and the bone m_ws from the controller lib (because the controller lib has only the inverse value, so i invert it)
14. ## GPU Skinning Problem

ps. I update my code to calculate the local matrices from the animations to world matrices with this: public static void TransformHierachy(Joint joint, Matrix parentMatrix) { Matrix result = joint.ObjectSpace.Matrix * parentMatrix; joint.ObjectSpace.Set(result); if(joint.HasAnimations) for (int i = 0; i < joint.Animations[0].AnimationMatrices.Length; i++) joint.Animations[0].AnimationMatrices[i] = joint.Animations[0].AnimationMatrices[i] * parentMatrix; foreach (Joint child in joint.Children) TransformHierachy(child, result); } It works like befor, the source and target space are now similar, the mesh will not deform, but the problem is still there. pps. I think my code is doing the same as yours right?
15. ## GPU Skinning Problem

I go only recursively up from the parents to the root But i tried now your code to calculate the bone local matrices to world matrices and your code, start from the root is very good and easy to understand and do this And the Preview Skeleton will draw correct too In my code i send the root bone (Joint1) and a Matrix Idetity to the function public static void TransformHierachy(Joint joint, Matrix parentMatrix) { Matrix result = joint.ObjectSpace.Matrix * parentMatrix; joint.ObjectSpace.Set(result); foreach (Joint child in joint.Children) TransformHierachy(child, result); } So but whats now if the animation local matrices, they need to calculate from local to world space too, right? It's so confuse to understand how the interpretation of Autodesk Exporter is. Because the Collada Exporter from Autodesk is differnt as the OpenCollada Exporter. In Autodesk i can choose between single matrix or scale, rotate and translate values, but this has only a effect to the visual lib, not the controller lib. OpenCollada Exporter do only export rotate and translate values and hasn't in the animation lib any of target space matrices x.x