Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

ChaseRLewis

Member Since 30 Aug 2010
Offline Last Active Sep 24 2012 11:34 PM
-----

Topics I've Started

Getting color pallette of non-shaded texture that ignores aliasing

22 September 2012 - 02:28 AM

Edit: I've gotten it from 5k to about 60 by only checking 100% opaque values and introducing floating point tolerances since Unity converts all the colors to floating point. But that's still about ~13-15x the number in the actual number in the photo ... that's with pretty generous tolerances of .1f which is is ~ +/- 25 in the 8-bit color scale.

So I'm trying to write a tool for my Unity game that will allow me to make a color edit mode. I figured if I went the extra step to make sure my colors were all completed seperated that it would be fairly easy, but I'm still getting far more colors then I actually attempted using when I colored the picture. The picture was done with vector graphics so I know the precise color of each not including the aliased lines which are interpolated with a completely alpha color.

I'm not 100% that aliasing is the problem but otherwise I am completely unsure why there would be in the realm of 4000 different colors showing in my photo. They all seem to be really similar versions of the same color so aliasing is the only thing that makes sense. The idea is have a color mask, a and a pallete to map use selected colors too at run time.

This is just a sample file of peach from paper mario I'm using to test the system Attached File  PrincessColor.png   4.25MB   15 downloads

The goal is to use this color map with the BW and a shade map to construct the final picture. I was separating the BW from the color to try and solve the aliasing issue but that isn't the solution.

Hopefully looking like this in the end.Attached File  ColorPrincess.png   297.65K   16 downloads

I got it working in photoshop but need to find out how to export this to my game. I could do it by exporting each clip mask out as a picture then recombining them mathematically to guarantee they are exact, but exporting 6-12 pics per frame then recombining is more work then it should have to be. Any help would be appreciated.


Code:

[source lang="java"]public class ColorEditorWindow : EditorWindow{ static ColorEditorWindow window = null; List<Color> ColorPallette = new List<Color>(); // Use this for initialization [MenuItem("Window/ColorEditor")] static public void Start () { if (window == null) window = EditorWindow.GetWindow<ColorEditorWindow>(); } public void GetPallette() { if (texture != null) {    //Reset Pallette if previous one existed if(ColorPallette.Count != 0) ColorPallette.Clear();    Color temp = new Color(); //cache color value to use as temporary for (int i = 0; i < texture.height; i++) { for (int j = 0; j < texture.width; j++) { temp = texture.GetPixel(j, i); //Get pixel to test if (temp.a == 0)//Ignore pure alpha colors continue; //See if color is unique for (int k = 0; k < ColorPallette.Count; k++) //If color exists in pallette skip it -- goto is ugly consider something else { if (ColorPallette[k].r == temp.r && ColorPallette[k].g == temp.g && ColorPallette[k].b == temp.b) goto NEXT; } ColorPallette.Add(temp); //If not in pallette add to pallette NEXT: continue; //If temp exists go here and continue. } } } } public Texture2D texture = null; public void OnGUI() { texture = EditorGUILayout.ObjectField(texture, typeof(Texture2D)) as Texture2D; if (GUILayout.Button("Get Pallette")) { GetPallette(); }    /* for (int i = 0; i < ColorPallette.Count; i++) ColorPallette[i] = EditorGUILayout.ColorField(ColorPallette[i]); */ EditorGUILayout.LabelField("Colors: " + ColorPallette.Count); }}[/source]

Depth Buffer Issue

21 April 2012 - 05:41 PM

Been following a tutorial to try and learn C++ DirectX. So far so good, but depth buffer is giving me problems.

I'll work this into classes after I have a better idea of how it all fits together but here's the code I have so far. The scene renders fine (well except depth buffer not clipping stuff) if I don't put my depth buffer pointer into OMSetRenderTargets() and comment out  ClearDepthBuffer();

This makes it pretty obvious to me that it has to do something with how I'm creating the buffer. I've looked up at least 3 different tutorials and tried to adapt their code but none of it seems to work.

I've tried everything I can think of and have been trolling forums for about an hour and nothing suggested seems to work.

I know it's pretty bleh at the second. Just want to get a better idea of how everything works so I don't have to do to rebuild wrapper classes.

//How I Initialize Stuff
void InitRenderTarget()
{ HRESULT hr;
ID3D11Texture2D* pBackBuffer;
pSwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)&pBackBuffer);
hr = pDev->CreateRenderTargetView(pBackBuffer,NULL,&pRenderTargetView);
pBackBuffer->Release();
pBackBuffer = nullptr;
if(hr != S_OK)
{
  isPlaying = false;
  return;
}
D3D11_TEXTURE2D_DESC texd;
ZeroMemory(&texd,sizeof(texd));
texd.Width = 800.0f;
texd.Height = 600.0f;
texd.ArraySize = 1;
texd.MipLevels = 1;
texd.SampleDesc.Count = 1;
texd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
texd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
texd.Usage = D3D11_USAGE_DEFAULT;
hr = pDev->CreateTexture2D(&texd,NULL,&pDepthBuff);
if(hr != S_OK)
{
  isPlaying = false;
  return;
}
D3D11_DEPTH_STENCIL_VIEW_DESC ddesc;
ZeroMemory(&ddesc,sizeof(ddesc));
ddesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
ddesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
pDev->CreateDepthStencilView(pDepthBuff,&ddesc,&pDepth);
pDC->OMSetRenderTargets(1,&pRenderTargetView,pDepth);

pDepthBuff->Release();
pDepthBuff = nullptr;

D3D11_RASTERIZER_DESC rDesc;
rDesc.FillMode = D3D11_FILL_SOLID;
rDesc.CullMode = D3D11_CULL_NONE;
rDesc.DepthClipEnable = true;
rDesc.FrontCounterClockwise = false;
rDesc.MultisampleEnable  = false;
rDesc.SlopeScaledDepthBias = false;
rDesc.DepthBias = false;
rDesc.DepthBiasClamp = false;
rDesc.AntialiasedLineEnable = false;
rDesc.ScissorEnable = false;

pDev->CreateRasterizerState(&rDesc,&pRastState);
pDC->RSSetState(pRastState);

//SetupViewPort
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport,sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = 800;
viewport.Height = 600;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
pDC->RSSetViewports(1,&viewport);
}

//How I do some basic drawing
void RenderFrame()
{
pDC->ClearRenderTargetView(pRenderTargetView,ClearColor);
pDC->ClearDepthStencilView(pDepth,D3D11_CLEAR_DEPTH,1.0f,0.0f);
pDC->Draw(3,0);
World2.MakeRotateY(VM_PI*gTimer.TotalTime());
World2.Translate(1.0f,0.0f,0.0f);
World2.RotateY(VM_PI_4*gTimer.TotalTime());
Matrix4x4::MatrixMultiply(World2,View,World2);
pDC->UpdateSubresource(pCBuffer,0,0,&World2,0,0);
pDC->Draw(3,0);
pSwapChain->Present(0,0);
}

PARTNERS