Example #1
0
void CGLCG::setShaderVars(int pass)
{
	/* mvp paramater
	*/
	CGparameter cgpModelViewProj = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, "modelViewProj");
	if(cgpModelViewProj)
		cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

#define setProgram2fv(pass,varname,floats)\
{\
	CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
	CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
	if(cgpf)\
		cgGLSetParameter2fv(cgpf,floats);\
	if(cgpv)\
		cgGLSetParameter2fv(cgpv,floats);\
}\

#define setProgram1f(pass,varname,val)\
{\
	CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
	CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
	if(cgpf)\
		cgGLSetParameter1f(cgpf,val);\
	if(cgpv)\
		cgGLSetParameter1f(cgpv,val);\
}\

#define setTextureParameter(pass,varname,val)\
{\
	CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
	if(cgpf) {\
		cgGLSetTextureParameter(cgpf,val);\
		cgGLEnableTextureParameter(cgpf);\
	}\
}\

#define setTexCoordsParameter(pass,varname,val)\
{\
	CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
	if(cgpv) {\
		cgGLSetParameterPointer(cgpv, 2, GL_FLOAT, 0, val);\
        cgGLEnableClientState(cgpv);\
		cgAttribParams.push_back(cgpv);\
	}\
}\

	/* IN paramater
	*/
	float inputSize[2] = {shaderPasses[pass-1].outputSize.x,shaderPasses[pass-1].outputSize.y};
	float textureSize[2] = {shaderPasses[pass-1].textureSize.x,shaderPasses[pass-1].textureSize.y};
	float outputSize[2] = {shaderPasses[pass].outputSize.x,shaderPasses[pass].outputSize.y};

	setProgram2fv(pass,"IN.video_size",inputSize);
	setProgram2fv(pass,"IN.texture_size",textureSize);
	setProgram2fv(pass,"IN.output_size",outputSize);
    unsigned int shaderFrameCnt = frameCnt;
    if(shaderPasses[pass].frameCounterMod)
        shaderFrameCnt %= shaderPasses[pass].frameCounterMod;
	setProgram1f(pass,"IN.frame_count",(float)shaderFrameCnt);
    setProgram1f(pass,"IN.frame_direction",GUI.rewinding?-1.0f:1.0f);

	/* ORIG parameter
	*/
	float orig_videoSize[2] = {shaderPasses[0].outputSize.x,shaderPasses[0].outputSize.y};
	float orig_textureSize[2] = {shaderPasses[0].textureSize.x,shaderPasses[0].textureSize.y};
	
	setProgram2fv(pass,"ORIG.video_size",orig_videoSize);
	setProgram2fv(pass,"ORIG.texture_size",orig_textureSize);
	setTextureParameter(pass,"ORIG.texture",shaderPasses[0].tex);
	setTexCoordsParameter(pass,"ORIG.tex_coord",shaderPasses[1].texcoords);

	/* PREV parameter
	*/
	if(prevPasses[0].textureSize.x>0) {
		float prev_videoSize[2] = {prevPasses[0].videoSize.x,prevPasses[0].videoSize.y};
		float prev_textureSize[2] = {prevPasses[0].textureSize.x,prevPasses[0].textureSize.y};

		setProgram2fv(pass,"PREV.video_size",prev_videoSize);
		setProgram2fv(pass,"PREV.texture_size",prev_textureSize);
		setTextureParameter(pass,"PREV.texture",prevPasses[0].tex);
		setTexCoordsParameter(pass,"PREV.tex_coord",prevPasses[0].texCoords);
	}

	/* PREV1-6 parameters
	*/
	for(int i=1;i<prevPasses.size();i++) {
		if(prevPasses[i].textureSize.x==0)
			break;
		char varname[100];
		float prev_videoSize[2] = {prevPasses[i].videoSize.x,prevPasses[i].videoSize.y};
		float prev_textureSize[2] = {prevPasses[i].textureSize.x,prevPasses[i].textureSize.y};
		sprintf(varname,"PREV%d.video_size",i);
		setProgram2fv(pass,varname,prev_videoSize);
		sprintf(varname,"PREV%d.texture_size",i);
		setProgram2fv(pass,varname,prev_textureSize);
		sprintf(varname,"PREV%d.texture",i);
		setTextureParameter(pass,varname,prevPasses[i].tex);
		sprintf(varname,"PREV%d.tex_coord",i);
		setTexCoordsParameter(pass,varname,prevPasses[i].texCoords);
	}

	/* LUT parameters
	*/
	for(int i=0;i<lookupTextures.size();i++) {
		setTextureParameter(pass,lookupTextures[i].id,lookupTextures[i].tex);
	}

	/* PASSX parameters, only for third pass and up
	*/
	if(pass>2) {
		for(int i=1;i<pass-1;i++) {
			char varname[100];
			float pass_videoSize[2] = {shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y};
			float pass_textureSize[2] = {shaderPasses[i].textureSize.x,shaderPasses[i].textureSize.y};
			sprintf(varname,"PASS%d.video_size",i);
			setProgram2fv(pass,varname,pass_videoSize);
			sprintf(varname,"PASS%d.texture_size",i);
			setProgram2fv(pass,varname,pass_textureSize);
			sprintf(varname,"PASS%d.texture",i);
			setTextureParameter(pass,varname,shaderPasses[i].tex);
			sprintf(varname,"PASS%d.tex_coord",i);
			setTexCoordsParameter(pass,varname,shaderPasses[i+1].texcoords);
		}
	}
}
Example #2
0
void CD3DCG::setShaderVars(int pass)
{
	D3DXVECTOR2 inputSize = shaderPasses[pass-1].outputSize;
	D3DXVECTOR2 textureSize = shaderPasses[pass-1].textureSize;
	D3DXVECTOR2 outputSize = shaderPasses[pass].outputSize;

	/* mvp paramater
	*/
	CGparameter cgpModelViewProj = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, "modelViewProj");

	if(cgpModelViewProj)
		cgD3D9SetUniformMatrix(cgpModelViewProj,&mvp);

#define setProgramUniform(pass,varname,floats)\
{\
	CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
	CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
	if(cgpf)\
		cgD3D9SetUniform(cgpf,floats);\
	if(cgpv)\
		cgD3D9SetUniform(cgpv,floats);\
}\

#define setTextureParameter(pass,varname,val,linear)\
{\
	CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
	if(cgpf) {\
		cgD3D9SetTexture(cgpf,val);\
		cgD3D9SetSamplerState(cgpf, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);\
		cgD3D9SetSamplerState(cgpf, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);\
		cgD3D9SetSamplerState(cgpf, D3DSAMP_MINFILTER, linear?D3DTEXF_LINEAR:D3DTEXF_POINT);\
		cgD3D9SetSamplerState(cgpf, D3DSAMP_MAGFILTER, linear?D3DTEXF_LINEAR:D3DTEXF_POINT);\
	}\
}\

#define setTexCoordsParameter(pass,varname,val)\
{\
	CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
	if(cgpv) {\
		unsigned long index = cgGetParameterResourceIndex(cgpv);\
		pDevice->SetStreamSource(shaderPasses[pass].parameterMap[index].streamNumber,val,0,sizeof(VERTEX));\
	}\
}\

	/* IN paramater
	*/
	setProgramUniform(pass,"IN.video_size",&inputSize);
	setProgramUniform(pass,"IN.texture_size",&textureSize);
	setProgramUniform(pass,"IN.output_size",&outputSize);
	setProgramUniform(pass,"IN.frame_count",&frameCnt);
    float frameDirection = GUI.rewinding?-1.0f:1.0f;
    setProgramUniform(pass,"IN.frame_direction",&frameDirection);

	/* ORIG parameter
	*/
	setProgramUniform(pass,"ORIG.video_size",shaderPasses[0].outputSize);
	setProgramUniform(pass,"ORIG.texture_size",shaderPasses[0].textureSize);
	setTextureParameter(pass,"ORIG.texture",shaderPasses[0].tex,shaderPasses[1].linearFilter);
	setTexCoordsParameter(pass,"ORIG.tex_coord",shaderPasses[1].vertexBuffer);

	/* PREV parameter
	*/
	if(prevPasses[0].tex) {
		setProgramUniform(pass,"PREV.video_size",prevPasses[0].imageSize);
		setProgramUniform(pass,"PREV.texture_size",prevPasses[0].textureSize);
		setTextureParameter(pass,"PREV.texture",prevPasses[0].tex,shaderPasses[1].linearFilter);
		setTexCoordsParameter(pass,"PREV.tex_coord",prevPasses[0].vertexBuffer);
	}

	/* PREV1-6 parameters
	*/
	for(int i=1;i<prevPasses.size();i++) {
		if(!prevPasses[i].tex)
			break;
		char varname[100];
		sprintf(varname,"PREV%d.video_size",i);
		setProgramUniform(pass,varname,prevPasses[i].imageSize);
		sprintf(varname,"PREV%d.texture_size",i);
		setProgramUniform(pass,varname,prevPasses[i].textureSize);
		sprintf(varname,"PREV%d.texture",i);
		setTextureParameter(pass,varname,prevPasses[i].tex,shaderPasses[1].linearFilter);
		sprintf(varname,"PREV%d.tex_coord",i);
		setTexCoordsParameter(pass,varname,prevPasses[i].vertexBuffer);
	}

	/* LUT parameters
	*/
	for(int i=0;i<lookupTextures.size();i++) {
		setTextureParameter(pass,lookupTextures[i].id,lookupTextures[i].tex,lookupTextures[i].linearFilter);
	}

	/* PASSX parameters, only for third pass and up
	*/
	if(pass>2) {
		for(int i=1;i<pass-1;i++) {
			char varname[100];
			sprintf(varname,"PASS%d.video_size",i);
			setProgramUniform(pass,varname,shaderPasses[i].outputSize);
			sprintf(varname,"PASS%d.texture_size",i);
			setProgramUniform(pass,varname,shaderPasses[i].textureSize);
			sprintf(varname,"PASS%d.texture",i);
			setTextureParameter(pass,varname,shaderPasses[i].tex,shaderPasses[i+1].linearFilter);
			sprintf(varname,"PASS%d.tex_coord",i);
			setTexCoordsParameter(pass,varname,shaderPasses[i+1].vertexBuffer);
		}
	}
}