VTF Shader refuses to work

I’ve been trying to use A vertex texture shader like the one is demomaster 0.8 which works perfectly for me, yet when I try to write one for terrian elevation,I get the “Shader too complex for driver Please chose another profile”

I used the loadPrcFileData("", “basic-shaders-only #f”)
and the demomaster water vtf example works fine(I have a gtx280 so I Know its not my video card)

program:

from direct.directbase import DirectStart
from pandac.PandaModules import loadPrcFileData, ConfigVariableBool
from pandac.PandaModules import Shader, Texture, TextureStage
loadPrcFileData("", "basic-shaders-only #f")

def load_terrian():
    tex =  loader.loadTexture('heightmap.png')
    g = loader.loadModel("plane128.egg") ##simple 128 x 128 grid
    g.setTexture(tex)
    g.reparentTo(render)

    ##g.setShaderInput('vtftex', tex)
    g.setShader(Shader.load("terrian.sha"))

if __name__ == "__main__":
    load_terrian()

    run()

    

shader:

//Cg
//Cg profile vp30 fp30

void vshader(
    uniform float4x4 mat_modelproj,
    uniform float4 mspos_light,
    
    in float4 vtx_position : POSITION,
    in float2 vtx_texcoord0 : TEXCOORD0,
    in float3 vtx_normal : NORMAL,
    in float4 vtx_color : COLOR,
    in uniform sampler2D k_vtftex : TEXUNIT0,
    out float4 l_color : COLOR,
    out float4 l_position : POSITION)
{

    float4 position = vtx_position;
    float4 h = tex2D(k_vtftex,vtx_texcoord0);
    position.z = h.x;
    l_position = mul(mat_modelproj, position);
}


void fshader(
    in float4 l_color : COLOR,
    out float4 o_color : COLOR)
{
    o_color = l_color;

}

If anyone can shed some light on this I’d be most grateful

You need to move tex2D in fragment shader. Also you must sent texture coordinates trough raster to fragment shader.

Something like that …

//Cg 
//Cg profile vp30 fp30 

void vshader( 
    uniform float4x4 mat_modelproj, 
    uniform float4 mspos_light, 
    
    in float4 vtx_position : POSITION, 
    in float2 vtx_texcoord0 : TEXCOORD0, 
    in float3 vtx_normal : NORMAL, 
    in float4 vtx_color : COLOR,  
    out float4 l_color : COLOR,
    out float2 l_texcoord0 : TEXCOORD0,
    out float4 l_position : POSITION) 
{ 

    float4 position = vtx_position;
    l_texcoord0 = vtx_texcoord0;
    l_position = mul(mat_modelproj, position); 
} 


void fshader( 
    in float4 l_color : COLOR,
    in float2 l_texcoord0 : TEXCOORD0,
    in uniform sampler2D k_vtftex : TEXUNIT0,
    out float4 o_color : COLOR) 
{ 
    o_color = tex2D(k_vtftex,l_texcoord0);
}

deflected, moving the tex2D to the fragment shader would defeat the whole point of VTF (Vertex Texture Fetch).

vonCrabbitz, try placing the DirectStart import line after the PRC specification.

well actually I’m not trying to apply the texture to the mesh, I’m wanting to use tex2d in the Vertex shader to deform the grid mesh to create a terrain

CL Cheung water vtf uses the tex2D in the vertex shader and his app works fine on my PC, but, nothing I do can get tex2D to work in my apps

here’s CL Cheung shader…uses Tex2D in the vshader

//Cg
//Cg profile vp30 fp30

/*
Comments:
	CL Cheung, Mar 2009
	A vertex texture shader, based on Vertex Texture Fetch Water demo in NVIDIA SDK 9.5
	This shader handles reflection only
*/


void vshader( 	in float4 vtx_position : POSITION,
				in float2 vtx_texcoord0 : TEXCOORD0,
                in uniform float4x4 mat_modelproj,
				in uniform float4x4 trans_model_to_world,
				in uniform sampler2D k_vtftex : TEXUNIT0,	// simulationSampler
				in uniform float4 k_eyePositionW,
				in uniform float4 k_gridratio,
				out float4 l_eyeVector: TEXCOORD1,
				out float4 l_normal: TEXCOORD2,
                out float4 l_position : POSITION)
{
	float4 position = vtx_position;
	float4 simulationSample = tex2D(k_vtftex, vtx_texcoord0);
	float4 normal;
	position.z = (simulationSample.x-0.5) * k_gridratio.w;
	float3 dzdx = float3(k_gridratio.x, 0.0,  (simulationSample.y-0.5) * 4 * k_gridratio.z);
	float3 dzdy = float3(0.0, k_gridratio.y, (simulationSample.z-0.5) * 4 * k_gridratio.z);
	normal.xyz = normalize(cross(dzdx, dzdy));
	
	l_normal = mul(trans_model_to_world,normal);
	
   	l_position = mul(mat_modelproj, position);
	float3 positionW = mul(trans_model_to_world,position).xyz; 
	l_eyeVector.xyz = positionW - k_eyePositionW;
}


void fshader( 	
		in uniform samplerCUBE k_texcube : TEXUNIT1,
		in float4 l_eyeVector: TEXCOORD1,
		in float4 l_normal: TEXCOORD2,
		in uniform float4 k_param2,
		in uniform float4 k_watercolor,
		out float4 o_color : COLOR)
{
	float4 R;
	R.xyz = reflect(l_eyeVector.xyz,l_normal.xyz);
	R.w = 0;
	//float4 reflectedColor = texCUBEbias(k_texcube, R);
	float4 reflectedColor = texCUBE(k_texcube, R.xyz);
	//o_color = reflectedColor;
	o_color = lerp(k_watercolor, reflectedColor, k_param2.x); //k_reflectivity
}

yeah, you`re right rdb …

IT WORKS! …awesome :smiley: ,
changed a few lines in the shader too and it works perfectly.

rdb your my new hero :stuck_out_tongue: i’ve been banging my head against the wall for some time trying to figure out what was wrong, I knew it had to be something simple like change the import order