Sign in to follow this  
Followers 0
damix911

Color is affecting texture samping in Visual Studio with HAL

6 posts in this topic

Hi guys, I need your help! I am developing a grass shader, with a technique based on this article. A screenshoot. The shader I'm writing is not based on their code, however; I started it from scratch. My theoretical preparation on shaders is not very strong, however up to this day I have always been able to achieve the result (normal mapping, shadow mapping, parallax mapping, something with caustics, blur etc...) But this shader is making my head ache a lot, mainly because it is behaving WELL when run OUTSIDE Visual Studio, and terribly WRONG when run from WITHIN Visual Studio (that is, when clicking on the green 'Run' button). A similar issue (just the complete opposite, how ironic :-) happened also yesterday, and in that case setting an unused variable to float4(0.0f, 0.0f, 0.0f, 1.0f) solved the problem (which is a strange situation, since it was unused); before this fix, inside Visual Studio it worked, outside it did NOT work. After the fix it worked perfectly in both ways. The new problem I have looks like this. In general, a color variable which is not (aparently) involved in the texture sampling process (is not being used as a coordinate) is affecting the sampling process. In particular, I would like to make some texture lighter to avoid that sort of darker grid that appears in the grass; to do this, I defined a color variable named 'correction': float4 correction = float4(0.0f, 0.01f, 0.0f, 0.0f); Which in my dreams should make the green greener; however this causes the disaster you can easily see in the right image. BUT ONLY IN VISUAL STUDIO! If I double click on the .exe everything is fine, the grid is how predicted less dark and no graphic errors appear! My question is: has anybody of you experienced difference when running a shader within or without Visual Studio? Thanks everybody! The shader will be distributed as open source and it will be possible to use it also in commercial games! UPDATE: I should have done it before, however I tested the program and with the REF device everything is doing fine, inside Visual Studio and outside. If something is working properly with the REF device are there chances that it will work fine with a newer card or after a driver update? My PC is an almost entry-level laptop, so the graphic card may not be very good. But why outside of Visual Studio it runs nice? Why? Why? Why? http://gpuz.techpowerup.com/08/10/19/7fa.png Here is the shader:
/*
	File..........: grass-effect.fx
	Description...: A grass shader, based on the work of Ralf Habel, Michael Wimmer and Stefan Jeschke.
	License.......: Ms-PL (http://www.opensource.org/licenses/ms-pl.html)
	Author........: Dario D'Amico
	Date..........: October 18, 2008
	E-Mail........: dario.damico@damix.it
	Web...........: http://www.damix.it
	References....: http://www.cg.tuwien.ac.at/research/publications/2007/Habel_2007_IAG/
*/

// WorldView matrix.
uniform float4x4 wv;

// WorldViewProjection matrix.
uniform float4x4 wvp;

// The ground texture.
uniform texture ground;

// A texture in which several grass slices are horizontally packed.
uniform texture grass;

// A slice of grass with no holes, which means fully opaque.
uniform texture grassFull;

// Begin of sampler declarations.
sampler sGround = sampler_state
{
	Texture = <ground>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};

sampler sGrass = sampler_state
{
	Texture = <grass>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};

sampler sGrassFull = sampler_state
{
	Texture = <grassFull>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};
// End of sampler declarations.

// Begin of structure declarations.
struct Input_VS
{
	float4 position : POSITION;
	float3 tangent : TANGENT;
	float3 binormal : BINORMAL;
	float2 uv : TEXCOORD0;
};

struct Input_PS
{
	float4 positionWVP : POSITION;
	float4 positionWV : TEXCOORD0;
	float3 tangentWV : TEXCOORD1;
	float3 binormalWV : TEXCOORD2;
	float3 normalWV : TEXCOORD3;
	float2 uv : TEXCOORD4;
};

struct Output_PS
{
	float4 color : COLOR0;
};
// End of structure declarations.

/*
	Vertex shader.
*/
Input_PS VS(Input_VS vsIn)
{
	Input_PS psIn;
	
	psIn.positionWVP = mul(vsIn.position, wvp);
	psIn.positionWV = mul(vsIn.position, wv);
	psIn.tangentWV = mul(vsIn.tangent, wv);
	psIn.binormalWV = mul(vsIn.binormal, wv);
	psIn.normalWV = cross(psIn.tangentWV, psIn.binormalWV);
	psIn.uv = vsIn.uv;
	
	return psIn;
}

/*
	Pixel shader.
*/
Output_PS PS(Input_PS psIn)
{
	Output_PS psOut;

	// Coordinates on the texture.
	float u = psIn.uv.x;
	float v = psIn.uv.y;
	
	// Eye vector in WorldView space.
	float3 eyeWV = normalize(-psIn.positionWV.xyz);
	
	// Vector (u, v) in WorldView space.
	float3 uvWV = u * psIn.tangentWV + v * psIn.binormalWV;
	
	// Height of the grass.
	float height = 1.00f;
	
	// Horizontal scaling of the grass slices.
	float hFactor = 1 / height;
	
	// Number of slices in the grass texture.
	int grassStripes = 16;
	
	// Intersects the negative eye vector with the virtual plane that
	// represents the ground; this plane is parallel to the polygon and
	// is located at a distance of height in the direction of the negative
	// normal of the polygon; grass slices will be drawn between the virtual
	// plane and the poligon.
	float alphaGnd = (dot(uvWV, psIn.normalWV) - dot(-normalize(psIn.normalWV) * height, psIn.normalWV)) / dot(eyeWV, psIn.normalWV);
	float3 pointPlaneWVGnd = uvWV - alphaGnd * eyeWV;
	float3 onPlaneWVGnd = pointPlaneWVGnd + normalize(psIn.normalWV) * height;
	float betaGnd = dot(onPlaneWVGnd, psIn.tangentWV) / length(psIn.tangentWV);
	float negGammaGnd = dot(onPlaneWVGnd, psIn.binormalWV) / length(psIn.binormalWV);
	
	float2 groundCoords = float2(betaGnd / length(psIn.tangentWV), negGammaGnd / length(psIn.binormalWV));
	
	// Samples the ground texture.	
	psOut.color = tex2D(sGround, groundCoords);
	
	// Number of vertical and horizontal slices in the grid.
	int N = 10;
	
	// Full texture correction.
	float4 correction = float4(0.0f, 0.0f, 0.0f, 0.0f);
	
	// Distance between two adjacent stripes.
	float step = 1.0f / N;
	
	// Coordinates of the cell in the grid in which the eye
	// vector is logically applied.
	int iU = (int)(u / step);
	int iV = (int)(v / step);
	
	// Increment variables; when added to iU and iV they
	// cause the algorithm to move to move to a farther
	// cell.
	int incU = sign(dot(-eyeWV, psIn.tangentWV));
	int incV = sign(dot(-eyeWV, psIn.binormalWV));
	
	// After this step and for the rest of the computation,
	// incU and incV will contain the indexes of the next stripes
	// to test for intersection (both vertical and horizontal).
	if (incU > 0) iU += incU;
	if (incV > 0) iV += incV;
	
	// Raytracing through the grass.
	for (int i = 0; i < 2 * N; i++)
	{
		// If the grid is over stop the algorithm.
		if (iU < 0 || iU > N || iV < 0 || iV > N)
		{
			break;
		}
	
		// Test for intersection with a slice perpendicular to the binormal,
		// that is, a so called horizontal stripe.
		float alpha_V = (dot(uvWV, psIn.binormalWV) - (iV * step) * dot(psIn.binormalWV, psIn.binormalWV)) / dot(eyeWV, psIn.binormalWV);
		float3 pointPlaneWV_V = uvWV - alpha_V * eyeWV;
		float3 onPlaneWV_V = pointPlaneWV_V - (iV * step) * psIn.binormalWV;
		float beta_V = dot(onPlaneWV_V, psIn.tangentWV) / length(psIn.tangentWV);
		float negGamma_V = dot(onPlaneWV_V, -normalize(psIn.normalWV) * height) / length(-normalize(psIn.normalWV) * height);
		
		float lengthTangent = length(psIn.tangentWV);
		
		bool int_V = false;
		bool solid_V = false;
		float4 col_V = float4(0, 0, 0, 1);
		
		if (beta_V >= 0.0f && beta_V <= lengthTangent && negGamma_V >= 0.0f && negGamma_V <= height && alpha_V > 0)
		{
			// If the stripe was hit.
		
			int_V = true;
			float4 grassCoords = float4((beta_V / lengthTangent) * hFactor, (negGamma_V / height), 0.0f, 0.0f);
			
			if (iV == N || iV == 0)
			{
				// If we are at the end of the stripe then the opaque
				// grass must be sampled.
			
				col_V = tex2Dlod(sGrassFull, grassCoords) + correction;
				solid_V = true;
			}
			else
			{
				// Else the non-fully opaque grass must be sampled,
				// and the raytrace could possibly continue.
			
				grassCoords.y /= grassStripes;
				grassCoords.y += (iV % grassStripes) * (1.0f / grassStripes);
			
				float a = tex2Dlod(sGrass, grassCoords).a;
					
				if (a > 0.5f)
				{
					// An opaque pixel has been hit.
				
					col_V = tex2Dlod(sGrass, grassCoords);


					

					// Raytracing will stop.
					solid_V = true;
				}
			}
		}
		
		// Test for intersection with a slice perpendicular to the tangent,
		// that is, a so called vertical stripe.
		float alpha_U = (dot(uvWV, psIn.tangentWV) - (iU * step) * dot(psIn.tangentWV, psIn.tangentWV)) / dot(eyeWV, psIn.tangentWV);
		float3 pointPlaneWV_U = uvWV - alpha_U * eyeWV;
		float3 onPlaneWV_U = pointPlaneWV_U - (iU * step) * psIn.tangentWV;
		float beta_U = dot(onPlaneWV_U, psIn.binormalWV) / length(psIn.binormalWV);
		float negGamma_U = dot(onPlaneWV_U, -normalize(psIn.normalWV) * height) / length(-normalize(psIn.normalWV) * height);
		
		float lengthBinormal = length(psIn.binormalWV);
		
		bool int_U = false;
		bool solid_U = false;
		float4 col_U = float4(0, 0, 0, 1); // This MUST be initialized!
		
		if (beta_U >= 0.0f && beta_U <= lengthBinormal && negGamma_U >= 0.0f && negGamma_U <= height && alpha_U > 0)
		{
			// If the stripe was hit.
		
			int_U = true;
			float4 grassCoords = float4((beta_U / lengthBinormal) * hFactor, (negGamma_U / height), 0.0f, 0.0f);
			
			if (iU == N || iU == 0)
			{
				// If we are at the end of the stripe then the opaque
				// grass must be sampled.
			
				col_U = tex2Dlod(sGrassFull, grassCoords) + correction;
				solid_U = true;
			}
			else
			{
				// Else the non-fully opaque grass must be sampled,
				// and the raytrace could possibly continue.
			
				grassCoords.y /= grassStripes;
				grassCoords.y += (iU % grassStripes) * (1.0f / grassStripes);
			
				float a = tex2Dlod(sGrass, grassCoords).a;
					
				if (a > 0.5f)
				{
					// An opaque pixel has been hit.
				
					col_U = tex2Dlod(sGrass, grassCoords);
					
					// Raytracing will stop.
					solid_U = true;
				}
			}
		}
		
		// If an opaque pixel was sampled, then the color
		// is determined.
		
		if (solid_V && !solid_U) psOut.color = col_V;
		else if (!solid_V && solid_U) psOut.color = col_U;
		else if (solid_V && solid_U)
		{
			if (alpha_V < alpha_U)
				psOut.color = col_V;
			else
				psOut.color = col_U;
		}
		
		// The algorithm can then terminate.
		if (solid_U || solid_V)
		{
			break;
		}
		
		// Otherwise the algorithm moves to a farther
		// cell.
		if (int_U || int_V)
		{
			iV += incV;
			iU += incU;
		}
		else {
			// This is the case in which the ground was hit; in this case
			// the algorithm can be stopped because the generic ground
			// texture has already been sampled before the cycle; that
			// will be the output color.
		
			break;
		}
	}
	
	return psOut;
}

technique GrassEffect
{
	pass Render
	{
		VertexShader = compile vs_1_0 VS();
		PixelShader = compile ps_3_0 PS();
	}
}







The main.cpp:
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>

struct VertexPTBTex1
{
	D3DVECTOR position;
	D3DVECTOR tangent;
	D3DVECTOR binormal;
	float u;
	float v;
};

FLOAT heightField(FLOAT x, FLOAT z);
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
	HRESULT hr;
	int width = 800;
	int height = 600;

	WNDCLASSEX wc;
	wc.cbClsExtra = 0;
	wc.cbSize = sizeof(wc);
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
	wc.hCursor = (HCURSOR)LoadCursor(0, IDC_ARROW);
	wc.hIcon = (HICON)LoadIcon(0, IDI_APPLICATION);
	wc.hIconSm = (HICON)LoadIcon(0, IDI_APPLICATION);
	wc.hInstance = hInst;
	wc.lpfnWndProc = MainWndProc;
	wc.lpszClassName = L"MainWnd";
	wc.lpszMenuName = 0;
	wc.style = 0;

	RegisterClassEx(&wc);

	RECT rect = {0, 0, width, height};
	AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, 0);
	HWND hWnd = CreateWindowEx(0, L"MainWnd", L"Grass Shader", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, 0, 0, hInst, 0);

	ShowWindow(hWnd, nShowCmd);

	IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.BackBufferHeight = height;
	d3dpp.BackBufferWidth = width;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.Flags = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.MultiSampleQuality = 0;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.Windowed = TRUE;

	IDirect3DDevice9 *d3dDevice;
	hr = d3d->CreateDevice(0, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice);

	if (FAILED(hr))
	{
		MessageBox(hWnd, L"Can not create the device.", L"Error!", MB_ICONERROR);
		return -1;
	}

	IDirect3DTexture9 *ground;
	IDirect3DTexture9 *grass;
	IDirect3DTexture9 *grassAlpha;
	IDirect3DTexture9 *grassFull;

	hr = D3DXCreateTextureFromFile(d3dDevice, L"textures-original\\s_grass_ground.tga", &ground);
	hr = D3DXCreateTextureFromFile(d3dDevice, L"textures-original\\s_grassblades.tga", &grass);
	hr = D3DXCreateTextureFromFile(d3dDevice, L"textures-original\\s_grass_back.tga", &grassFull);

	D3DVERTEXELEMENT9 vePTBTex1[] =
	{
		{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
		{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},
		{0, 36, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		D3DDECL_END()
	};

	IDirect3DVertexDeclaration9 *vdPTBTex1;

	hr = d3dDevice->CreateVertexDeclaration(vePTBTex1, &vdPTBTex1);

	if (FAILED(hr))
	{
		MessageBox(hWnd, L"Can not create the vertex declaration.", L"Error!", MB_ICONERROR);
		return -1;
	}

	ID3DXEffect *effect;
	ID3DXBuffer *buffer;

	hr = D3DXCreateEffectFromFile(d3dDevice, L"effects\\grass-effect-playing.fx", 0, 0, 0, 0, &effect, &buffer);

	if (FAILED(hr))
	{
		if (buffer)
		{
			MessageBoxA(hWnd, (LPCSTR)buffer->GetBufferPointer(), "Error!", MB_ICONERROR);
			buffer->Release();			
		}
		else
		{
			MessageBox(hWnd, L"Can not create the effect.", L"Error!", MB_ICONERROR);
		}

		return -1;
	}

	MSG msg;
	BOOL run = TRUE;

	while (run)
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
		{
			GetMessage(&msg, 0, 0, 0);

			if (msg.message != WM_QUIT)
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else
			{
				run = FALSE;
			}
		}
		else
		{
			D3DXMATRIX world;
			D3DXMatrixRotationY(&world, 0.2f * GetTickCount() / 1000.0f);

			D3DXMATRIX view;
			D3DXMatrixTranslation(&view, 0.0f, -1.0f, 0.0f);

			D3DXMATRIX projection;
			D3DXMatrixPerspectiveFovLH(&projection, 1.0f, width / (FLOAT)height, 1.0f, 100.0f);

			D3DXMATRIX worldView;
			D3DXMatrixMultiply(&worldView, &world, &view);
			D3DXMATRIX worldViewProjection;
			D3DXMatrixMultiply(&worldViewProjection, &worldView, &projection);

			D3DXHANDLE handle;

			handle = effect->GetTechniqueByName("GrassEffect");
			effect->SetTechnique(handle);

			UINT nPasses;
			effect->Begin(&nPasses, 0);

			for (UINT i = 0; i < nPasses; i++)
			{
				effect->BeginPass(i);

				if (i == 0)
				{
					hr = d3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(150/255.0f, 220/255.0f, 230/255.0f, 1.0f), 1.0f, 0);
					hr = d3dDevice->BeginScene();

					handle = effect->GetParameterByName(0, "wv");
					hr = effect->SetMatrix(handle, &worldView);
					handle = effect->GetParameterByName(0, "wvp");
					hr = effect->SetMatrix(handle, &worldViewProjection);

					handle = effect->GetParameterByName(0, "ground");
					hr = effect->SetTexture(handle, ground);
					handle = effect->GetParameterByName(0, "grass");
					hr = effect->SetTexture(handle, grass);
					handle = effect->GetParameterByName(0, "grassFull");
					hr = effect->SetTexture(handle, grassFull);

					hr = effect->CommitChanges();

					int N = 5;

					for (int i = -N; i <= N; i++)
					{
						FLOAT cz = 10.0f * i;

						for (int j = -N; j <= N; j++)
						{
							FLOAT cx = 10.0f * j;

							VertexPTBTex1 vertices[4];
							vertices[0].position = D3DXVECTOR3(-5.0f + cx, heightField(-5.0f + cx, -5.0f + cz), -5.0f + cz);
							vertices[1].position = D3DXVECTOR3(-5.0f + cx, heightField(-5.0f + cx, 5.0f + cz), 5.0f + cz);
							vertices[2].position = D3DXVECTOR3(5.0f + cx, heightField(5.0f + cx, -5.0f + cz), -5.0f + cz);
							vertices[3].position = D3DXVECTOR3(5.0f + cx, heightField(5.0f + cx, 5.0f + cz), 5.0f + cz);
							vertices[0].tangent = D3DXVECTOR3(10.0f, 0.0f, 0.0f);
							vertices[1].tangent = D3DXVECTOR3(10.0f, 0.0f, 0.0f);
							vertices[2].tangent = D3DXVECTOR3(10.0f, 0.0f, 0.0f);
							vertices[3].tangent = D3DXVECTOR3(10.0f, 0.0f, 0.0f);
							vertices[0].binormal = D3DXVECTOR3(0.0f, 0.0f, -10.0f);
							vertices[1].binormal = D3DXVECTOR3(0.0f, 0.0f, -10.0f);
							vertices[2].binormal = D3DXVECTOR3(0.0f, 0.0f, -10.0f);
							vertices[3].binormal = D3DXVECTOR3(0.0f, 0.0f, -10.0f);
							vertices[0].u = 0.0f; vertices[0].v = 1.0f;
							vertices[1].u = 0.0f; vertices[1].v = 0.0f;
							vertices[2].u = 1.0f; vertices[2].v = 1.0f;
							vertices[3].u = 1.0f; vertices[3].v = 0.0f;

							hr = d3dDevice->SetVertexDeclaration(vdPTBTex1);
							hr = d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(VertexPTBTex1));
						}
					}

					hr = d3dDevice->EndScene();
					hr = d3dDevice->Present(0, 0, 0, 0);
				}

				effect->EndPass();
			}

			effect->End();
		}
	}

	ground->Release();
	grass->Release();
	grassFull->Release();
	effect->Release();
	vdPTBTex1->Release();
	d3dDevice->Release();
	d3d->Release();

	return 0;
}

FLOAT heightField(FLOAT x, FLOAT z)
{
	return (FLOAT)(-2.0f + 3 * sin(0.05 * x + 0.08 * z));
}

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}

	return 0;
}







[Edited by - damix911 on October 19, 2008 5:35:44 AM]
0

Share this post


Link to post
Share on other sites
There is a difference between running in Visual Studio and outside it, but I don't know what it is. Some ATI drivers crashed my programs when I ran them from within VS, and IIRC I've also had problem with Intel integrated graphics in this regards. Your idea of trying different drivers is a good one.
0

Share this post


Link to post
Share on other sites
Reduce your shaders to a minimal one that still exhibit the problem and use the PIX profiling tool that comes with the DirectX SDK to debug the issue - that tool is just gold.

Perhaps you could set VS run PIX run your app to debug both VS and non-VS environments.

Otherwise, the fact that VS/noVS affects the problem leads me to think that the problem wouldn't be in the drivers at least. I'd first assume something like some uninitialized data or access to bad memory or perhaps even different CPU floating point modes (that bit me when I was running my 3dsmax export plugin from VS versus outside it).

How does the debug build run in VS and outside it?
0

Share this post


Link to post
Share on other sites
Thank you so much ET3D, this is an important contribution because it shows that someone else encountered the problem. I didn't find anything about it on the web.

I have more details on the issue; if I change this line:


hr = D3DXCreateEffectFromFile(d3dDevice, L"effects\\grass-effect-playing.fx", 0, 0, 0, 0, &effect, &buffer);





To this line (the filename is different):


hr = D3DXCreateEffectFromFile(d3dDevice, L"effects\\grass-effect-playing.fxo", 0, 0, 0, 0, &effect, &buffer);





And I compile the shader with the command:


fxc /Gec /T fx_2_0 /Fo grass-effect-playing.fxo grass-effect-playing.fx





The shader still does not work properly within Visual Studio.

I'm really curious to see how many developers noticed this difference; in theory it should be possible to tune some parameters in the Project Properties in Visual Studio, in order to get the same behaviour of a double clicked application. At that point the changed properties would give several hints about the nature of the error. I don't even know how a process launched from Visual Studio differs from a double clicked one. I tried to copy the .manifest files created by Visual Studio in the same folder of the application I double click, because I know that .manifest can rebind dynamic-link libraries. But this doesn't solve the problem.
0

Share this post


Link to post
Share on other sites
Thanks clb, I should learn how to use PIX. I also had the sensation this could have been related to uninitialized data, because the first issue I had yesterday was in the end solved by setting an uninitialized color variable to black. In that case however the problem was the opposite: it ran perfectly inside VS, and badly outside VS.

The problem I am experiencing now is instead the opposite; inside Visual Studio it runs badly, outside it runs fine. But this happens only if 'float4 correction' is not black.
0

Share this post


Link to post
Share on other sites
Hi clb I did a little experiment; I still have to understand how to use PIX, however I launched it, I selected my GrassShader.exe file (which behaves fine when double-clicked) and asked PIX to record the replayable call stream.

During the recording, MY PROGRAM LOOKS BAD, as if it was executed from within Visual Studio! This may make sense, because both VS and PIX are 'external callers'. But you know what? When I playback the PIX recording, IT LOOKS NICE, as if it was double-clicked! But there's more, I tried several times and in a few cases even the playback LOOKED BAD! As in this video I took. In the video 4 executions are shown:

1) From Visual Studio (BAD)
2) Double-clicking (GOOD)
3) From PIX (BAD)
4) PIX playback (BAD, most of the times was GOOD)

I hope the pain I am goind through will be useful for someone in the future :-)

Thanks to everybody, if you have any little hint or if you experienced something similar please reply to this post!

Dario
0

Share this post


Link to post
Share on other sites
Try the single-frame capture mode with F12, and take a snapshot of a bad frame. PIX lets you double-check the device state and input buffers, as well as debug individual pixels as they are outputted from the pixel shader.

And as I said before, try reducing your pixel shader to a minimal one that still exhibits the problem. There is quite a lot of code there and it will help you simplify down the debugging.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0