[RESOLVED] Shader Model 3.0 - New Relief Shader Compiles

I’m getting an error when trying to compile the ambient pass on a fragment shader targeted at Shader Model 3.0.

I’m getting the error:

Cg in program 'af': error C6006: Maximum texture indirection of 4 exceeded; 31 indirections needed to compile program at line 15

I only have 2 textures, I’m not sure what this is about?

I’ve attached a simplified version of the issue. A scene with a plane and a single material with the shader.

See attached.

109413–4189–$relieftest001_151.zip (3.4 MB)

Basically, you can’t do more than 4 levels of “dependent read”. A dependent read is when you read from a texture and then use the result to compute new coordinates to read from a texture.

Shader Model 3.0 does not have this limitation in Direct3D, but on OpenGL (in particular Apple’s OpenGL implementation), some graphics cards (I think some Radeon HDs) only support 4 levels of texture indirection. Yes, the hardware can do unlimited texture indirections, but Apple’s OpenGL only allows 4 :frowning:

So is there a way to specify this is a DX shader only so this will compile?

I’m using:

#pragma target 3.0

Shouldn’t that be enough to let this know it’s DirectX?

Not right now. But yeah, having that capability does make sense, will add for next release.

This tries to do “rougly shader model 3.0” for both D3D9 and OpenGL. On D3D it compiles to SM3, and on OpenGL it tries to use similar set of limits (plus the aforementioned four dependent reads limit, which you’re hitting).

Could I make an empty OpenGL subprogram?

SubProgram "opengl " {

I’m using another compiled Cg as an example.

Well this didn’t work.

	SubShader {
        Pass {
        
SubProgram "opengl "
{
}

CGPROGRAM

...

}
}

109520–4194–$compiledcg_173.shader (4.66 KB)

What about project compile options. Can I remove the OpenGL component until the next release?

Thanks Aras for all the help. I was able to port the relief shader from Max with ShaderFX to FX Composer, and then manually ported to RenderMonkey and then manually ported to Unity3d.

The code is a little messy. I left the generated code in, while I figured out how to port to the Unity variables.

The shader will work for everybody else when the new CgBatch compiler is released.


110042–4217–$reliefshader_140.shader (11.9 KB)
110042–4227–$relieftest001_168.zip (3.41 MB)

Looks awesome :slight_smile: Well done!

I added some information to the wiki about the process that I used to port the shader.

Sorry…I tried to test the shader on my pc and I got a looong sequence or errors like this on different shader parameters:

Material doesn’t have a color property ‘_LightPosition’
UnityEditor.DockArea:OnGUI()

Could you please help me?