Sign in to follow this  

Problem with CG Shader (SOLVED)

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, Sorry, if this is the wrong forum to post this in. Im having a problem with a shader, Im trying to render some terrain with a shader that takes a 1D texture as a lookup for the colour the terrain should be at a certain height. This part works on its own, also im trying to combine a detail texture across the landscape, just a grass texture repeated across the whole thing. This part also works on its own. The problem is combining them, im trying to multiply the height color by the texture color then apply the amount of diffuse light. Each works on its own, and the light calculations work with the height color and detail texture on their own but multiplying the detail texture by the height color produces black everywhere. Below is the fragment shader.
fragmentOutputs main( fragmentInputs IN,
                                        uniform float3 lightPosition)
                {
	                fragmentOutputs OUT;

                    float lookup = (1.0f / IN.terrainHeightRange) * (IN.position.y - IN.terrainMinHeight );

                    float3 heightColor = tex1D( IN.terrainLookup, lookup).rgb;

                    float3 detailTex = tex2D( IN.detailTextureA, float2( IN.position.x, IN.position.z )).rgb;

                    //float3 heightColor = float3(texColor.r, 0.0f, 0.0f) * color;

                    //float3 lightToPixel = IN.position - lightPosition;
	                //lightToPixel = normalize( lightToPixel );
	                //float3 normal = normalize( -IN.normal );

	                //float lambertTerm = dot( normal, lightToPixel );

	                //float3 diffuseIntensity = (lambertTerm);

                    //OUT.color.rgba = float4(diffuseIntensity, 1.0f );
                    //OUT.color.rgba = float4( (heightColor * diffuseIntensity.rgb), 1.0f );
                    OUT.color.rgba = float4( detailTex, 1.0f );
                	
	                return OUT;
                }



With OUT.color.rgba = float4( detailTex, 1.0f ); as the final output I get this With OUT.color.rgba = float4( heightColor, 1.0f ); as the final output I get this and finally, with OUT.color.rgba = float4( detailTex * heightColor, 1.0f ); I get this Im sure Im doing something stupid, but I cant think of what it is. Otherwise it just seems as though when I multiply them, one or both the colours is 0,0,0. Any help would be greatly appreciated, im going mad trying to get this working. [Edited by - ArThor on December 8, 2008 3:19:24 PM]

Share this post


Link to post
Share on other sites
As far as I know, other than the initial glBindTexture calls for creating the textures in OpenGL, im not using any glTextureBind calls for the shader or glActiveTexture calls. I didnt think I needed to, im just using CG to get named parameters for the textures and setting then enabling those textures before each draw of the terrain.

There isnt much more to the shader other than the inputs, Im at work right now so I cant get to my source to post it or get more details. Ill try and post more when I get home later.

Ive had something similar working before and the differences dont seem to great, unfortunatly the old project is unavailable. The only difference I can think of at the moment that might affect things is that Im mixing a 1D and 2D texture in the shader.

Share this post


Link to post
Share on other sites
Quote:
Original post by ArThor
As far as I know, other than the initial glBindTexture calls for creating the textures in OpenGL, im not using any glTextureBind calls for the shader or glActiveTexture calls. I didnt think I needed to, im just using CG to get named parameters for the textures and setting then enabling those textures before each draw of the terrain.


That's where I believe things are going wrong. Make sure that Cg is binding textures to the correct samplers. It's probably binding both textures to sampler 0.

Share this post


Link to post
Share on other sites
Ive fixed the problem, i tried adding the active texture calls and the bind calls in but they didnt work. However, I did notice as I was removing them again, that I had copy and pasted the call to get the texture parameter from the shader and had only changed the parameter name to look for and not the variable to store it in.

I think you can use either the active texture and bind calls or the set texture and enable texture cg calls. I was just making a mess everywhere else. Thanks for the help deathkrush, I wouldnt have been looking around in that area if it wasnt for your suggestion and I never realised there were two methods to do this either.

Share this post


Link to post
Share on other sites

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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