Jump to content

  • Log In with Google      Sign In   
  • Create Account

Wilhelm van Huyssteen

Member Since 22 Mar 2008
Offline Last Active Today, 07:26 AM

Posts I've Made

In Topic: MSAA and offscreen render target issue

19 September 2014 - 03:16 PM

Thanks il take a look at that.


In Topic: MSAA and offscreen render target issue

19 September 2014 - 02:09 PM

Im not trying to sample from a MSAA texture in particular (I was just under the impression that all render targets needed to have their sample count set to the AA level as wel).

 

I just want whatever is rendered to the backbuffer to be anti-alaised (In opengl i could do this simply by enabling multisampling when creating the context. I just want the same in directx). I have set the count of the render targets back to 1 but i stil have the same problem.

 

As far as using the debugger goes my engine is written in java and ive only written some c++ bindings (that i export as a .dll) so i can use directx. Dont know if it would be possible to still use the debugger but it would certainly be nice.

 

EDIT: found the issue. Both the depth buffer i use with the back buffer and the depth buffer i use with the render targets had their counts set to the AA level whereas only the depth texture that i use with the backbuffer should have had that count set. Im stil wondering if there might be a way for me to get some debug info back with my setup like i described in the above paragraph.


In Topic: Mip mapping issue

12 September 2014 - 08:30 AM

So. since mhagain mentioned that gluBuild2DMipmaps uses a box filter as well I went back to my mipmap generation code and I discovered that (as part of some earlier testing/debugging) I commented out the line of code that averages the 4 nearest pixels together and instead replaced it with a line that that just uses the value of the top-left pixel and ignores the rest...

 

Undoing that bit of test code the directx version now renders perfectly. Feel kind of silly. Should probably take it easy with all the late night coding.

 

Thank you for your time.


In Topic: Mip mapping issue

11 September 2014 - 06:32 PM

Ok.

 

I use directX 11. And yes the opengl is quite a bit older. 

 

filter options in opengl:

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
 
filter options in directx
 


D3D11_SAMPLER_DESC sampDesc;
ZeroMemory(&sampDesc, sizeof(sampDesc));
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
 
Shaders. The first 4 textures contain height, normal and tile weight information. the next 8 textures are the actual colour textures for the terrain. all textures and samplers are bound to the vertex and pixel shader using the same slots (for compatibility with opengl). The pixel shader contains 1 sampler for each texture but theyre all the same. The vertex shader is probaly pretty irrelevent to the question.
 
vertex shader
 


Texture2D tex1  : register( t0 );
SamplerState samp1  : register( s0 );<span> </span>
 
Texture2D tex2  : register( t1 );
SamplerState samp2  : register( s1 );<span> </span>
 
Texture2D tex3  : register( t2 );
SamplerState samp3  : register( s2 );<span> </span>
 
Texture2D tex4  : register( t3 );
SamplerState samp4  : register( s3 );
 
 
 
 
 
  struct VSInput
 {
float4 pos : a_position;
float2 textCoordA : v_textCoordA;
 };
 
 
  struct PSInput
 {<span> </span>
 <span> </span> float4 pos : SV_Position;
 <span> </span> float3 p : v_pos;
float2 textCoordA : v_textCoordA;
float3 normal : v_normal;
float2 gridPos : v_gridPos;
float w1 : v_w1;
float w2 : v_w2;
float w3 : v_w3;
float w4 : v_w4;
float w5 : v_w5;
float w6 : v_w6;
float w7 : v_w7;
float w8 : v_w8;<span> </span>
float2 c : v_c;
 };
 
 
 
 
 
 
PSInput main(VSInput attrib)
{
 
        PSInput ps;
   
float4 vpos = attrib.pos;
ps.gridPos = float2(vpos.x*128,vpos.y*128);
 
 
float2 coord = float2(vpos.x/(8*lod)+tOffset.x,vpos.y/(8*lod)+tOffset.y);
 
ps.c = coord;
 
coord.x = clamp(coord.x,1.0/1024.0,1023.0/1024.0);
coord.y = clamp(coord.y,1.0/1024.0,1023.0/1024.0);
coord = float2(coord.x+1.0/2048, coord.y+1.0/2048);
 
float2 ic = float2(vpos.x/(8*lod)+tOffset.x,vpos.y/(8*lod)+tOffset.y);<span> </span>
ic = ic * 1024;
ic.x = clamp(ic.x,1.0,1023.0);
ic.y = clamp(ic.y,1.0,1023.0);<span> </span>
 
uint3 ici = uint3(ic.x,ic.y,0);
 
float4 t1 = tex1.Load(ici);
float4 t2 = tex2.Load(ici);
float4 t3 = tex3.Load(ici);
float4 t4 = tex4.Load(ici);
 
 
float h = (t1.r-(127.0/255.0)) * 65280.0 +
 t1.g * 255.0 +
                  t1.b * 1.0;
 
vpos.z = vpos.z + h;
 
ps.normal =  t2.rgb*2-1;
 
 
float4 vertPos = mul(vpos,modelMatrix);
   <span> </span>ps.pos = mul(vertPos,projectionAndViewMatrix);
   <span> </span>ps.p = vertPos.xyz;
   <span> </span>
   <span> </span>ps.w1 = t3.r;
   <span> </span>ps.w2 = t3.g;
   <span> </span>ps.w3 = t3.b;
   <span> </span>ps.w4 = t3.a;
   <span> </span>ps.w5 = t4.r;
   <span> </span>ps.w6 = t4.g;
   <span> </span>ps.w7 = t4.b;
   <span> </span>ps.w8 = t4.a;
   <span> </span>
   <span> </span>ps.textCoordA = attrib.textCoordA*(8.0/lod);
   <span> </span>
   <span> </span>return ps;
 
}
 
 
Pixel shader
 
 


Texture2D tex1  : register( t0 );
Texture2D tile1  : register( t4 );
Texture2D tile2  : register( t5 );
Texture2D tile3  : register( t6 );
Texture2D tile4  : register( t7 );
Texture2D tile5  : register( t8 );
Texture2D tile6  : register( t9 );
Texture2D tile7  : register( t10 );
Texture2D tile8  : register( t11 );
 
SamplerState samp1  : register( s4 );<span> </span>
SamplerState samp2  : register( s5 );
SamplerState samp3  : register( s6 );
SamplerState samp4  : register( s7 );
SamplerState samp5  : register( s8 );
SamplerState samp6  : register( s9 );
SamplerState samp7  : register( s10 );
SamplerState samp8  : register( s11 );
 
  struct PSInput
 {<span> </span>
 <span> </span> float4 pos : SV_Position;
 <span> </span> float3 p : v_pos;
float2 textCoordA : v_textCoordA;
float3 normal : v_normal;
float2 gridPos : v_gridPos;
float w1 : v_w1;
float w2 : v_w2;
float w3 : v_w3;
float w4 : v_w4;
float w5 : v_w5;
float w6 : v_w6;
float w7 : v_w7;
float w8 : v_w8;<span> </span>
float2 c : v_c;
 };
 
 
 
float4 main(PSInput ps) : SV_Target
{
 
uint x = int(floor(ps.p.x));
uint y = int(floor(ps.p.y));
x = x % 1024;
y = y % 1024;
 
 
float4 t1 = tex1.Load(uint3(ps.c.x*1024,ps.c.y*1024,0));
 
if (t1.a == 0.0) //indicates a hole in the terrain. Caves etc.
{
discard;
}
 
 
 
float3 n = normalize(ps.normal);
 
 
 
 
float4 c1 = tile1.Sample(samp1, ps.textCoordA);
float4 c2 = tile2.Sample(samp2, ps.textCoordA);
float4 c3 = tile3.Sample(samp3, ps.textCoordA);
float4 c4 = tile4.Sample(samp4, ps.textCoordA);
float4 c5 = tile5.Sample(samp5, ps.textCoordA);
float4 c6 = tile6.Sample(samp6, ps.textCoordA);
float4 c7 = tile7.Sample(samp7, ps.textCoordA);
float4 c8 = tile8.Sample(samp8, ps.textCoordA);
 
float4 fvBaseColor = c1;
 
float total = ps.w1+ps.w2+ps.w3+ps.w4+ps.w5+ps.w6+ps.w7+ps.w8;
 
if (total > 0.0)
{
fvBaseColor = c1 * ps.w1 +  c2 * ps.w2 +  c3 * ps.w3 +  c4 * ps.w4 +  c5 * ps.w5 +  c6 * ps.w6 +  c7 * ps.w7 +  c8 * ps.w8;
fvBaseColor.a = 0.0;
}
 
 
 
float NdotL = max(dot(n, normalize(float3(1000,-1000,1000))),0.0);
 
 
  <span> </span>float cut = 0.3;
  <span> </span>float shade = 0.85;
  <span> </span>
if (NdotL > cut + 0.05)
{
NdotL = 1.0;
}
else if (NdotL < cut)
{
NdotL = shade;
}
else
{<span> </span>
NdotL = ((NdotL - cut)*20)*(1.0-shade)+shade;
}
 
 
 
    <span> </span>  NdotL = 1.0 - NdotL;
 float4 diffuse = float4(fvBaseColor.r-NdotL,fvBaseColor.g-NdotL,fvBaseColor.b-NdotL,1.0);
 
 
 
 
 
 
float4 colour1 = diffuse;
 
 
 
 
 
 
 
 
 
 
 
 
 
float len = length(ps.p-camera);
float start = 500.0;
float end = 700.0;
float4 fadeColor = float4(0.3,0.3,0.9,1.0);
if (len > start)
{
if (len > end)
{
colour1 = fadeColor;
}
else
{ 
colour1 = lerp(colour1,fadeColor,(len-start)/(end-start));
}
}
 
 
 
float4 cc2 = colour1;
cc2.a = 1.0;
 
 
 if (death == 1)
 {
 <span> </span>float grey = (cc2.r+cc2.g+cc2.b)/3.0;
 <span> </span>cc2.r = grey;
 <span> </span>cc2.g = grey;
 <span> </span>cc2.b = grey;
 }
 
 return cc2;
 
}

 

 
Here is the code that creates the texture. My game engine is written in Java but since you cant do directx in java directly I wrote my directx calls in c++). I create and concatenate all the mip levels in java before calling this c++ method. If the mipLevel is higher than one this method will only work for textures that has width and height values that is multiples of 2 I will improve that as soon as this problem is sorted out. This is probably the part that I'm the most unsure of. especially where I load all the mipmaps into the SUB_RESOURCE_DATA array.
 


struct Texture
{
ID3D11ShaderResourceView* textureView;
ID3D11DepthStencilView* depthStencilView;
ID3D11RenderTargetView* renderTargetView;
ID3D11SamplerState* sampler;
};

 


JNIEXPORT jint JNICALL Java_dmdx11_DmdxNative_createTexture(JNIEnv* env, jobject, jobject data, jint width, jint height, jint type,jint mipLevel)
{
Texture texture = Texture();
ID3D11Texture2D* pTexture;
if (type == 0)//color
{



D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
D3D11_TEXTURE2D_DESC sTexDesc;
 
sTexDesc.Width = width;
sTexDesc.Height = height;
sTexDesc.MipLevels = mipLevel;
sTexDesc.ArraySize = 1;
sTexDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sTexDesc.SampleDesc.Count = 1;
sTexDesc.SampleDesc.Quality = 0;
sTexDesc.Usage = D3D11_USAGE_IMMUTABLE;
sTexDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
sTexDesc.CPUAccessFlags = 0;
sTexDesc.MiscFlags = 0;
 
D3D11_SUBRESOURCE_DATA *sSubData = new D3D11_SUBRESOURCE_DATA[mipLevel];
 
int sofar = 0;
for (int i = 0; i < mipLevel; i++)
{
 
 
sSubData[i].pSysMem = (jbyte*)env->GetDirectBufferAddress(data) + sofar;
sSubData[i].SysMemPitch = (UINT)(width * 4);
sSubData[i].SysMemSlicePitch = (UINT)(width * height * 4);
 
sofar += (int)(width * height * 4);
 
width = width / 2;
height = height / 2;
 
}
hr = g_pd3dDevice->CreateTexture2D(&sTexDesc, sSubData, &pTexture);
delete[] sSubData;
 
 
 
shaderResourceViewDesc.Format = sTexDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = mipLevel;
 
g_pd3dDevice->CreateShaderResourceView(pTexture, &shaderResourceViewDesc, &texture.textureView);
 
 
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory(&sampDesc, sizeof(sampDesc));
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
 
g_pd3dDevice->CreateSamplerState(&sampDesc, &texture.sampler);
}
... 
...
...
}
 

 
If theres any more information needed please ask.
 
Thank you for your time ^^

In Topic: You, according to the internet.

18 August 2014 - 06:09 AM

I'm obese and I absolutely love Forex trading. I also fancy Russian women.


PARTNERS