Advertisement Jump to content
Sign in to follow this  

why fragment.fogcoord.x is alway zero?( fragment program,fog)

This topic is 4746 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

I am doing terrain texture blend now.I have made it works use texture_env_combine already. But use too many passes. X700,can do it in one pass(fix-function),but FX5200,can not(?), so i want use frament program. i want blend 4 textures and 1 light map , with fog on( fogmodel:linear ). My card is : X700.It supports EXT_fog_coord. fogFactor = (end-z)/(end-start) fog color is OK . i am sure fog model is on . and output frament.position.z*frament.position.w,is OK. but output frament.fogcoord.x, ( like this: = frament.fog.coord.x), i get black color,always . i think maybe i did not set correct render state . The document says "If a fragment attribute binding matches "fragment.fogcoord", the "x" component of the fragment attribute variable is filled with either the fragment eye distance or the fog coordinate, depending on whether the fog source is set to FRAGMENT_DEPTH_EXT or FOG_COORDINATE_EXT". If i set correct render state , i can get the distance i want? Or have to use vertex program? I sorry for poor English. Thanks . My shader is: # Generated by ATI's Ashli Compiler on 2006-01-17 19:51:06.\n# Ashli Version: 1.7.0\n\n\n# Instructions (Alu): 5\n# Registers (Temp): 1\n# Registers (Constant): 3\n# Registers (Color): 2\n# Registers (Output): 1\n\nATTRIB Color0 = fragment.color.primary;\nATTRIB Color1 = fragment.color.secondary;\nATTRIB TexA = fragment.texcoord[0];\nATTRIB TexD0 = fragment.texcoord[1];\nATTRIB TexD1 = fragment.texcoord[2];\nATTRIB TexL = fragment.texcoord[3];\nATTRIB dis = fragment.fogcoord;\nPARAM zfc = state.fog.color;\nPARAM fp = state.fog.params;\n\nPARAM Const2 = { 0, 0, 0, 1 };\n\nPARAM Const0 = program.local[0];\nPARAM Const1 = program.local[1];\n\nTEMP Temp0;\nTEMP Temp1;\nTEMP Temp2;\nTEMP Temp3;\nTEMP Temp4;\nTEMP Temp5;\n\nOUTPUT Output0 = result.color;\nTEX Temp0,TexA,texture[0],2D;\nTEX Temp1,TexD0,texture[1],2D;\nTEX Temp2,TexD1,texture[2],2D;\nLRP Temp3,Temp0.aaaa,Temp1,Temp2;\nTEX Temp4,TexL,texture[3],2D;\nMUL Temp5,Temp3,Temp4;\nMUL Temp5,Color0,Temp5;\nSUB Temp0.x,fp.z,fp.z;\nMUL_SAT Temp1.x,Temp0.x,fp.w;\nLRP Output0,Temp1.x,Temp5,zfc;\nMUL Temp4.xyzw, dis,Temp5;\n\//***** ******************/ MOV,dis;\n\//*****here****** just output distance \nEND\n";

Share this post

Link to post
Share on other sites
if i understand correctly u can get fog working?
ive never used it with glsl, my question is do u need to use it?
im pretty sure the only reason frament.fogcoord exists is a legacy of the fixed pipeline. with glsl u can emulate that pwe vertex or per pixel

eg for per vertex fog (off the top of my head so may not work 100%),
u can easily make this per pixel fog by sticking the distance calculation in the fragmentshader

/// vertex_shader /////
varying float vec_dist;

vec3 cam_pos = gl_ModelViewMatrixInverse[3].xyz;
vec3 vert_pos =;
vec_dist = distance( vert_pos, cam_pos );

/// fragment_shader /////

varying float vec_dist;
float fog_amount = ( end - vec_dist ) / ( end - start );

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!