Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

Johannes1991

Member Since 05 Jan 2009
Offline Last Active Mar 13 2013 11:30 AM
-----

Topics I've Started

Compile Shader From Memory

28 February 2013 - 10:33 AM

I have started making my own shader loader and of course it's not working! When I read from the shader file i separate the hlsl code and my own code into different strings and when i try to compile the shader code with D3DX11CompileFromMemory() I get this error message:
"error X3000: syntax error: unexpected end of file"

I have put a null terminator in the end of the string but it doesn't work...
So anyone know the reason for this problem?

Code:

std::fstream file(path, std::ios::in);
std::string shaderCode = "", tempBuffer;

if(file.is_open())
{
        while(!file.eof())
        {
            //file.get(tempBuffer);
            file >> tempBuffer;

            if(tempBuffer == "ShaderInformation")
            {
                int i = 0;
                i += 0;
            }
            else
            {
                shaderCode += " " + tempBuffer;
            }
        }
}

shaderCode += '\0';

HRESULT hr;
ID3D10Blob *vsBlob, *psBlob, *errorBlob;
	
//Dummy hlsl code
const char temp[] = 
"Texture2D colormap;"
"Texture2D lightmap;"

"SamplerState fullscreenQuadSampler;"

"struct VertexInput"
"{"
	"float3 position : POSITION0;"
	"float2 uv : TEXCOORD0;"
"};"

"struct PixelInput"
"{"
	"float4 position : SV_Position;"
	"float2 uv : TEXCOORD0;"
"};"

"PixelInput VS(VertexInput input)"
"{"
	"PixelInput output;"

	"output.position = float4(input.position, 1.0f);"
	"float2 halfPixel = float2(0.5f / 800.0f, 0.5f / 600.0f);"
	"output.uv = input.uv;// + halfPixel;"

	"return output;"
"}"

"float4 PS(PixelInput input) : SV_Target"
"{"
	"float3 diffuseColor = colormap.Sample(fullscreenQuadSampler, input.uv).rgb;"
	"float4 lightData = lightmap.Sample(fullscreenQuadSampler, input.uv);"
   
	"float3 diffuseLight = lightData.rgb;"
	"float specularLight = lightData.a;"

	"return float4(diffuseColor * diffuseLight + specularLight, 1.0f);"
"}"
"\0";		
	
hr = D3DX11CompileFromMemory(temp,
		sizeof(temp),
		"FinalComposition.hlsl",
		NULL,
		NULL,
		"VS",
		"vs_4_0",
		D3D10_SHADER_PACK_MATRIX_ROW_MAJOR,
		NULL,
		NULL,
		&vsBlob,
		&errorBlob,
		NULL);


if(hr != S_OK)
{
	if(!errorBlob)
		return false;

	char msg[20000];
	strcpy_s(msg, sizeof(msg), (char*)errorBlob->GetBufferPointer());
	OutputDebugStringA(msg);
	MessageBoxA(GetDesktopWindow(), msg, "VertexShader Compilation Failed!", MB_OK | MB_ICONERROR);
	errorBlob->Release();

	return false;
}

 

 


PARTNERS