Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

2317 Excellent

About KaiserJohan

  • Rank

Personal Information

  • Role
  • Interests

Recent Profile Visitors

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

  1. KaiserJohan

    Smooth normals and Tessellation

    Any pointers are much appreciated 🙂
  2. KaiserJohan

    Smooth normals and Tessellation

    Hmm.. how am I changing the heights after generating the normals? It's all done in a previous shader stage? > - Calculate in the domain shader based on heightmap sampling I suppose this seems like a solid option. Will the normals be correctly interpolated in the pixel shader? Is there anything different from calculating normals in domain shader from say how you typically do it in a simple vertex shader?
  3. KaiserJohan

    Smooth normals and Tessellation

    I managed to produce normals in the pixel shader using the screen-space derivates of the view position from the domain shader like this [domain("quad")] DomainOut domain_main(PatchTess patchTess, float2 uv : SV_DomainLocation, const OutputPatch<HullOut, 4> quad) { DomainOut ret; float2 topMidpointWorld = lerp( quad[ 0 ].mWorldPosition.xz, quad[ 1 ].mWorldPosition.xz, uv.x ); float2 bottomMidpointWorld = lerp( quad[ 3 ].mWorldPosition.xz, quad[ 2 ].mWorldPosition.xz, uv.x ); float2 midPointWorld = lerp( topMidpointWorld, bottomMidpointWorld, uv.y ); float3 topMidpointN = lerp( quad[ 0 ].mWorldNormal.xyz, quad[ 1 ].mWorldNormal.xyz, uv.x ); float3 bottomMidpointN = lerp( quad[ 3 ].mWorldNormal.xyz, quad[ 2 ].mWorldNormal.xyz, uv.x ); float3 midPointN = lerp( topMidpointN, bottomMidpointN, uv.y ); float2 topMidpointTexcoord = lerp( quad[ 0 ].mTexcoord, quad[ 1 ].mTexcoord, uv.x ); float2 bottomMidpointTexcoord = lerp( quad[ 3 ].mTexcoord, quad[ 2 ].mTexcoord, uv.x ); float2 midPointTexcoord = lerp( topMidpointTexcoord, bottomMidpointTexcoord, uv.y ); float y = quad[ 0 ].mWorldPosition.y; y += ( gHeightmap.SampleLevel( gPointSampler, midPointTexcoord, 0.0f ).r * gHeightModifier ); ret.mPosition = float4( midPointWorld.x, y, midPointWorld.y, 1 ); ret.mViewPosition = mul( gFrameView, ret.mPosition ); ret.mPosition = mul( gFrameViewProj, ret.mPosition ); ret.mTexcoord = midPointTexcoord; return ret; } struct PixelOut { float4 mDiffuse : SV_Target0; float3 mNormal : SV_Target1; }; PixelOut ps_main(DomainOut input) { PixelOut ret; float3 dFdxPos = ddx( input.mViewPosition.xyz ); float3 dFdyPos = ddy( input.mViewPosition.xyz ); ret.mNormal = normalize( cross( dFdxPos, dFdyPos ) ); ret.mNormal += 1.0f; ret.mNormal *= 0.5f; ret.mDiffuse = float4( 0.0f, 1.0f, 1.0f, 1.0f); return ret; } It gives me flat shading per tessellated vertex however Is there a better way to produce actual smooth normals? This just isn't good enough 😐
  4. Hello, I'm doing tessellation and while I got the positions setup correctly using quads I am at a loss how to generate smooth normals from them. I suppose this should be done in the Domain shader but how would this process look like? I am using a heightmap for tessellation but I would rather generate the normals from the geometry than use a normal map, if possible. Cheers
  5. I know this might come of as ranting but I recently came back from being a relatively active poster/browser and in my humble opinion navigation has become strictly worse in every regards. I remember a more clean and neat design, it's difficult to find the usual forums I look at and theres ads everywhere. What happened?
  6. KaiserJohan

    Strange tessellation pattern

    Still wierd sadly. Must be something wrong with the shaders but I cant figure out why? The vertex/index buffers must be legit as per first screenshot is fine...
  7. Am trying a basebones tessellation shader and getting unexpected result when increasing the tessellation factor. Am rendering a group of quads and trying to apply tessellation to them. OutsideTess = (1,1,1,1), InsideTess= (1,1) OutsideTess = (1,1,1,1), InsideTess= (2,1) I expected 4 triangles in the quad, not two. Any idea of whats wrong? Structs: struct PatchTess { float mEdgeTess[4] : SV_TessFactor; float mInsideTess[2] : SV_InsideTessFactor; }; struct VertexOut { float4 mWorldPosition : POSITION; float mTessFactor : TESS; }; struct DomainOut { float4 mWorldPosition : SV_POSITION; }; struct HullOut { float4 mWorldPosition : POSITION; }; Hull shader: PatchTess PatchHS(InputPatch<VertexOut, 3> inputVertices) { PatchTess patch; patch.mEdgeTess[ 0 ] = 1; patch.mEdgeTess[ 1 ] = 1; patch.mEdgeTess[ 2 ] = 1; patch.mEdgeTess[ 3 ] = 1; patch.mInsideTess[ 0 ] = 2; patch.mInsideTess[ 1 ] = 1; return patch; } [domain("quad")] [partitioning("fractional_odd")] [outputtopology("triangle_ccw")] [outputcontrolpoints(4)] [patchconstantfunc("PatchHS")] [maxtessfactor( 64.0 )] HullOut hull_main(InputPatch<VertexOut, 3> verticeData, uint index : SV_OutputControlPointID) { HullOut ret; ret.mWorldPosition = verticeData[index].mWorldPosition; return ret; } Domain shader: [domain("quad")] DomainOut domain_main(PatchTess patchTess, float2 uv : SV_DomainLocation, const OutputPatch<HullOut, 4> quad) { DomainOut ret; const float MipInterval = 20.0f; ret.mWorldPosition.xz = quad[ 0 ].mWorldPosition.xz * ( 1.0f - uv.x ) * ( 1.0f - uv.y ) + quad[ 1 ].mWorldPosition.xz * uv.x * ( 1.0f - uv.y ) + quad[ 2 ].mWorldPosition.xz * ( 1.0f - uv.x ) * uv.y + quad[ 3 ].mWorldPosition.xz * uv.x * uv.y ; ret.mWorldPosition.y = quad[ 0 ].mWorldPosition.y; ret.mWorldPosition.w = 1; ret.mWorldPosition = mul( gFrameViewProj, ret.mWorldPosition ); return ret; } Any ideas what could be wrong with these shaders?
  8. KaiserJohan

    StructuredBuffer and matrix layout

    Sorry for bump but I just stumbled upon this recently. Was frustrated as I already had my matrices column-major when sending to the shader so I couldn't understand why it got sampled transposed. I just transposed() the matrix after sampling in the shader.
  9. I need to bind a shader resource as a structured buffer. Textures (t#) and constant buffers (b#) are listed as expected but not StructuredBuffers? I've looked at https://msdn.microsoft.com/en-us/library/windows/desktop/dd607359(v=vs.85).aspx and it still puzzles me - what is the register type used for Structured Buffers in HLSL?
  10. Just a really quick question - is there any overhead to using DrawIndexedInstanced even for geometry you just render once vs using DrawIndexed? Or is the details obfuscated by the graphics driver? I would assume no but you never know
  11. KaiserJohan

    Terrain tessellation and frustum culling

      Makes sense. The 'BoundsY' for a quad is calculated on the CPU once by reading the heightmap and making an AABB? Can this be used in conjunction with other terrain tessellation alghorithms (like http://www.frostbite.com/wp-content/uploads/2013/05/adaptive_terrain_tessellation.pdf)?
  12. So I'm trying to implement terrain tessellation. I suppose it should be as simple as draw an enormous quad patch, generate new vertices and then offset the y-coordinate using a heightmap. Am I correct that far? :) What I'm curious is how do you perform any form of culling of the terrain geometry at this point. Say only a small part of this large quad is visible, how do you prevent it from tessellating alot of soon-to-be-unused vertices?
  13. As the title says :) Using my mouse, I want to pick out a texel on a mesh I have rendered and modify that texel. I start by picking a screen coordinate using my mouse. I then convert this screen coordinate to a world coordinate (using depth value at that pixel + inverse wvp matrix). This world coordinate is on the mesh at the pixel of the texture I want to modify. The question is how do I then go from world coordinate to texture coordinate on that specific texture?
  • 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!